summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-12-07 16:42:59 -0800
committerAlon Zakai <alonzakai@gmail.com>2015-12-07 16:42:59 -0800
commit246bf84adcba84abc96cc6910ca4b5a0898d6c46 (patch)
tree18eabb38ce6f076d5c7303a81702623d9f149a0d
parent4f542922b1b42536be31f6c1987b976f39a921b7 (diff)
downloadbinaryen-246bf84adcba84abc96cc6910ca4b5a0898d6c46.tar.gz
binaryen-246bf84adcba84abc96cc6910ca4b5a0898d6c46.tar.bz2
binaryen-246bf84adcba84abc96cc6910ca4b5a0898d6c46.zip
fix sign-aware div/mod
-rw-r--r--src/wasm2asm.h8
-rw-r--r--test/emcc_O2_hello_world.2asm.js2
-rw-r--r--test/unit.2asm.js2
3 files changed, 6 insertions, 6 deletions
diff --git a/src/wasm2asm.h b/src/wasm2asm.h
index d0c79097f..1898da415 100644
--- a/src/wasm2asm.h
+++ b/src/wasm2asm.h
@@ -940,10 +940,10 @@ Ref Wasm2AsmBuilder::processFunctionBody(Expression* curr, IString result) {
return ValueBuilder::makeBinary(left, MINUS, right); break;
}
}
- case DivS: ret = ValueBuilder::makeBinary(left, DIV, right); break;
- case DivU: ret = ValueBuilder::makeBinary(left, DIV, right); break;
- case RemS: ret = ValueBuilder::makeBinary(left, MOD, right); break;
- case RemU: ret = ValueBuilder::makeBinary(left, MOD, right); break;
+ case DivS: ret = ValueBuilder::makeBinary(makeSigning(left, ASM_SIGNED), DIV, makeSigning(right, ASM_SIGNED)); break;
+ case DivU: ret = ValueBuilder::makeBinary(makeSigning(left, ASM_UNSIGNED), DIV, makeSigning(right, ASM_UNSIGNED)); break;
+ case RemS: ret = ValueBuilder::makeBinary(makeSigning(left, ASM_SIGNED), MOD, makeSigning(right, ASM_SIGNED)); break;
+ case RemU: ret = ValueBuilder::makeBinary(makeSigning(left, ASM_UNSIGNED), MOD, makeSigning(right, ASM_UNSIGNED)); break;
case And: ret = ValueBuilder::makeBinary(left, AND, right); break;
case Or: ret = ValueBuilder::makeBinary(left, OR, right); break;
case Xor: ret = ValueBuilder::makeBinary(left, XOR, right); break;
diff --git a/test/emcc_O2_hello_world.2asm.js b/test/emcc_O2_hello_world.2asm.js
index 184a6e34e..a6c665d01 100644
--- a/test/emcc_O2_hello_world.2asm.js
+++ b/test/emcc_O2_hello_world.2asm.js
@@ -2314,7 +2314,7 @@ function asmFunc(global, env, buffer) {
i8 = i7;
}
} else i8 = ___fwritex(i1 | 0, i5 | 0, i4 | 0) | 0;
- if ((i8 | 0) == (i5 | 0)) i9 = i3; else i9 = (i8 >>> 0 | 0) / (i2 >>> 0 | 0) | 0;
+ if ((i8 | 0) == (i5 | 0)) i9 = i3; else i9 = ((i8 >>> 0 | 0) >>> 0) / ((i2 >>> 0 | 0) >>> 0) | 0;
wasm2asm_i32$0 = i9;
}
return wasm2asm_i32$0 | 0;
diff --git a/test/unit.2asm.js b/test/unit.2asm.js
index 50cc1a866..8e90926b0 100644
--- a/test/unit.2asm.js
+++ b/test/unit.2asm.js
@@ -165,7 +165,7 @@ function asmFunc(global, env, buffer) {
function big_uint_div_u() {
var x = 0, wasm2asm_i32$0 = 0;
topmost : {
- x = (4294967295 / 2 | 0) & 4294967295 | 0;
+ x = ((4294967295 >>> 0) / (2 >>> 0) | 0) & 4294967295 | 0;
wasm2asm_i32$0 = x;
}
return wasm2asm_i32$0 | 0;