summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2017-09-23 20:50:15 -0700
committerGitHub <noreply@github.com>2017-09-23 20:50:15 -0700
commit23d015b159e6805022cfac1797030fbec42aa8d1 (patch)
tree6b13676ce0c020e376eb1ca7b5654589180455a8
parentde54837f0ff631cd8f215a447b15cb3d9d99fdff (diff)
downloadbinaryen-23d015b159e6805022cfac1797030fbec42aa8d1.tar.gz
binaryen-23d015b159e6805022cfac1797030fbec42aa8d1.tar.bz2
binaryen-23d015b159e6805022cfac1797030fbec42aa8d1.zip
wasm2asm fixes for coercion on rotl/rotr/ctz/popcnt calls, and refactor the name of constants to include the WASM_ prefix so as not to collide with constants for the unprefixed values (#1199)
-rw-r--r--src/asmjs/shared-constants.cpp19
-rw-r--r--src/asmjs/shared-constants.h19
-rw-r--r--src/wasm2asm.h39
-rw-r--r--test/i32.2asm.js8
4 files changed, 52 insertions, 33 deletions
diff --git a/src/asmjs/shared-constants.cpp b/src/asmjs/shared-constants.cpp
index 6e92f1b3e..43c3d1065 100644
--- a/src/asmjs/shared-constants.cpp
+++ b/src/asmjs/shared-constants.cpp
@@ -62,18 +62,21 @@ cashew::IString GLOBAL("global"),
MATH_IMUL("Math_imul"),
MATH_ABS("Math_abs"),
MATH_CEIL("Math_ceil"),
+ MATH_CLZ32("Math_clz32"),
MATH_FLOOR("Math_floor"),
MATH_TRUNC("Math_trunc"),
MATH_NEAREST("Math_NEAREST"),
MATH_SQRT("Math_sqrt"),
MATH_MIN("Math_min"),
MATH_MAX("Math_max"),
- CTZ32("__wasm_ctz_i32"),
- CTZ64("__wasm_ctz_i64"),
- POPCNT32("__wasm_popcnt_i32"),
- POPCNT64("__wasm_popcnt_i64"),
- ROTL32("__wasm_rotl_i32"),
- ROTL64("__wasm_rotl_i64"),
- ROTR32("__wasm_rotr_i32"),
- ROTR64("__wasm_rotr_i64");
+ WASM_CTZ32("__wasm_ctz_i32"),
+ WASM_CTZ64("__wasm_ctz_i64"),
+ WASM_CLZ32("__wasm_clz_i32"),
+ WASM_CLZ64("__wasm_clz_i64"),
+ WASM_POPCNT32("__wasm_popcnt_i32"),
+ WASM_POPCNT64("__wasm_popcnt_i64"),
+ WASM_ROTL32("__wasm_rotl_i32"),
+ WASM_ROTL64("__wasm_rotl_i64"),
+ WASM_ROTR32("__wasm_rotr_i32"),
+ WASM_ROTR64("__wasm_rotr_i64");
}
diff --git a/src/asmjs/shared-constants.h b/src/asmjs/shared-constants.h
index 555efce6a..ce5cd95a6 100644
--- a/src/asmjs/shared-constants.h
+++ b/src/asmjs/shared-constants.h
@@ -65,20 +65,23 @@ extern cashew::IString GLOBAL,
MATH_IMUL,
MATH_ABS,
MATH_CEIL,
+ MATH_CLZ32,
MATH_FLOOR,
MATH_TRUNC,
MATH_NEAREST,
MATH_SQRT,
MATH_MIN,
MATH_MAX,
- CTZ32,
- CTZ64,
- POPCNT32,
- POPCNT64,
- ROTL32,
- ROTL64,
- ROTR32,
- ROTR64;
+ WASM_CTZ32,
+ WASM_CTZ64,
+ WASM_CLZ32,
+ WASM_CLZ64,
+ WASM_POPCNT32,
+ WASM_POPCNT64,
+ WASM_ROTL32,
+ WASM_ROTL64,
+ WASM_ROTR32,
+ WASM_ROTR64;
}
#endif // wasm_asmjs_shared_constants_h
diff --git a/src/wasm2asm.h b/src/wasm2asm.h
index ef3ab0c0d..7be5c72f6 100644
--- a/src/wasm2asm.h
+++ b/src/wasm2asm.h
@@ -227,7 +227,7 @@ static Function* makeCtzFunc(MixedArena& allocator, UnaryOp op) {
Builder b(allocator);
// if eqz(x) then 32 else (32 - clz(x ^ (x - 1)))
bool is32Bit = (op == CtzInt32);
- Name funcName = is32Bit ? Name(CTZ32) : Name(CTZ64);
+ Name funcName = is32Bit ? Name(WASM_CTZ32) : Name(WASM_CTZ64);
BinaryOp subOp = is32Bit ? SubInt32 : SubInt64;
BinaryOp xorOp = is32Bit ? XorInt32 : XorInt64;
UnaryOp clzOp = is32Bit ? ClzInt32 : ClzInt64;
@@ -270,7 +270,7 @@ static Function* makePopcntFunc(MixedArena& allocator, UnaryOp op) {
// popcnt implemented as:
// int c; for (c = 0; x != 0; c++) { x = x & (x - 1) }; return c
bool is32Bit = (op == PopcntInt32);
- Name funcName = is32Bit ? Name(POPCNT32) : Name(POPCNT64);
+ Name funcName = is32Bit ? Name(WASM_POPCNT32) : Name(WASM_POPCNT64);
BinaryOp addOp = is32Bit ? AddInt32 : AddInt64;
BinaryOp subOp = is32Bit ? SubInt32 : SubInt64;
BinaryOp andOp = is32Bit ? AndInt32 : AndInt64;
@@ -328,8 +328,8 @@ Function* makeRotFunc(MixedArena& allocator, BinaryOp op) {
// where k is shift modulo w. reverse shifts for right rotate
bool is32Bit = (op == RotLInt32 || op == RotRInt32);
bool isLRot = (op == RotLInt32 || op == RotLInt64);
- static Name names[2][2] = {{Name(ROTR64), Name(ROTR32)},
- {Name(ROTL64), Name(ROTL32)}};
+ static Name names[2][2] = {{Name(WASM_ROTR64), Name(WASM_ROTR32)},
+ {Name(WASM_ROTL64), Name(WASM_ROTL32)}};
static BinaryOp shifters[2][2] = {{ShrUInt64, ShrUInt32},
{ShlInt64, ShlInt32}};
Name funcName = names[isLRot][is32Bit];
@@ -1267,15 +1267,26 @@ Ref Wasm2AsmBuilder::processFunctionBody(Function* func, IString result) {
case i32: {
switch (curr->op) {
case ClzInt32:
- return ValueBuilder::makeCall(MATH_CLZ32,
- visit(curr->value,
- EXPRESSION_RESULT));
+ return ValueBuilder::makeCall(
+ MATH_CLZ32,
+ visit(curr->value, EXPRESSION_RESULT)
+ );
case CtzInt32:
- return ValueBuilder::makeCall(CTZ32, visit(curr->value,
- EXPRESSION_RESULT));
+ return makeSigning(
+ ValueBuilder::makeCall(
+ WASM_CTZ32,
+ visit(curr->value, EXPRESSION_RESULT)
+ ),
+ ASM_SIGNED
+ );
case PopcntInt32:
- return ValueBuilder::makeCall(POPCNT32, visit(curr->value,
- EXPRESSION_RESULT));
+ return makeSigning(
+ ValueBuilder::makeCall(
+ WASM_POPCNT32,
+ visit(curr->value, EXPRESSION_RESULT)
+ ),
+ ASM_SIGNED
+ );
case EqZInt32:
return ValueBuilder::makeBinary(
makeAsmCoercion(visit(curr->value,
@@ -1476,9 +1487,11 @@ Ref Wasm2AsmBuilder::processFunctionBody(Function* func, IString result) {
return ValueBuilder::makeBinary(makeSigning(left, ASM_UNSIGNED), GE,
makeSigning(right, ASM_UNSIGNED));
case RotLInt32:
- return ValueBuilder::makeCall(ROTL32, left, right);
+ return makeSigning(ValueBuilder::makeCall(WASM_ROTL32, left, right),
+ ASM_SIGNED);
case RotRInt32:
- return ValueBuilder::makeCall(ROTR32, left, right);
+ return makeSigning(ValueBuilder::makeCall(WASM_ROTR32, left, right),
+ ASM_SIGNED);
default: {
std::cerr << "Unhandled binary operator: " << curr << std::endl;
abort();
diff --git a/test/i32.2asm.js b/test/i32.2asm.js
index bd6f7e221..0c94f23b7 100644
--- a/test/i32.2asm.js
+++ b/test/i32.2asm.js
@@ -93,13 +93,13 @@ function asmFunc(global, env, buffer) {
function $$13(x, y) {
x = x | 0;
y = y | 0;
- return __wasm_rotl_i32(x, y) | 0;
+ return __wasm_rotl_i32(x, y) | 0 | 0;
}
function $$14(x, y) {
x = x | 0;
y = y | 0;
- return __wasm_rotr_i32(x, y) | 0;
+ return __wasm_rotr_i32(x, y) | 0 | 0;
}
function $$15(x) {
@@ -109,12 +109,12 @@ function asmFunc(global, env, buffer) {
function $$16(x) {
x = x | 0;
- return __wasm_ctz_i32(x) | 0;
+ return __wasm_ctz_i32(x) | 0 | 0;
}
function $$17(x) {
x = x | 0;
- return __wasm_popcnt_i32(x) | 0;
+ return __wasm_popcnt_i32(x) | 0 | 0;
}
function $$18(x) {