summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/asm2wasm.h9
-rw-r--r--src/shared-constants.h1
-rw-r--r--test/unit.asm.js8
-rw-r--r--test/unit.fromasm20
4 files changed, 36 insertions, 2 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 16ed0cf68..353f80413 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -197,6 +197,7 @@ private:
IString Math_fround;
IString Math_abs;
IString Math_floor;
+ IString Math_ceil;
IString Math_sqrt;
// function types. we fill in this information as we see
@@ -458,6 +459,10 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
assert(Math_floor.isNull());
Math_floor = name;
return;
+ } else if (imported[2] == CEIL) {
+ assert(Math_ceil.isNull());
+ Math_ceil = name;
+ return;
} else if (imported[2] == SQRT) {
assert(Math_sqrt.isNull());
Math_sqrt = name;
@@ -1126,12 +1131,12 @@ Function* Asm2WasmBuilder::processFunction(Ref ast) {
abort();
}
}
- if (name == Math_floor || name == Math_sqrt) {
+ if (name == Math_floor || name == Math_sqrt || name == Math_ceil) {
// overloaded on type: f32 or f64
Expression* value = process(ast[2][0]);
if (value->type == f32 || value->type == f64) {
auto ret = allocator.alloc<Unary>();
- ret->op = name == Math_floor ? Floor : Sqrt;
+ ret->op = name == Math_floor ? Floor : name == Math_ceil ? Ceil : Sqrt;
ret->value = value;
ret->type = value->type;
return ret;
diff --git a/src/shared-constants.h b/src/shared-constants.h
index 6662c50b2..053aecc83 100644
--- a/src/shared-constants.h
+++ b/src/shared-constants.h
@@ -46,6 +46,7 @@ cashew::IString GLOBAL("global"),
GLOBAL_MATH("global.Math"),
ABS("abs"),
FLOOR("floor"),
+ CEIL("ceil"),
SQRT("sqrt"),
I32_TEMP("asm2wasm_i32_temp"),
DEBUGGER("debugger"),
diff --git a/test/unit.asm.js b/test/unit.asm.js
index e539c6139..491f90835 100644
--- a/test/unit.asm.js
+++ b/test/unit.asm.js
@@ -6,6 +6,7 @@ function asm() {
var Double = 0.0;
var Math_fround = global.Math.fround;
var Math_abs = global.Math.abs;
+ var Math_ceil = global.Math.ceil;
function big_negative() {
var temp = 0.0;
@@ -135,6 +136,13 @@ function asm() {
h(i | 0);
}
}
+ function ceiling_32_64(u, B) {
+ u = Math_fround(u);
+ B = +B;
+ var temp = Math_fround(0);
+ temp = Math_fround(Math_ceil(B));
+ temp = Math_fround(u * Math_fround(Math_ceil(Math_fround(B))));
+ }
function z() {
}
diff --git a/test/unit.fromasm b/test/unit.fromasm
index 1262b11da..c23c1a0db 100644
--- a/test/unit.fromasm
+++ b/test/unit.fromasm
@@ -426,6 +426,26 @@
(br $for-in$1)
)
)
+ (func $ceiling_32_64 (param $u f32) (param $B f64)
+ (local $temp f32)
+ (set_local $temp
+ (f32.demote/f64
+ (f64.ceil
+ (get_local $B)
+ )
+ )
+ )
+ (set_local $temp
+ (f32.mul
+ (get_local $u)
+ (f32.ceil
+ (f32.demote/f64
+ (get_local $B)
+ )
+ )
+ )
+ )
+ )
(func $z
(nop)
)