summaryrefslogtreecommitdiff
path: root/src/asm2wasm.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2015-10-29 20:19:46 -0700
committerAlon Zakai <alonzakai@gmail.com>2015-10-29 20:19:46 -0700
commit39cef85d01a43b4f1352c065ddccc58d3b62bfe5 (patch)
tree7cea0d37841587dd555fd04c37fde5209d1c6731 /src/asm2wasm.cpp
parentf32ab820be47c968685dc5e24e27218bb0c9861c (diff)
downloadbinaryen-39cef85d01a43b4f1352c065ddccc58d3b62bfe5.tar.gz
binaryen-39cef85d01a43b4f1352c065ddccc58d3b62bfe5.tar.bz2
binaryen-39cef85d01a43b4f1352c065ddccc58d3b62bfe5.zip
clz
Diffstat (limited to 'src/asm2wasm.cpp')
-rw-r--r--src/asm2wasm.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/asm2wasm.cpp b/src/asm2wasm.cpp
index ac2c1d5e8..50f504c6a 100644
--- a/src/asm2wasm.cpp
+++ b/src/asm2wasm.cpp
@@ -24,7 +24,8 @@ IString GLOBAL("global"), NAN_("NaN"), INFINITY_("Infinity"),
FLOAT64ARRAY("Float64Array"),
IMPOSSIBLE_CONTINUE("impossible-continue"),
MATH("Math"),
- IMUL("imul");
+ IMUL("imul"),
+ CLZ32("clz32");
static void abort_on(std::string why) {
@@ -246,6 +247,7 @@ class Asm2WasmModule : public wasm::Module {
std::map<IString, View> views; // name (e.g. HEAP8) => view info
IString Math_imul; // imported name of Math.imul
+ IString Math_clz32; // imported name of Math.imul
// function types. we fill in this information as we see
// uses, in the first pass
@@ -466,10 +468,16 @@ void Asm2WasmModule::processAsm(Ref ast) {
if (module[0] == DOT) {
// we can have (global.Math).floor; skip the 'Math'
assert(module[1][0] == NAME);
- if (module[2] == MATH && imported[2] == IMUL) {
- assert(Math_imul.isNull());
- Math_imul = name;
- return;
+ if (module[2] == MATH) {
+ if (imported[2] == IMUL) {
+ assert(Math_imul.isNull());
+ Math_imul = name;
+ return;
+ } else if (imported[2] == CLZ32) {
+ assert(Math_clz32.isNull());
+ Math_clz32 = name;
+ return;
+ }
}
module = module[1];
}
@@ -885,6 +893,7 @@ Function* Asm2WasmModule::processFunction(Ref ast) {
if (ast[1][0] == NAME) {
IString name = ast[1][1]->getIString();
if (name == Math_imul) {
+ assert(ast[2]->size() == 2);
auto ret = allocator.alloc<Binary>();
ret->op = Mul;
ret->left = process(ast[2][0]);
@@ -892,6 +901,14 @@ Function* Asm2WasmModule::processFunction(Ref ast) {
ret->type = BasicType::i32;
return ret;
}
+ if (name == Math_clz32) {
+ assert(ast[2]->size() == 1);
+ auto ret = allocator.alloc<Unary>();
+ ret->op = Clz;
+ ret->value = process(ast[2][0]);
+ ret->type = BasicType::i32;
+ return ret;
+ }
Call* ret;
if (imports.find(name) != imports.end()) {
ret = allocator.alloc<CallImport>();