| ▲ | cogman10 7 hours ago | ||||||||||||||||||||||||||||||||||||||||
x87 is such a weird architecture. It was designed the same way you'd design a chip for a scientific calculator. Heck, It's almost a perfect fit for an HP RPN calculator. But for a compiler to target, it's just so painful. It's so different from almost all other ways CPUs work. There's a reason both CPU and compilers prefer to avoid x87 when possible and use regular SIMD (SSE/AVX) instead. Also, the arbitrary "Oh, and the registers are 80 bits wide" is also just one of those weird "Where did that number come from?". | |||||||||||||||||||||||||||||||||||||||||
| ▲ | jcranmer 5 hours ago | parent | next [-] | ||||||||||||||||||||||||||||||||||||||||
> But for a compiler to target, it's just so painful. It's so different from almost all other ways CPUs work. There's a reason both CPU and compilers prefer to avoid x87 when possible and use regular SIMD (SSE/AVX) instead. The x87 ISA is essentially a one-address stack-based ISA (so unlike a pure stack ISA, you can reference another value on the stack without having to introduce something like a dup instruction). Which honestly isn't particularly painful to work with for a compiler; it's not usual, but there are other ISAs that are also stack-based (the JVM bytecode is the one that most immediately comes to mind). The actual weirdness of x87, what makes all the compilers run away from it, is that the only values you can have on the stack are 80-bit extended-precision types. But people don't use those types in their code, they use 32-bit and 64-bit single and double precision, and compilers largely implemented these types by pretending that the x87 just used those value sizes in the first type (the only ones to actually get it correct that I'm aware of are Java's strictfp and Intel's icc, although the latter is merely just correctly implementing FLT_EVAL_METHOD==2). The end result is that compilers caused code to have essentially random and largely uncontrollable precision changes, which pissed a lot of users off, and the SSE units having regular scalar proper single and double precision types made it easier for compilers to switch to that rather than introducing the proper sequences to compile for x87. | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| ▲ | em3rgent0rdr 6 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||
80-bit wide registers isn't really arbitrary if you consider that the bulk of the floating point number is a 64-bit significand (and the signifiand ALU makes sense as power-of two) and that you don't need as many bits for exponent (it would be wasteful to go to the next power of two up). Memory is stored as 8-bit bytes as the lowest addressable unit, and so the question would be how many extra bytes the number should take, and 80 bits is a nice integer number of 10 bytes. | |||||||||||||||||||||||||||||||||||||||||
| ▲ | matja 6 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||
> Also, the arbitrary "Oh, and the registers are 80 bits wide" is also just one of those weird "Where did that number come from?". One of the features that was advertised (mentioned in the iAPX 86, 88, 186 Microprocessors Part II book (July 1984)) was the ability to do exact arithmetic on integers up to 2^64, which is possible due to the 64-bit mantissa used in the 80-bit format. | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| ▲ | Sharlin 3 hours ago | parent | prev | next [-] | ||||||||||||||||||||||||||||||||||||||||
There's also the fact that for all intents and purposes, the real floating-point unit of any x86 in the last 20 years is the SIMD unit, and legacy x87 instructions are emulated on top of that. | |||||||||||||||||||||||||||||||||||||||||
| ▲ | kens 5 hours ago | parent | prev [-] | ||||||||||||||||||||||||||||||||||||||||
I've looked at some early calculators and they are a whole different world of weirdness. They used decimal arithmetic (BCD) because it's a lot easier than converting between binary and decimal. The first calculators were serial, with a 1-bit adder and shift registers and bits constantly in motion. The Sinclair Scientific calculator used TI's strange 4-bit architecture along with terrible algorithms. | |||||||||||||||||||||||||||||||||||||||||