You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
255u8.leading_zeros() is wrong on emscripten #39119
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?
It does seem like the asm.js implementation of that intrinsic should be modified to just look at the lower 8 bits, instead of assuming the top 24 are zero. I'll do that. However, I worry there is something more generally wrong here.
I would expect 255u8 to be an llvm i8, which is then sent into the LLVM intrinsic which receives an i8. After compilation to JS, any math operation on it should preserve that only the lower 8 bits are used (since we &255 after e.g. addition etc. - that's why we assume we can look at only the lower 8 bits; but, in certain ffi conditions, that might be false, which is why I want to fix it in emscripten as I said).
But that seems to not be what's happening here. It's apparently sent as 0xffffffff, which means it was sign-extended, despite being unsigned, and despite the intrinsic expecting an i8 so no extension should have been done.. Did that happen on the rust side, llvm side, or emscripten side? Bitcode could help.
Great, perfect. So the issue is clang emits i8 255 for such constants, but rust i8 -1, and we just never handled the latter case, and indeed the intrinsics need fixing, but there is no deeper issue hidden here. Fix in emscripten-core/emscripten#4865
Activity
kripken commentedon Jan 17, 2017
It does seem like the asm.js implementation of that intrinsic should be modified to just look at the lower 8 bits, instead of assuming the top 24 are zero. I'll do that. However, I worry there is something more generally wrong here.
I would expect
255u8to be an llvm i8, which is then sent into the LLVM intrinsic which receives an i8. After compilation to JS, any math operation on it should preserve that only the lower 8 bits are used (since we&255after e.g. addition etc. - that's why we assume we can look at only the lower 8 bits; but, in certain ffi conditions, that might be false, which is why I want to fix it in emscripten as I said).But that seems to not be what's happening here. It's apparently sent as
0xffffffff, which means it was sign-extended, despite being unsigned, and despite the intrinsic expecting an i8 so no extension should have been done.. Did that happen on the rust side, llvm side, or emscripten side? Bitcode could help.alexcrichton commentedon Jan 17, 2017
@kripken sure yeah, for this rust program:
I get this IR (unoptimized):
I agree that something's getting sign extended, I'm just not sure where :(
do not assume anything about the top bits in llvm intrinsics receivin…
do not assume anything about the top bits in llvm intrinsics receivin…
kripken commentedon Jan 17, 2017
Great, perfect. So the issue is clang emits
i8 255for such constants, but rusti8 -1, and we just never handled the latter case, and indeed the intrinsics need fixing, but there is no deeper issue hidden here. Fix in emscripten-core/emscripten#4865alexcrichton commentedon Jan 17, 2017
Awesome, thanks for the quick fix @kripken!
brson commentedon Jan 18, 2017
Thanks @kripken !
do not assume anything about the top bits in llvm intrinsics receivin…
travis: Get an emscripten builder online
Rollup merge of rust-lang#39120 - alexcrichton:emscripten-tests, r=brson
alexcrichton commentedon Aug 25, 2017
I believe this has since been fixed
remove FIXME(rust-lang#39119) and allow running test on emscripten