forked from AssemblyScript/assemblyscript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asmjs-math-builtins.js
45 lines (37 loc) · 924 Bytes
/
asmjs-math-builtins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var binaryen = require("binaryen");
var mod = new binaryen.Module();
var funcType = mod.addFunctionType("F", binaryen.f64, [ binaryen.f64 ]);
mod.addFunction("floor", funcType, [],
mod.f64.floor(
mod.get_local(0, binaryen.f64)
)
);
mod.addExport("floor", "floor");
mod.addFunction("ceil", funcType, [],
mod.f64.ceil(
mod.get_local(0, binaryen.f64)
)
);
mod.addExport("ceil", "ceil");
mod.addFunction("sqrt", funcType, [],
mod.f64.sqrt(
mod.get_local(0, binaryen.f64)
)
);
mod.addExport("sqrt", "sqrt");
mod.addFunction("trunc", funcType, [],
mod.f64.trunc(
mod.get_local(0, binaryen.f64)
)
);
mod.addExport("trunc", "trunc");
mod.addFunction("nearest", funcType, [],
mod.f64.nearest(
mod.get_local(0, binaryen.f64)
)
);
mod.addExport("nearest", "nearest");
console.log(mod.emitText());
if (!mod.validate())
console.log("-> does not validate");
console.log(mod.emitAsmjs());