RasterCore

The Intel 8087: Floating Point Luxury

:: SysOp

The Socket Next Door

If you open up an original IBM PC (5150) or an AT (5170), you will see the main CPU (8088 or 80286). But right next to it, there is an empty 40-pin socket. This was the home for the Floating Point Unit (FPU), also known as the Math Coprocessor.

  • For the 8086/88, it was the 8087.
  • For the 286, it was the 287.
  • For the 386, it was the 387.

Why did we need it?

Standard CPUs of the 80s were “Integer” processors. They understood whole numbers: 1, 5, 100, -50. They did not understand 3.14159 or 0.005.

To perform a calculation like SIN(45.5), the computer had to use a software library (like emu87). This library broke the decimal operation down into hundreds of integer additions and bit-shifts. It was agonizingly slow. Calculating a single sine wave point might take 10,000 clock cycles.

The 8087 was a dedicated silicon brain for math. It could perform that same sine calculation in perhaps 100 cycles. For scientific applications (CAD, spreadsheets like Lotus 1-2-3), the speedup wasn’t 50%—it was 1000%.

The Stack Architecture

The x87 FPU operated differently from the main x86 CPU. It didn’t use general-purpose registers like AX, BX, CX. Instead, it used a Register Stack of eight 80-bit registers: ST(0) through ST(7).

You pushed values onto the stack, performed an operation, and popped them off.

Code Snippet: The Area of a Circle

Here is how you would calculate Area = PI * r^2 in x87 Assembly.

; Assumption: Radius is stored in memory at [radius]
; Result will be stored in [area]

FLDPI           ; Push PI onto the stack -> ST(0)=3.14159...
FLD [radius]    ; Push Radius -> ST(0)=r, ST(1)=PI
FMUL ST(0),ST(0); Multiply Top * Top -> ST(0) = r*r
FMULP ST(1),ST(0); Multiply ST(1)*ST(0), Pop stack -> ST(0) = PI * r^2
FSTP [area]     ; Store Top into memory and Pop -> Stack empty

The Gamer’s Perspective: “Co-Pro Required?”

For the first decade of PC gaming, the FPU was ignored. Why? Because it cost $200-$400. Game developers couldn’t assume the average kid had one. Instead, games used Fixed Point Arithmetic. They would use a standard 32-bit integer, but pretend that the last 16 bits were the decimal part. 1.5 would be stored as 1 << 16 | 32768. This allowed games like Doom and Wolfenstein to run fast on integer-only CPUs.

The turning point was Quake (1996). John Carmack decided that the precision issues of fixed-point (jittery polygons) were unacceptable for a full 3D engine. He required a Floating Point Unit. Luckily, Intel had just released the Pentium, which—for the first time—integrated the FPU directly into the main CPU die. The era of the optional coprocessor was over.

The NMI Error

If you ever ran a program that tried to use FPU instructions on a machine that didn’t have the chip installed (and didn’t have a software emulator loaded), the CPU would panic. It didn’t just crash; it often triggered a Non-Maskable Interrupt (NMI), dumping you to a black screen with a cryptic “Coprocessor Error” message. This is why many old AUTOEXEC.BAT files contained the line SET NO87=1—a flag telling programs to disable their FPU code paths to avoid crashing the machine.