Hacker News new | ask | show | jobs
by kccqzy 1675 days ago
Why didn't the author benchmark the one-instruction equivalent MOV AL,[RBX+AL] that the author uses to explain XLATB? How would its performance differ from the third sequence going through RCX?
1 comments

x86-64 does not have an addressing mode that uses the 8-bit register alias; in particular, the base and index registers are always either 32-bit (in 32-bit mode) or 64-bit (in 64-bit mode). As such, you need to zero-extend AL to a 64-bit register before using it in an offset addressing mode (or use XLATB).

For more information on supported addressing modes, see the manual: https://www.intel.com/content/www/us/en/develop/download/int... (specifically volume 1, section 3.7.5)

One could get rid of the push / pop though, assuming that the high bits of EAX don't need to be saved:

  movzx eax,al     ;could also do "and eax,0ffh"
  mov al,[rbx+rax]