summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-10-02 21:38:20 -0700
committerGitHub <noreply@github.com>2016-10-02 21:38:20 -0700
commit652d70cecc75fbcb4933bdc695be4d2be168f16f (patch)
tree3bcd048c77ba16dfd2326ddfd425feeeaff15489
parent9046e5fb540c92c7d994ba72893c724415ab371b (diff)
downloadbinaryen-652d70cecc75fbcb4933bdc695be4d2be168f16f.tar.gz
binaryen-652d70cecc75fbcb4933bdc695be4d2be168f16f.tar.bz2
binaryen-652d70cecc75fbcb4933bdc695be4d2be168f16f.zip
wasm-only additions: i32.cttz, copysign, popcnt (#729)
-rw-r--r--src/asm2wasm.h21
-rw-r--r--test/wasm-only.asm.js7
-rw-r--r--test/wasm-only.fromasm9
-rw-r--r--test/wasm-only.fromasm.imprecise9
-rw-r--r--test/wasm-only.fromasm.imprecise.no-opts32
-rw-r--r--test/wasm-only.fromasm.no-opts32
6 files changed, 105 insertions, 5 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index f413cbe9e..9f0276737 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -42,7 +42,11 @@ using namespace cashew;
// Names
-Name I64("i64"),
+Name I32_CTTZ("i32_cttz"),
+ I32_CTPOP("i32_ctpop"),
+ I32_BC2F("i32_bc2f"),
+ I32_BC2I("i32_bc2i"),
+ I64("i64"),
I64_CONST("i64_const"),
I64_ADD("i64_add"),
I64_SUB("i64_sub"),
@@ -82,10 +86,13 @@ Name I64("i64"),
I64_BC2I("i64_bc2i"),
I64_CTTZ("i64_cttz"),
I64_CTLZ("i64_ctlz"),
+ I64_CTPOP("i64_ctpop"),
I64S_REM("i64s-rem"),
I64U_REM("i64u-rem"),
I64S_DIV("i64s-div"),
I64U_DIV("i64u-div"),
+ F32_COPYSIGN("f32_copysign"),
+ F64_COPYSIGN("f64_copysign"),
LOAD1("load1"),
LOAD2("load2"),
LOAD4("load4"),
@@ -97,9 +104,7 @@ Name I64("i64"),
STORE4("store4"),
STORE8("store8"),
STOREF("storef"),
- STORED("stored"),
- I32_BC2F("i32_bc2f"),
- I32_BC2I("i32_bc2i");
+ STORED("stored");
// Utilities
@@ -1577,6 +1582,8 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
return value;
}
}
+ if (name == I32_CTTZ) return builder.makeUnary(UnaryOp::CtzInt32, value);
+ if (name == I32_CTPOP) return builder.makeUnary(UnaryOp::PopcntInt32, value);
if (name == I32_BC2F) return builder.makeUnary(UnaryOp::ReinterpretInt32, value);
if (name == I32_BC2I) return builder.makeUnary(UnaryOp::ReinterpretFloat32, value);
@@ -1595,6 +1602,7 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
if (name == I64_BC2I) return builder.makeUnary(UnaryOp::ReinterpretFloat64, value);
if (name == I64_CTTZ) return builder.makeUnary(UnaryOp::CtzInt64, value);
if (name == I64_CTLZ) return builder.makeUnary(UnaryOp::ClzInt64, value);
+ if (name == I64_CTPOP) return builder.makeUnary(UnaryOp::PopcntInt64, value);
} else if (num == 2) { // 2 params,binary
if (name == I64_CONST) return builder.makeConst(getLiteral(ast));
auto* left = process(ast[2][0]);
@@ -1627,6 +1635,11 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
}
break;
}
+ case 'f': {
+ if (name == F32_COPYSIGN) return builder.makeBinary(BinaryOp::CopySignFloat32, process(ast[2][0]), process(ast[2][1]));
+ if (name == F64_COPYSIGN) return builder.makeBinary(BinaryOp::CopySignFloat64, process(ast[2][0]), process(ast[2][1]));
+ break;
+ }
default: {}
}
}
diff --git a/test/wasm-only.asm.js b/test/wasm-only.asm.js
index 568687904..8dc208372 100644
--- a/test/wasm-only.asm.js
+++ b/test/wasm-only.asm.js
@@ -74,10 +74,15 @@ function asm(global, env, buffer) {
}
function test() {
- var i = 0, f = fround(0);
+ var i = 0, j = i64(), f = fround(0), f1 = fround(0), f2 = fround(0), d1 = +0, d2 = +0;
// bitcasts
i = i32_bc2i(f);
f = i32_bc2f(i);
+ i = i32_cttz(i);
+ i = i32_ctpop(i);
+ j = i64_ctpop(j);
+ f1 = f32_copysign(f1, f2);
+ d1 = f64_copysign(d1, d2);
}
function test64() {
diff --git a/test/wasm-only.fromasm b/test/wasm-only.fromasm
index 8f3b2fa5c..e8f8cfc79 100644
--- a/test/wasm-only.fromasm
+++ b/test/wasm-only.fromasm
@@ -111,6 +111,15 @@
(get_local $1)
)
)
+ (func $test
+ (local $0 f32)
+ (local $1 i32)
+ (set_local $1
+ (i32.reinterpret/f32
+ (get_local $0)
+ )
+ )
+ )
(func $i64u-div (param $0 i64) (param $1 i64) (result i64)
(select
(i64.const 0)
diff --git a/test/wasm-only.fromasm.imprecise b/test/wasm-only.fromasm.imprecise
index ac76c6c90..b27eb3f9b 100644
--- a/test/wasm-only.fromasm.imprecise
+++ b/test/wasm-only.fromasm.imprecise
@@ -110,6 +110,15 @@
(get_local $1)
)
)
+ (func $test
+ (local $0 f32)
+ (local $1 i32)
+ (set_local $1
+ (i32.reinterpret/f32
+ (get_local $0)
+ )
+ )
+ )
(func $test64
(local $0 i64)
(local $1 i32)
diff --git a/test/wasm-only.fromasm.imprecise.no-opts b/test/wasm-only.fromasm.imprecise.no-opts
index 78050d9cd..dfd7db50e 100644
--- a/test/wasm-only.fromasm.imprecise.no-opts
+++ b/test/wasm-only.fromasm.imprecise.no-opts
@@ -224,7 +224,12 @@
)
(func $test
(local $i i32)
+ (local $j i64)
(local $f f32)
+ (local $f1 f32)
+ (local $f2 f32)
+ (local $d1 f64)
+ (local $d2 f64)
(set_local $i
(i32.reinterpret/f32
(get_local $f)
@@ -235,6 +240,33 @@
(get_local $i)
)
)
+ (set_local $i
+ (i32.ctz
+ (get_local $i)
+ )
+ )
+ (set_local $i
+ (i32.popcnt
+ (get_local $i)
+ )
+ )
+ (set_local $j
+ (i64.popcnt
+ (get_local $j)
+ )
+ )
+ (set_local $f1
+ (f32.copysign
+ (get_local $f1)
+ (get_local $f2)
+ )
+ )
+ (set_local $d1
+ (f64.copysign
+ (get_local $d1)
+ (get_local $d2)
+ )
+ )
)
(func $test64
(local $x i64)
diff --git a/test/wasm-only.fromasm.no-opts b/test/wasm-only.fromasm.no-opts
index 31840158b..491abf98f 100644
--- a/test/wasm-only.fromasm.no-opts
+++ b/test/wasm-only.fromasm.no-opts
@@ -224,7 +224,12 @@
)
(func $test
(local $i i32)
+ (local $j i64)
(local $f f32)
+ (local $f1 f32)
+ (local $f2 f32)
+ (local $d1 f64)
+ (local $d2 f64)
(set_local $i
(i32.reinterpret/f32
(get_local $f)
@@ -235,6 +240,33 @@
(get_local $i)
)
)
+ (set_local $i
+ (i32.ctz
+ (get_local $i)
+ )
+ )
+ (set_local $i
+ (i32.popcnt
+ (get_local $i)
+ )
+ )
+ (set_local $j
+ (i64.popcnt
+ (get_local $j)
+ )
+ )
+ (set_local $f1
+ (f32.copysign
+ (get_local $f1)
+ (get_local $f2)
+ )
+ )
+ (set_local $d1
+ (f64.copysign
+ (get_local $d1)
+ (get_local $d2)
+ )
+ )
)
(func $i64u-div (param $0 i64) (param $1 i64) (result i64)
(if i64