logoalt Hacker News

ginkotoday at 8:14 AM1 replyview on HN

>Bonus authenticity: use `a^=a` to zero a register in a single x86 instruction (and makes a real difference for compiler toolchains 30+ years old).

Modern compilers will still use xor for zeroing registers on their own.

For instance: https://godbolt.org/z/n5n35xjqx

Variable a(register esi) is first initialized to 42 with mov and then cleared to zero using xor.


Replies

gobdovantoday at 8:20 AM

Yes, the whole comment is tongue in cheek for pointless manual optimizations.