News for hackers. Stuff that matters.
Re:Clever code is probably the worst code you could write by vlovich123 on Wednesday May 22, 2024 @01:37PM (#40443736)
Are you sure that the compiler doesn’t autovectorize a simple loop into this form anyway? This is kind of the defacto scenario for that pass.
Re:Clever code is probably the worst code you could write by im3w1l on Wednesday May 22, 2024 @03:23PM (#40445124)
This transformation is only legal if order of summation doesn't matter. So the compiler can do it for ints, but not floats.
Re:Clever code is probably the worst code you could write by vlovich123 on Wednesday May 22, 2024 @09:54PM (#40449501)
Applying std::reduce to floats would be a similarly bad idea for having the compiler do it, except people will write it without thinking. Of course, people always struggle with writing correct floating point so I doubt it makes things better or worse, but it’s conceptually the library equivalent of -fast-math (which coincidentally would also auto-vectorize the loop but can impact more than just that).
Re:Clever code is probably the worst code you could write by im3w1l on Thursday May 23, 2024 @02:51PM (#40458414)
Using fast math in one particular expression is way different and less risky than doing it globally.