I
Immortal Nephi
You use data type to determine the size of char, short, and long. If
you choose to use either char or short to do calculation, C++ Compiler
converts from char or short to either maximum 32 bit register size or
64 register size to do calculation before they are converted back to
original size.
For example:
char a = 1;
char b = 2;
char s = 0;
short aa = 5;
short bb = 10;
short ss = 0;
s = a + b;
ss = aa + bb;
The C++ Compiler copies either a or aa from memory into 32 bit
register. CPU performs sum calculation. The result of sum in
register is converted back to either 8 bit or 16 bits back to the
memory. The performance can be improved to use 32 bit register than
16 bit register.
What happen if C++ Compiler may assign 32 bits to int on x86 and 64
bits to int on I64 or AMD machine? My code does not care to use
either 32 bits or 64 bits when calculation can be done in 16 bits. My
code should use minimum 32 bit register for best performance.
Like this here.
if (sizeof(int) == 4 ) // 32 bits machine
typedef long int register_t;
else // 64 bits machine
typedef long long int register_t
Please correct me if I am wrong.
you choose to use either char or short to do calculation, C++ Compiler
converts from char or short to either maximum 32 bit register size or
64 register size to do calculation before they are converted back to
original size.
For example:
char a = 1;
char b = 2;
char s = 0;
short aa = 5;
short bb = 10;
short ss = 0;
s = a + b;
ss = aa + bb;
The C++ Compiler copies either a or aa from memory into 32 bit
register. CPU performs sum calculation. The result of sum in
register is converted back to either 8 bit or 16 bits back to the
memory. The performance can be improved to use 32 bit register than
16 bit register.
What happen if C++ Compiler may assign 32 bits to int on x86 and 64
bits to int on I64 or AMD machine? My code does not care to use
either 32 bits or 64 bits when calculation can be done in 16 bits. My
code should use minimum 32 bit register for best performance.
Like this here.
if (sizeof(int) == 4 ) // 32 bits machine
typedef long int register_t;
else // 64 bits machine
typedef long long int register_t
Please correct me if I am wrong.