Why is the x86 undefined instruction called ud2? Why 2?(devblogs.microsoft.com)
253 points by ibobev 23 hours ago | 58 comments
tl;dr: The x86 `ud2` instruction is guaranteed to raise an invalid opcode exception, often emitted by compilers after `[[noreturn]]` calls. It's named "ud2" because two earlier undocumented byte sequences (`0F FF` and `0F B9`) were informally used for the same purpose, and Intel retroactively named them `ud0` and `ud1` after Hyrum's Law forced them to preserve the behavior. `ud2` is preferred because it's a clean two-byte instruction with no operands, avoiding edge cases where operand decoding crosses into a non-present page and raises an access violation instead.
HN Discussion:
  • Humorous appreciation of the irony that an undefined instruction has guaranteed behavior
  • Playful embrace of the Hyrum's Law framing regarding UD0/UD1 origins
  • Adding technical detail about ModRM decoding explaining the page-crossing issue
  • Extending the article with additional undefined instructions like UDB and UDW
  • Questioning whether the article's historical claims are speculation or evidenced