Motorola 68K Floating Point Processors - how different from X87, Pentium FPU?

I’ve used Intel floating point processors in assembly language a little and am roughly familiar with the circular stack, the 80 and 64 and 32 bit floats, the functions for converting between integers and floats and some ways of transferring between the FPU and the rest of the system, and the two argument and one argument functions, including the higher math ones. The biggest thing I’ve done is rewrite part of a floating point package in assembly so that I could keep arguments in the circular stack rather than stripping them to 64 bit between each operation, in a data acquisition and PID control setup.

So, what would be different about the Motorola world, from that point of view? Is it the MC68882 as a separate device that would be used, or is that as old as PCs with “coprocessor sockets”? Are the approaches similar? Does it have its own stack? Does it work with the same widths? What important abilities does one have that the other doesn’t?

Would there be any
elegant surprises awaiting the X86 programmer who strayed across the fence???

It’s been a while, but as I recall:

[ul]
[li]The m68k FPU is not stack based, like the x86 FPU, but rather has 8 directly accessible registers.[/li][li]Like the x86, the separate m68882 FPU was ultimately integrated into the CPU. I think this happened with the m68030, although some of the later embedded m68k variants didn’t have a FPU or coprocessor support at all.[/li][li]Like the x86, you can load and store 32 and 64 bit values, but calculations are generally performed in 80 bits, so there can be similar issues with excess precision. Instructions to explicitly perform operations in 64 or 32 bit mode were added to the m68040.[/li][li]I don’t recall instructions for sin, cos, log, exp, etc. operations, but that may be faulty memory on my part.[/li][/ul]

A rough, but fairly accurate summary is that the Motorola 68000 processor is designed in the style of Seymour Cray, of CDC & Cray supercomputer fame; while the Intel 8087, etc. is designed in the style of Gene Amdahl, of IBM 360 & Amdahl fame.

It was the 68040 that integrated the FPU. The 68030 integrated Motorola’s MMU which used to be a separate chip.

One little quirk: the memory storage format for floating point numbers was actually 96 bits, with 16 bits unused. This was for alignment reasons —12 bytes loads and stores faster than 10. The registers inside the FPU were still 80 bits, as you say.

They were there. Here’s an MC68882 data sheet for reference. (Warning: scanned PDF document.) Short descriptions of the instructions start on physical page 10.

I should have said: the storage format for full-precision values was 96 bits. As John says, you could load and store 32- or 64-bit formats as well.

Thanks, all! Byte, thanks for the link to the datasheet.

So how does one use the registers? Does, for example, division work directly on any two registers? Or do they serve particular purposes, like an accumulator that can only be summed into or cleared? Or is there a low layer of hardware abstraction so there can be special purpose registers but an appearance of 8 arbitrarily useable registers in the programmer’s model? I guess this last is a little like asking what the lithography masks looked like, in principle untestable by any program and therefore a potentially secret internal detail without consequence to the programmer.

I am just curious, by the way. The Intel FPU has been an object of idle fascination for me for years.

You’re welcome.

Some interesting 6888x instructions that might or might not exist on the Intel:

FSINCOS – calculates both the sine and cosine of an angle
FETOXM1 – (e ^ x) - 1
FLOGNP1 – natural log of (x + 1)
FLOG10, FLOG2, FLOGN – logarithms in base 10, 2, or e
FTENTOX – 10 ^ x

There are no restrictions on which FP registers can be used in any of the instructions. All eight FP registers are equivalent. Unlike the x86 family, Motorola’s designs were pretty orthogonal from the very beginning. Though there were groups of specialized registers — address, integer, and floating-point — within these groups, you could use any appropriate instruction on any register.

One exception that comes to mind is the A7 address register, which the 68K CPU “borrowed” as the system stack pointer. This one you treated gingerly of course, or else a hard crash would be in your immediate future.

Right. I don’t know what the microcode or low-level “hidden” architecture of the Motorola chips was like. At a glance, the data sheet above seems to describe only the visible features of the 68882. I imagine the eight FP registers were really down there somewhere in their full 80-bit glory — but that there were also some scratch registers, used for computation, that were inaccessible from software.

For what it’s worth, I was once very familiar with the i386 about 16 years ago, but never learned any of Intel’s FP architecture. If I had, I could give you better comparisons between the two families.

Bytegeist, this is first rate of you. Most interesting.

The math functions you point out are all on the X87 too, except IIRC there is only one log function, in base 2, and the multiplicands to turn this into the other bases are built-in constants. But it looks like the Motorola has more built in constants than the X87 does.

And there’s some function on the X87 that returns two arguments, one of which is always 1. I think maybe it’s tan. There must be some reason for this, like leaving the registers in a more convenient state for some action that often follows tan, but I never knew what it was.

That is curious. The only explanation I can come up with — while sitting in my chair here, not doing any actual research — is that the internal algorithm is doing an exact inverse of the ‘atan2’ function. (That’s ‘atan2’ like the one defined in the C standard library: taking x and y coordinates and returning the angle that that vector makes with the x-axis.)

Assuming that, then the Intel ‘tan’ function is returning both an “x” and a “y”, but with x always 1, and y the actual tangent result that you care about.

Either that or the Intel engineers were just fond of the number 1, and felt you needed to be reminded of it from time to time, in case you were about to stop appreciating it. Here, have a one. Is nice, no?