News for hackers. Stuff that matters.
Re:Bitwise Division by int_19h on Wednesday March 01, 2023 @04:04PM (#34988317)
The obvious question this invites: if this is generally faster for unknown values, why don't compilers use this optimization directly in emitted code?
Re:Bitwise Division by _a_a_a_ on Wednesday March 01, 2023 @04:40PM (#34988720)
> Compilers usually do this, but only when the divisor is known at compile time

if the divisor is in a variable or otherwise 'hidden', the compiler can't deduce enought to get to it, is my guess.

Re:Bitwise Division by baruch on Wednesday March 01, 2023 @04:35PM (#34988675)
Calculating the divisor values is also expensive, this works when you do this work once and then do the efficient divides multiple times.
Re:Bitwise Division by moonchild on Wednesday March 01, 2023 @05:10PM (#34989045)
They could, but it's less profitable, and cost models are, as always, a big problem. If we have:

  loop for i from 0 to n
      f(a[i]/y)
How big does n have to be before it makes sense to compute a reciprocal for y? And how frequently is it actually that big during the runtime of the code?