news.volyx.in

Why xor eax, eax? (xania.org)

576 points by hasheddan · 235 days ago · 215 comments on HN

Article summary

The article discusses the use of the `xor eax, eax` instruction in x86 assembly language, which is used to set the EAX register to zero. This instruction is preferred over `mov eax, 0` because it is more compact and can be optimized by the CPU. The article explains that this optimization is due to the way x86 CPUs handle partial register writes and the use of a REX prefix. The instruction is also used to zero out the top 32 bits of the RAX register in 64-bit mode.

Main themes

  • x86 assembly language
  • compiler optimizations
  • CPU architecture
  • instruction encoding
  • RISC vs CISC

What commenters say

  • The use of a dedicated zero register in RISC-V simplifies instruction encoding and reduces hardware complexity.
  • The x86 instruction set is more complex due to its CISC design, but this complexity can be mitigated by compiler optimizations.
  • The benefits of a dedicated zero register are debated, with some arguing it is a waste of hardware resources, while others see it as a useful feature.
  • The design of the RISC-V instruction set is elegant, but has some limitations, such as the lack of support for 64-bit immediates.
  • The trade-offs in ISA design, such as instruction size and decode complexity, must be carefully considered to achieve optimal performance.
  • The use of a fixed link register in RISC-V is seen as a good design choice, allowing for efficient save-restore and orthogonal encoding.