Using registers
Main memory access is slow. Performance is heavily impacted by how registers are used. Optimal register allocation is nondeterministic polynomial-complete (NP-complete): very difficult. Optimizing compilers expend great effort on register allocation. That is beyond the scope of this book.
x64 has 16 general-purpose registers, as illustrated in the following table, but many registers have a special role. Arithmetic is performed on an accumulator register, rax
. Registers have 8- to 64-bit versions. Jzero only uses the 64-bit versions of registers, plus whichever 8-bit registers are necessary for strings. In AT&T syntax, register names are preceded by a percentage sign, as in %rax
:
Many registers are saved as part of a call
instruction. The more registers, the slower it is to perform function calls. These issues are determined by the calling conventions of the compiler. Jzero only saves modified registers...