better registers representation in C?

Programming, for all ages and all languages.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: better registers representation in C?

Post by Owen »

Except for when doing whole program optimization and with at least hidden symbols, the compiler can't assign variables to specific register slots across function calls in a safe manner. The register globals extension is used to allow e.g. the VM program counter or (for a stack machine) stack pointer to be placed in registers across multiple functions.

You can think of this as, almost, a custom calling convention exteennsion. Indeed, if you had one (e.g. Watcom's pragma based method) this would probably not be necessary (though, then again, it may still produce cleaner code)
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: better registers representation in C?

Post by Love4Boobies »

That's what optimizing linkers are for---making things clean (e.g., LLVM gold plugin) :)
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Thomas
Member
Member
Posts: 281
Joined: Thu Jun 04, 2009 11:12 pm

Re: better registers representation in C?

Post by Thomas »

Hi,

Just putting this for informational purposes only, the good old Turbo / Borland C++ had the feature of accessing registers like this. I do not have access to a Borland compiler right now , but i guess newer versions allows access to 32 bit registers

Code: Select all

_AX = 2 ;
_BX = 3 ;
_CX  = _AX + _BX ;

--Thomas
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: better registers representation in C?

Post by Love4Boobies »

Yes, miker00lz already mentioned that. At least what Owen (who will get his 5th start after just two more posts from the time I post this :mrgreen:) mentions is useful for a sucky toolchain...
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Thomas
Member
Member
Posts: 281
Joined: Thu Jun 04, 2009 11:12 pm

Re: better registers representation in C?

Post by Thomas »

Yes, miker00lz already mentioned that. At least what Owen (who will get his 5th start after just two more posts from the time I post this :mrgreen:) mentions is useful for a sucky toolchain...
Sorry , missed that :oops: . However redundancy does improve reliability at times :mrgreen:


--Thomas
Post Reply