3 ms·
The obvious question this invites: if this is generally faster for unknown values, why don't compilers use this optimization directly in emitted code?
by int_19h 4y ago
The obvious question this invites: if this is generally faster for unknown values, why don't compilers use this optimization directly in emitted code?
- baruch 4y agoCalculating the divisor values is also expensive, this works when you do this work once and then do the efficient divides multiple times.
- _a_a_a_ 4y ago> 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.
- moonchild 4y agoThey 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?