· via Hacker News – Front Page (hnrss.org)
Reverse-engineering the 8087: the 140 micro-instructions behind FSCALE
A righto.com teardown traces the 8087's FSCALE instruction through more than 140 micro-instructions, showing how the coprocessor that set today's floating-point standard handled special cases.
One instruction, over 140 micro-steps
A reverse-engineering write-up on righto.com, which reached the Hacker News front page, dissects the microcode behind a single instruction — FSCALE — on Intel's 1980 floating-point coprocessor, the 8087. The author is part of a group called the Opcode Collective that is decoding the chip's internal control code, and went into the project expecting FSCALE to be nearly trivial to explain. According to the post, it is not: the instruction consumes more than 140 micro-instructions and three nested levels of subroutine calls, and the analysis also surfaces a hidden feature of the chip.
From incompatible arithmetic to a de facto standard
For context, the post sketches the mess the 8087 cleaned up: through the 1970s, floating-point arithmetic was split across roughly a dozen incompatible implementations, most shaped to make hardware easy rather than math correct, with numerical instability as a recurring consequence. Intel shipped the 8087 in 1980, engineering it for maximum accuracy even in awkward corner cases. Installed in an IBM PC, it could make floating-point operations as much as 100 times faster in software ranging from spreadsheets to CAD. More lastingly, the write-up notes, the chip's behavior became the floating-point rules most of today's computers follow.
Reading the die under a microscope
Recovering the microcode required opening an 8087 package and photographing the 5-by-6-millimeter die at high resolution. As the post describes it, the microcode ROM occupies the center of the chip and stores 1,648 micro-instructions. To its left sits the microcode engine, which sequences those instructions and manages jumps and subroutine calls. The bottom half of the die is the datapath — the arithmetic circuitry — split into a 16-bit path that handles exponents and a 64-bit path that handles significands.
The machinery FSCALE runs on
The instruction's code path touches several functional blocks. An exponent ROM holds constants, while a dedicated exponent converter checks exponent fields, recognizes special values and translates between exponent representations. A large shifter can slide a 64-bit value left or right by any number of positions. The adder is where the chip's real arithmetic happens — microcode drives it in a loop to carry out multiplication, division and square roots — with the B register feeding one input and a sum register catching the output. Numbers live in eight stack registers or in temporary storage: tmpA and tmpB are 80 bits wide with two tag bits each, while tmpC holds only a 64-bit significand.
Corner cases are the real work
FSCALE itself scales a value by a power of two — in the common case a tweak to the exponent, which is why it beats an actual multiplication for speed. The remaining hundred-plus micro-instructions exist to handle everything else.
Each of the eight programmer-visible registers is stack-organized, 80 bits wide, and carries a tag, largely hidden from programmers, marking its contents as valid, special, zero or empty; infinity, NaN and denormalized values all count as special. Whatever a program stores — narrower floats, integers, binary-coded decimal — is held internally as an 80-bit "temporary real": a sign bit, a 15-bit exponent stored with a bias of 16383 (true range about -16382 to 16383) and a 64-bit significand.
Layered on top are six exception types: invalid operation, overflow, underflow, divide-by-zero, denormalized operand and precision. Bits in the control register decide, per exception, whether it is masked. An unmasked exception interrupts the host 8086 so software can respond; a masked one lets the coprocessor keep the calculation running and produce the most accurate answer it can, substituting NaN for invalid outcomes, infinity for overflow or division by zero, and rounding for inexact ones. That flexibility, the post explains, is exactly what inflates the microcode: every combination of special operands and exception settings needs its own route through the routine.
Why it matters
The 8087's rules became the floating-point behavior most modern hardware inherited, so documenting its microcode is documenting where those semantics physically came from. The FSCALE walkthrough shows how much invisible machinery a "simple" instruction requires once correctness in corner cases is a design goal, and the masked-exception approach on display — keep computing and return the best answer possible — is a deliberate 1980 decision software still lives with. For emulator authors, CPU historians and anyone curious how a floating-point unit fits on 30 square millimeters of silicon, the Opcode Collective's work is turning the 8087 from a black box into readable code.
- #intel
- #microcode
- #reverse-engineering
- #floating-point
- #retro-computing