The ability to handle larger amounts of data directly in physical
memory rather than relying on disk I/O is perhaps the most significant
performance benefit of 64-bit machines. However, some applications
compiled in 32-bit mode perform better than when they are recompiled
in 64-bit mode. Some reasons for this include:
- 64-bit programs are larger. The increase in program size places
greater demands on physical memory.
- 64-bit long division is more time-consuming than 32-bit integer
division.
- 64-bit programs that use 32-bit signed integers as array indexes
might require additional instructions to perform sign extension each
time the array is referenced.
Some ways to compensate for the performance liabilities of 64-bit
programs include:
- Avoid performing mixed 32- and 64-bit operations. For example,
adding a 32-bit data type to a 64-bit data type requires that the
32-bit type be sign-extended to clear the upper 32 bits of the register.
This slows the computation.
- Use long types instead of signed, unsigned,
and plain int types for variables which will be frequently
accessed, such as loop counters and array indexes. Doing so frees
the compiler from having to truncate or sign-extend array references,
parameters during function calls, and function results during returns.