Hacker News new | past | comments | ask | show | jobs | submit login

> This has some interesting implications – there’s no ‘divide’ instruction, for instance, because it can take a variable amount of time to finish. To perform a divide, you need to first compute the ‘reciprocal approximation’ (something we can do in exactly 13 cycles, it turns out) of the denominator value, and then perform a separate multiply of that result with the numerator.

Note that the special sauce behind this is the same as the special sauce behind fast inverse square root. The integer bitwise components of a floating point number permit a really good approximation of the log base 2 of it. And once you have the log base 2 of a number simple arithmetic does interesting operations.

log2(x^-.5) = -.5 \* log2(x)

log2(x^-1) = -log2(x)

The same trick can be used to calculate any constant power over the range [-1,1]. -.5 is the most famous for whatever reason, probably because of the "what the fuck?" comment in the open source quake code.

I'm not entirely sure why this knowledge was known at Cray, then lost, and had to be rediscovered at SGI or whatever. And I'm not entirely convinced it ever was lost. But if it was lost, I imagine it had something to do with replacing engineers whose bread and butter was done on a sliderule (which is inherently built on the premise of manipulating logs of numbers) with engineers who always had a pocket calculator.




   > The same trick can be used to calculate any constant power over
   > the range [-1,1]. -.5 is the most famous for whatever reason,
   > probably because of the "what the fuck?" comment in the open. 
 >  source quake code.
That was an interesting read, thanks!


I remember when I was learning 6502 it didn't have an add instruction. You had to clear carry, then add with carry.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: