Microcode inside the Intel 8087 floating-point chip: register exchange

pwg1 pts0 comments

Microcode inside the Intel 8087 floating-point chip: register exchange

Microcode inside the Intel 8087 floating-point chip: register exchange

In 1980, Intel introduced the 8087 floating-point chip, a co-processor that made floating-point operations<br>up to 100 times faster.<br>This chip was highly influential, and today most processors use the floating-point standard introduced by the 8087.

The 8087 uses complicated algorithms to accurately compute functions such as square roots, tangents, and exponentials.<br>These algorithms are implemented inside the chip in low-level code called microcode.<br>I'm part of a group, the Opcode Collective, that is reverse-engineering this microcode.<br>In this post, I take a close look at the microcode for one of the 8087's instructions—FXCH—and explain how the microcode works.<br>The FXCH (Floating-point Exchange) instruction exchanges two floating-point registers. You might expect this instruction to be trivial,<br>but there's more going on than you might expect; the microcode uses 14 micro-instructions to implement the exchange instruction.

The Intel 8087 chip is packaged in a 40-pin DIP (dual in-line package).

To explore the microcode, I opened up an 8087 chip and created a high-resolution image with a microscope.<br>The large microcode ROM occupies a central position, holding the micro-instructions that control the chip.<br>The microcode engine on the left steps through the microcode, handling jumps and subroutine calls.<br>The bottom half of the chip is the "datapath", the circuitry that performs floating-point calculations; it is split into a 16-bit datapath for the<br>number's exponent and a 64-bit datapath for the number's fractional part (also known as the significand).

Die of the Intel 8087 floating-point unit chip, with main functional blocks labeled. The die is 5mm&times;6mm. Click for a larger image.

This post focuses on the temporary registers and stack registers that are highlighted in red.<br>The chip has two temporary registers and eight stack registers, each holding a number's exponent and fraction.<br>Each register also has two tag bits that label the type of value in the register.<br>The stack control circuitry at the right manages the stack,<br>keeping track of the top-of-stack position as values are pushed onto the stack or popped off the stack.

The 8087's microcode

Executing an 8087 instruction such as arctan requires hundreds of internal steps to compute the result.<br>These steps are implemented in microcode with micro-instructions specifying each step of the algorithm.<br>(Keep in mind the two levels of instructions: the assembly language instructions used by a programmer and the<br>undocumented low-level micro-instructions inside the chip.)<br>The microcode ROM holds 1648 micro-instructions, implementing the 8087's instruction set.<br>Each micro-instruction is 16 bits long and performs a simple operation such as moving data inside the chip, adding two values, or shifting data.<br>I'm working with the Opcode Collective to reverse-engineer the micro-instructions and fully understand the microcode (link).

The 8087's micro-instructions are complicated, with many corner cases and ad hoc functions, but I'll provide a simplified overview.<br>Each micro-instruction consists of 16 bits, as shown below.<br>The first three bits specify the type of the micro-instruction, which controls the meaning of the remaining bits.<br>The first type indicates a transfer operation, transferring data from one internal register to another.<br>The two fields specify the source and destination for the data. The three unspecified bits are used for various special cases.<br>Next is a shift operation, which uses the barrel shifter to shift a value left or right.<br>The third type of micro-instruction uses the adder/subtractor. It can also be used in a loop for multiplication or division.<br>Fourth are various arithmetic control micro-instructions that configure the adder, set rounding modes, and so forth.<br>The far jump and far call micro-instructions perform a jump or subroutine call to a target micro-address in a fixed list.<br>The condition field allows conditional jumps/calls based on numerous conditions, while the last bit inverts the condition.<br>A local jump allows a conditional jump to a nearby micro-instruction.<br>Finally, the miscellaneous micro-instructions range from returning from a subroutine or raising an exception to<br>ending the microcode execution.

Structure of an 8087 micro-instruction.

How values are stored inside the 8087 chip

The 8087 supports a variety of data types: floating-point numbers of various sizes, integers, and binary-coded decimal.<br>But internally, everything is stored as an 80-bit floating-point number.<br>A number has three parts: a 64-bit significand (the fractional part), a 15-bit exponent, and a sign bit.<br>The chip has two separate data paths: one for the significand, and one for the exponent and sign.

The chip has eight registers to store numbers during calculations, the top registers in the diagram below.<br>However, the...

microcode chip micro instructions floating point

Related Articles