Is there any reason why arithmetic operation on shorts and bytes return int?
Era Scarecrow
rtcvb32 at yahoo.com
Sun Dec 16 12:39:37 PST 2012
On Tuesday, 11 December 2012 at 12:53:38 UTC, monarch_dodra wrote:
> integer operations are always promoted to at least int. That's
> standard fare since C. I think it is a performance thing:
> Unpack into ints, oeprate, repack into ints.
If memory serves me right, promotion to int is based more on CPU
efficiency and code size than anything else (and yes packing and
unpacking takes some 6 extra steps). Also with libraries possibly
written by different compilers may have different results if they
don't all agree on a common (default) type to return.
Also most x86 operations for ints can be written as 1 byte
opcodes, although for modern CPUs that kind of code generation
may not be as efficient as it used to be.
http://www.codeproject.com/Articles/6154/Writing-Efficient-C-and-C-Code-Optimization
More information about the Digitalmars-d
mailing list