Is int faster than byte/short?
Dmitry Olshansky
dmitry.olsh at gmail.com
Sun May 1 02:58:38 PDT 2011
On 30.04.2011 19:34, Mariusz Gliwiński wrote:
> Hello,
> I'm trying to learn high-performance real-time programming.
>
> One of my wonderings are:
> Should i use int/uint for all standard arithmetic operations or
> int/short/byte (depends on actual case)?
> I believe this question has following subquestions:
> * Arithmetic computations performance
> * Memory access time
>
> My actual compiler is DMD, but I'm interested in GDC as well.
>
> Lastly, one more question would be:
> Could someone recommend any books/resources for this kind of
> informations and tips that could be applied to D? I'd like to defer my
> own experiments with generated assembly and profiling, but i suppose
> people already published general rules that i could apply for my
> programming.
>
> Thanks,
> Mariusz Gliwiński
I find Agner Fog's guides on optimization for x86 the best source on
such architecture specific matters.
http://www.agner.org/optimize/
Citing releveant part from C++ optimization guide (on Integers):
>Integers of smaller sizes (char, short int) are only slightly less
>efficient. In most cases, the compiler will convert these types to
integers of the default size
>when doing calculations, and then use only the lower 8 or 16 bits of
the result. You can
>assume that the type conversion takes zero or one clock cycle. In
64-bit systems, there is
>only a minimal difference between the efficiency of 32-bit integers
and 64-bit integers, as
>long as you are not doing divisions.
--
Dmitry Olshansky
More information about the Digitalmars-d-learn
mailing list