-
Notifications
You must be signed in to change notification settings - Fork 13.4k
255u8.leading_zeros() is wrong on emscripten #39119
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
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 But that seems to not be what's happening here. It's apparently sent as |
@kripken sure yeah, for this rust program: pub fn main() -> u32 {
255u8.leading_zeros()
} I get this IR (unoptimized): ; ModuleID = 'foo.cgu-0.rs'
source_filename = "foo.cgu-0.rs"
target datalayout = "e-p:32:32-i64:64-v128:32:128-n32-S128"
target triple = "asmjs-unknown-emscripten"
; Function Attrs: inlinehint uwtable
define internal i32 @"_ZN4core3num20_$LT$impl$u20$u8$GT$13leading_zeros17h0d6a1b849828bff0E"(i8) unnamed_addr #0 {
entry-block:
%tmp_ret = alloca i8
br label %start
start: ; preds = %entry-block
%1 = call i8 @llvm.ctlz.i8(i8 %0, i1 false)
store i8 %1, i8* %tmp_ret
%2 = load i8, i8* %tmp_ret
br label %bb1
bb1: ; preds = %start
%3 = zext i8 %2 to i32
ret i32 %3
}
; Function Attrs: uwtable
define i32 @_ZN3foo4main17ha0ecef40c3578f1eE() unnamed_addr #1 {
entry-block:
br label %start
start: ; preds = %entry-block
%0 = call i32 @"_ZN4core3num20_$LT$impl$u20$u8$GT$13leading_zeros17h0d6a1b849828bff0E"(i8 -1)
br label %bb1
bb1: ; preds = %start
ret i32 %0
}
; Function Attrs: nounwind readnone
declare i8 @llvm.ctlz.i8(i8, i1) #2
attributes #0 = { inlinehint uwtable }
attributes #1 = { uwtable }
attributes #2 = { nounwind readnone } I agree that something's getting sign extended, I'm just not sure where :( |
…g i8/i16 values - while normally we can assume that the top bits are clear due to how LLVM creates the call, if the call is an ffi or constructed in a non-clang way (see rust-lang/rust#39119) then we must be careful
…g i8/i16 values - while normally we can assume that the top bits are clear due to how LLVM creates the call, if the call is an ffi or constructed in a non-clang way (see rust-lang/rust#39119 - rust emits a negative constant i8 -1 instead of clang's i8 255) then we must be careful
Great, perfect. So the issue is clang emits |
Awesome, thanks for the quick fix @kripken! |
Thanks @kripken ! |
…g i8/i16 values - while normally we can assume that the top bits are clear due to how LLVM creates the call, if the call is an ffi or constructed in a non-clang way (see rust-lang/rust#39119 - rust emits a negative constant i8 -1 instead of clang's i8 255) then we must be careful (#4865)
This commit adds a new entry to the Travis matrix which will execute emscripten test suites. Along the way it updates a few bits of the test suite to continue passing on emscripten, such as: * Ignoring i128/u128 tests as they're presumably just not working (didn't investigate as to why) * Disabling a few process tests (not working on emscripten) * Ignore some num tests in libstd (rust-lang#39119) * Fix some warnings when compiling
travis: Get an emscripten builder online This commit adds a new entry to the Travis matrix which will execute emscripten test suites. Along the way it updates a few bits of the test suite to continue passing on emscripten, such as: * Ignoring i128/u128 tests as they're presumably just not working (didn't investigate as to why) * Disabling a few process tests (not working on emscripten) * Ignore some num tests in libstd (rust-lang#39119) * Fix some warnings when compiling
I believe this has since been fixed |
Running some tests this program is incorrect when run through emscripten currently:
This program prints 232 when I'd expect 0. This may be due to the implementation in emscripten-core/emscripten#4544 which looks like:
(in the compiled JS at least)
x
coming in is-1
, soMath_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?
The text was updated successfully, but these errors were encountered: