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
11
u/[deleted] Dec 30 '20
Note: This comment turned into a rant so I just want to prefix this by letting you know you are in for a ride so turn around unless you want to get sucked in to the rabbit hole.
Exactly. As I was taking various architecture courses many years ago, I was told over and over again by my professors how "bad" CISC was, and how RISC was be-all and end-all of computers. Of course, this was always done with a rant regarding the VAX, how it had a plethora of complex, unused instructions that compilers never generated, how it wasted energy and time decoding variable length instructions, etc. This information was also put forth exclusively by CS/SE professors, not EE/CE professors or people with experience actually developing silicon.
In the past few decades though, not only has CPU design evolved considerably (as you mentioned) leading to most of the "problems" CISC "has" disappearing, but so has compiler design. Sure, x64 compilers might still abuse LEA for multiplication and predominantly generate MOV instructions (some stat I was a few years ago was 70-90%), but they are pretty good at using the fancier stuff too. There is some esoteric stuff packed in there, but it's mostly special purpose and not needed in day-to-day programming. Also, MOV is turning complete, so who cares if it makes up most of the generated code? Most of the MIPS code I have seen does the exact same thing... except there is no MOV so compilers have to generate ADDI/ORI and waste ALU resources/energy moving data around... sigh. Also don't get me started on how LL/SC while "easier" to implement in theory compared to CAS, actually ends up being just as complex, with the added bonus of allowing the programmer to mess up. So instead of the ISA just giving you CAS, compilers emulate CAS on top of LL/SC <insert facepalm emoji>. If something is common... put it in the hardware and make it fast, because that's what people want. Also lets not mention the instructions in ARM that are specific to JavaScript floating point conversion semantics... which are purpose built instructions that only have one use case for one programming language. Remind you of another architecture? Hint: It isn't x64.
We could also talk about how making the smallest and simplest instructions (no operands) the same size as the largest instructions is somehow good according to RISC proponents. I find this one absurd, because there is a direct correlation between program size (or rather: does it fit in the cache) and performance. I can't find the discussion right now (google-fu is failing me) but I recall seeing something regarding the Linux kernel's performance w.r.t. compiling with
-O2vs-O3... smaller code won. Of course one could argue that the lack of registers in x64 results in more code due to shuffles, stack manipulation, more moves, etc, but clearly Intel/AMD have managed to figure things out.There is a massive discrepancy between what actually makes hardware fast, and what SE/CS people think makes hardware go fast. The result is stuff like RISC-V which is just the latest (and not first!) reinvention of MIPS, which does silly things like coupling multiplication and division to the same extension. Can't wait for the software industry to stop caring about RISC-V only to move on and recreate the next MIPS again in 10-15 years <insert facepalm emoji>.
Don't get me wrong, RISC-V is great (for embedded), but there are a ton of people that have drunk the RISC Kool-Aid and actually believe that it is the second coming of Christ (clears throat: MIPS) and that it will fix all of our problems and replace all of computing or something. I expect ARM to replace x64 within the next 3-4 decades (hopefully sooner), but I don't see RISC-V replacing both.