Rename Number.prototype.clz to Math.clz
brendan at mozilla.com
Tue Jan 28 15:07:16 PST 2014
Luke Wagner wrote:
> It seems to me that we*must* have Math.clz perform ToUint32() on its input. Otherwise (if ToInt32() is used), even if the expression is written "Math.clz(x>>> 0)", asm.js/type-inference won't be able to optimize away the<0 branch since the ToInt32() in the semantics of Math.clz will convert a large unsigned integer argument into a negative integer.
> Secondly, I think clz(0) should be 32, not 0:
> - for x86's bsr, since the result is undefined if the input is zero, we need a branch or cmov*anyway* to deal with zero.
> - to make up for bsr's shortcomings, newer x86 chips have lzcnt (which JITs can emit after testing the right cpuid bit), which defines clz(0) == 32.
> - ARM's clz also defines clz(0) == 32.
> The only reason not to do this I could imagine is if there was a de facto standard among all x86 chips (such that the JIT could rely on it) to have bsr(0) == 0, but I couldn't find any evidence of this.
Thanks, I just presented this pretty much verbatim, and Math.clz32 it
is, by TC39 consensus. ToUint32 on parameter, 0 => 32 and all.
More information about the es-discuss