Skip to content

Commit 62f6a12

Browse files
tlivelykripken
authored andcommitted
wasm2asm i32 arithmetic support (#1120)
* Rotations, popcnt, ctz, etc
1 parent ffd9a72 commit 62f6a12

10 files changed

Lines changed: 612 additions & 35 deletions

File tree

src/asmjs/shared-constants.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,20 @@ cashew::IString GLOBAL("global"),
5858
ENV("env"),
5959
INSTRUMENT("instrument"),
6060
MATH_IMUL("Math_imul"),
61-
MATH_CLZ32("Math_clz32"),
62-
MATH_POPCNT32("Math_popcnt32"),
6361
MATH_ABS("Math_abs"),
6462
MATH_CEIL("Math_ceil"),
6563
MATH_FLOOR("Math_floor"),
6664
MATH_TRUNC("Math_trunc"),
6765
MATH_NEAREST("Math_NEAREST"),
6866
MATH_SQRT("Math_sqrt"),
69-
MATH_MIN("Math_max"),
70-
MATH_MAX("Math_min");
71-
67+
MATH_MIN("Math_min"),
68+
MATH_MAX("Math_max"),
69+
CTZ32("__wasm_ctz_i32"),
70+
CTZ64("__wasm_ctz_i64"),
71+
POPCNT32("__wasm_popcnt_i32"),
72+
POPCNT64("__wasm_popcnt_i64"),
73+
ROTL32("__wasm_rotl_i32"),
74+
ROTL64("__wasm_rotl_i64"),
75+
ROTR32("__wasm_rotr_i32"),
76+
ROTR64("__wasm_rotr_i64");
7277
}

src/asmjs/shared-constants.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,22 @@ extern cashew::IString GLOBAL,
6161
ENV,
6262
INSTRUMENT,
6363
MATH_IMUL,
64-
MATH_CLZ32,
65-
MATH_POPCNT32,
6664
MATH_ABS,
6765
MATH_CEIL,
6866
MATH_FLOOR,
6967
MATH_TRUNC,
7068
MATH_NEAREST,
7169
MATH_SQRT,
7270
MATH_MIN,
73-
MATH_MAX;
74-
71+
MATH_MAX,
72+
CTZ32,
73+
CTZ64,
74+
POPCNT32,
75+
POPCNT64,
76+
ROTL32,
77+
ROTL64,
78+
ROTR32,
79+
ROTR64;
7580
}
7681

7782
#endif // wasm_asmjs_shared_constants_h

src/emscripten-optimizer/parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ IString TOPLEVEL("toplevel"),
5050
UNARY_PREFIX("unary-prefix"),
5151
UNARY_POSTFIX("unary-postfix"),
5252
MATH_FROUND("Math_fround"),
53+
MATH_CLZ32("Math_clz32"),
5354
INT64("i64"),
5455
INT64_CONST("i64_const"),
5556
SIMD_FLOAT32X4("SIMD_Float32x4"),

src/emscripten-optimizer/parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extern IString TOPLEVEL,
6565
UNARY_PREFIX,
6666
UNARY_POSTFIX,
6767
MATH_FROUND,
68+
MATH_CLZ32,
6869
INT64,
6970
INT64_CONST,
7071
SIMD_FLOAT32X4,

src/wasm-builder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ class Builder {
336336
return block;
337337
}
338338

339+
template<typename ...Ts>
340+
Block* blockify(Expression* any, Expression* append, Ts... args) {
341+
return blockify(blockify(any, append), args...);
342+
}
343+
339344
// ensure a node is a block, if it isn't already, and optionally append to the block
340345
// this variant sets a name for the block, so it will not reuse a block already named
341346
Block* blockifyWithName(Expression* any, Name name, Expression* append = nullptr) {

0 commit comments

Comments
 (0)