News for hackers. Stuff that matters.
Re:Do Not Taunt Happy Fun Branch Predictor by david2ndaccount on Wednesday January 25, 2023 @02:10PM (#34522774)
He didn’t gain 10x from a micro optimization, he gained that much by converting it to use SIMD which is a macro optimization. You usually have to structure your program in such a way to be SIMD friendly. In this case it was already simd-friendly (adding a large number of floats).
Re:Do Not Taunt Happy Fun Branch Predictor by Jensson on Wednesday January 25, 2023 @03:38PM (#34523849)
> In this case it was already simd-friendly (adding a large number of floats).

So it was micro optimization afterall!

Re:Do Not Taunt Happy Fun Branch Predictor by lmm on Wednesday January 25, 2023 @05:25PM (#34525026)
It was a micro optimization because it was a toy example. Doing floating-point arithmetic (and not already using BLAS etc.) is very niche in real code.
Re:Do Not Taunt Happy Fun Branch Predictor by Jensson on Wednesday January 25, 2023 @05:28PM (#34525042)
It is still micro optimization to ensure that those instructions are used when the compiler is too dumb to use them. You can say that they are niche, but that is different from it being micro optimization.
Re:Do Not Taunt Happy Fun Branch Predictor by lmm on Wednesday January 25, 2023 @06:23PM (#34525615)
It's not the compiler being dumb, it won't use those extensions because they reassociate the arithmetic and change the result - and setting that compiler flag is very much a macro rather than micro change.
Re:Do Not Taunt Happy Fun Branch Predictor by Jensson on Wednesday January 25, 2023 @07:01PM (#34526000)
But he didn't set the compiler option, he rewrote it to explicitly use those instructions, that is micro optimization no matter how you look at it. The reason micro optimization is so easy to get better than compiler results is that you know things about the data the compiler doesn't, like in this case you know it is fine to reorder the result while the compiler is too dumb to know that. You need much smarter compilers than we have today in order for such micro optimizations to stop paying dividends.
Re:Do Not Taunt Happy Fun Branch Predictor by lmm on Wednesday January 25, 2023 @07:31PM (#34526252)
Making sure it will behave correctly with that change (which changes the result of the function!) is a macro change - you have to trace the implications all the way through the program.