Closed
Description
Running some tests this program is incorrect when run through emscripten currently:
fn main() {
println!("{}", 255u8.leading_zeros());
}
This program prints 232 when I'd expect 0. This may be due to the implementation in emscripten-core/emscripten#4544 which looks like:
function _llvm_ctlz_i8(x, isZeroUndef) {
x = x | 0;
isZeroUndef = isZeroUndef | 0;
return (Math_clz32(x) | 0) - 24 | 0;
}
(in the compiled JS at least)
x
coming in is -1
, so Math_clz32(x)
returns 0, and then chopping of 24 returns -24. When interpreted as a u8 that's 232 (what we see).
@kripken I'm not familiar with asmjs internals/representations, but is this a bug in the intrinsic? Or perhaps in our own representation of integers along the line? Or did I get unlucky with an LLVM mismatch or something?