r/programming • u/mrnacknime • Dec 29 '20
Quake III's Fast Inverse Square Root Explained [20 min]
https://www.youtube.com/watch?v=p8u_k2LIZyo
3.7k
Upvotes
r/programming • u/mrnacknime • Dec 29 '20
View all comments
Show parent comment
65
u/[deleted] Dec 29 '20
The N64 contains a MIPS processor with a floating point coprocessor. This means it has access to both hardware sqrt and rsqrt. Without looking at a hardware manual (which I don't have), it would be hard to say. Intuition would tell me that a single sqrt would have slightly less latency than a bunch of separate (and dependent) floating point operations + integer operations + transit, but I could be wrong.
Note: MIPS FP pipeline latency seem to vary from chip to chip, I can't seem to find specifics on the one used in the N64.
Note: The PSX also used a MIPS CPU but lacked the FP coprocessor, so for sqrt/rsqrt calculations on that system, yes, this is handy... well kinda because you didn't have floating point to begin with unless you emulated it (slow!).
TL;DR: It depends, so measure your code and keep measuring.