signed-unsigned-div-mod.js (1884B)
1 // The result should be -1 because it is (i32.rem_s -1 10000) and the spec 2 // stipulates "result has the sign of the dividend". This test uncovers a bug 3 // in SpiderMonkey wherein the shape of the lhs (it looks like an unsigned 4 // value) causes an unsigned modulo to be emitted. 5 6 assertEq(wasmEvalText( 7 `(module 8 (func (result i32) 9 (i32.const -1) 10 (i32.const 0) 11 i32.shr_u 12 (i32.const 10000) 13 i32.rem_s) 14 (export "f" (func 0)))`).exports.f(), -1); 15 16 // Ditto for int64 17 18 wasmAssert( 19 `(module 20 (func $run (result i64) 21 (i64.const -1) 22 (i64.const 0) 23 i64.shr_u 24 (i64.const 10000) 25 i64.rem_s) 26 )`, [{type:'i64', expected:'0xffffffffffffffff', func:'$run'}]); 27 28 // Despite the signed shift this is 0x80000000 % 10000 (rem_u) 29 // and the result is positive. 30 31 assertEq(wasmEvalText( 32 `(module 33 (func (result i32) 34 (i32.const -1) 35 (i32.const 0) 36 i32.shl 37 (i32.const 10000) 38 i32.rem_u) 39 (export "f" (func 0)))`).exports.f(), 7295); 40 41 // 0x80000000 is really -0x80000000 so the result of signed division shall be 42 // negative. 43 44 assertEq(wasmEvalText( 45 `(module 46 (func (result i32) 47 (i32.const 0x80000000) 48 (i32.const 0) 49 i32.shr_u 50 (i32.const 10000) 51 i32.div_s) 52 (export "f" (func 0)))`).exports.f(), -214748); 53 54 assertEq(wasmEvalText( 55 `(module 56 (func (result i32) 57 (i32.const 0x80000000) 58 (i32.const 0) 59 i32.shr_u 60 (i32.const -10000) 61 i32.div_s) 62 (export "f" (func 0)))`).exports.f(), 214748); 63 64 // And the result of unsigned division shall be positive. 65 66 assertEq(wasmEvalText( 67 `(module 68 (func (result i32) 69 (i32.const 0x80000000) 70 (i32.const 0) 71 i32.shr_u 72 (i32.const 10000) 73 i32.div_u) 74 (export "f" (func 0)))`).exports.f(), 214748);