Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the benefits of using smaller registers, e.g. al vs eax / rax

I noticed that GHC's code generator does not currently output assembly that uses any of the lower machine registers like al. Even byte-size operations are implemented using rax on 64 bit and eax on 32 bit machines. GCC, however, frequently makes use of these smaller registers.

Are there any real performance benefits of using small registers like al?


One suggestion I've heard so far is that the opcode for inc al is smaller than inc rax (but not smaller than inc eax). Are there other, non-performance considerations why to use small registers?

like image 651
nh2 Avatar asked Jan 13 '14 20:01

nh2


1 Answers

Using the 64-bit registers (rxx) on x86-64 requires opcode-prefixes. Thus the instructions are longer, taking more space in memory and the instruction cache. I don't know if it also slows down decoding. The code-size could hurt performance if the bigger code is used in a loop that doesn't fit into the L1 instruction cache.

like image 158
EOF Avatar answered Sep 19 '22 12:09

EOF