3 ms·
I had a couple of question about this bit of history mentioned in the article. I'm hoping someone could shed some light on this: >"You can emulate floating-p
by bogomipz 8y ago
I had a couple of question about this bit of history mentioned in the article. I'm hoping someone could shed some light on this:
>"You can emulate floating-point arithmetic by using integer instructions—but taking 10–100 times as long."
Exactly how is/was floating point arithmetic emulated using only integers?
Why is that range given an order of magnitude? Is this dependent on the precision I'm guessing?
- phkahler 8y agoWe had floating point when programming in BASIC on old 6502 8bit computers. There were software routines for doing the math. You know, multiply the mantissa, add the exponents... If someone gave you pointers to a couple 4-byte chunks of data and told you to write code to do floating point multiply on the contents using only C-char variables, what would you write? That's why it's 100 times slower than a nice modern fmul. It wasn't quite that bad, they could use the carry flag which isn't available in C.
- sehugg 8y agoYep, here's the old Woz/Roy Rankin 6502 code for log, exp, conversions, and basic math: http://www.6502.org/source/floats/wozfp1.txt http://www.6502.org/source/floats/wozfp1.txt
- bogomipz 8y agoWha a wonderful bit of history your link is. Thanks for sharing.
- bogomipz 8y agoThanks these are all good reads and explanations. I guess I just have never had to think about FPU emulation before and it kind of threw me for a loop. It's amazing what we can take for granted now I guess :) Cheers.
- brandmeyer 8y agoIf you have a copy of Knuth's Art of Computer Programming, the section on seminumerical algorithms covers software floating point. Another source is the Handbook of Floating Point Arithmetic, which covers both hardware and software methods in detail. An implementation in source code may be found in libgcc. IIRC their ARM assembly code versions are some of the fastest routines available anywhere for software floating point emulation. While they are in assembly, ARM assembly is fairly intelligible. Finally, you can probably come up with 90% or more of the correct solutions yourself if you start with the definition of a floating-point number as (-1)^s * 1.m * 2^(e - bias) and grind through the algebra with the bias as a constant. The theorems that prove the minimum number and nature of the guard bits to get correct rounding are another matter, but you can start off by computing the equivalent infinite-precision terms and then rounding.
- pkaye 8y agoA floating point number consists of 3 parts: mantissa, exponent and sign. These are usually packing into a 32-bit or 64-bit value. So you can split them back into 3 integers and do the integer adds, multiply and shifts to get the result and pack them back. It is not hard to implement a basic version but to make it fast and comply with the standard is a bit more work.