103
IEEE Floating-Point Bit Tricks
See [7], Section 2.1, for a few really useful IEEE fl oating-point “bit tricks” that
can make fl oating-point calculations lightning-fast.
3.2.1.5. Atomic Data Types
As you know, C and C++ provide a number of atomic data types. The C and
C++ standards provide guidelines on the relative sizes and signedness of these
data types, but each compiler is free to defi ne the types slightly diff erently in
order to provide maximum performance on the target hardware.
z char. A char is usually 8 bits and is generally large enough to hold an
ASCII or UTF-8 character (see Section 5.4.4.1). Some compilers defi ne
char to be signed, while others use unsigned chars by default.
z int,short,long. An int is supposed to hold a signed integer value
that is the most effi cient size for the target platform; it is generally de-
fi ned to be 32 bits wide on Pentium class PCs. A short is intended to
be smaller than an int and is 16 bits on many machines. A long is as
large as or larger than an int and may be 32 or 64 bits, depending on
the hardware.
z float. On most modern compilers, a float is a 32-bit IEEE-754 fl oat-
ing-point value.
z double. A double is a double-precision (i.e., 64-bit) IEEE-754 fl oating-
point value.
z bool. A bool is a true/false value. The size of a bool varies widely across
diff erent compilers and hardware architectures. It is never implemented
as a single bit, but some compilers defi ne it to be 8 bits while others use
a full 32 bits.
Compiler-Specifi c Sized Types
The standard C/C++ atomic data types were designed to be portable and
therefore nonspecifi c. However, in many soft ware engineering endeavors, in-
cluding game engine programming, it is oft en important to know exactly how
wide a particular variable is. The Visual Studio C/C++ compiler defi nes the fol-
lowing extended keywords for declaring variables that are an explicit number
of bits wide: int8, int16, int32, and int64.
SIMD Types
The CPUs on many modern computers and game consoles have a special-
ized type of arithmetic logic unit (ALU) referred to as a vector processor or
vector unit. A vector processor supports a form of parallel processing known
as single instruction, multiple data (SIMD), in which a mathematical operation
3.2. Data, Code, and Memory in C/C++