summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-12-02 20:23:59 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-12-07 16:50:04 -1000
commitb0d3056aa9dfda88f86db9d580989372ab198f11 (patch)
tree48d9e36ad78bc7687a8950d185a1d9005fd6a437 /src
parent0a498b945e6fe51db9fd3e5b76997e3f40b735a7 (diff)
downloadbinaryen-b0d3056aa9dfda88f86db9d580989372ab198f11.tar.gz
binaryen-b0d3056aa9dfda88f86db9d580989372ab198f11.tar.bz2
binaryen-b0d3056aa9dfda88f86db9d580989372ab198f11.zip
lower min and max in asm2wasm in wasm f*.min/max
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm.h30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 853cb84df..1df74456d 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -107,7 +107,9 @@ Name I32_CTTZ("i32_cttz"),
STOREF("storef"),
STORED("stored"),
FTCALL("ftCall_"),
- MFTCALL("mftCall_");
+ MFTCALL("mftCall_"),
+ MAX_("max"),
+ MIN_("min");
// Utilities
@@ -280,6 +282,8 @@ private:
IString Math_floor;
IString Math_ceil;
IString Math_sqrt;
+ IString Math_max;
+ IString Math_min;
IString llvm_cttz_i32;
@@ -606,6 +610,14 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
assert(Math_sqrt.isNull());
Math_sqrt = name;
return;
+ } else if (imported[2] == MAX_) {
+ assert(Math_max.isNull());
+ Math_max = name;
+ return;
+ } else if (imported[2] == MIN_) {
+ assert(Math_min.isNull());
+ Math_min = name;
+ return;
}
}
std::string fullName = module[1][1]->getCString();
@@ -1596,6 +1608,22 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
}
return ret;
}
+ if (name == Math_max || name == Math_min) {
+ // overloaded on type: f32 or f64
+ assert(ast[2]->size() == 2);
+ auto ret = allocator.alloc<Binary>();
+ ret->left = process(ast[2][0]);
+ ret->right = process(ast[2][1]);
+ if (ret->left->type == f32) {
+ ret->op = name == Math_max ? MaxFloat32 : MinFloat32;
+ } else if (ret->left->type == f64) {
+ ret->op = name == Math_max ? MaxFloat64 : MinFloat64;
+ } else {
+ abort();
+ }
+ ret->type = ret->left->type;
+ return ret;
+ }
bool tableCall = false;
if (wasmOnly) {
auto num = ast[2]->size();