Skip to content

Commit f10bc3e

Browse files
authored
wasm2js: 'handle' saturating float to int conversions - we don't handle any of them precisely anyhow (#2087)
1 parent ae7c24e commit f10bc3e

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/wasm2js.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,19 +1176,22 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m,
11761176
switch (curr->type) {
11771177
case i32: {
11781178
switch (curr->op) {
1179-
case ClzInt32:
1179+
case ClzInt32: {
11801180
return ValueBuilder::makeCall(
11811181
MATH_CLZ32, visit(curr->value, EXPRESSION_RESULT));
1182+
}
11821183
case CtzInt32:
1183-
case PopcntInt32:
1184+
case PopcntInt32: {
11841185
std::cerr << "i32 unary should have been removed: " << curr
11851186
<< std::endl;
11861187
WASM_UNREACHABLE();
1187-
case EqZInt32:
1188+
}
1189+
case EqZInt32: {
11881190
// XXX !x does change the type to bool, which is correct, but may
11891191
// be slower?
11901192
return ValueBuilder::makeUnary(
11911193
L_NOT, visit(curr->value, EXPRESSION_RESULT));
1194+
}
11921195
case ReinterpretFloat32: {
11931196
ABI::wasm2js::ensureScratchMemoryHelpers(
11941197
module, ABI::wasm2js::SCRATCH_STORE_F32);
@@ -1205,22 +1208,26 @@ Ref Wasm2JSBuilder::processFunctionBody(Module* m,
12051208
// generate (~~expr), what Emscripten does
12061209
case TruncSFloat32ToInt32:
12071210
case TruncSFloat64ToInt32:
1211+
case TruncSatSFloat32ToInt32:
1212+
case TruncSatSFloat64ToInt32: {
12081213
return ValueBuilder::makeUnary(
12091214
B_NOT,
12101215
ValueBuilder::makeUnary(B_NOT,
12111216
visit(curr->value, EXPRESSION_RESULT)));
1212-
1217+
}
12131218
// generate (~~expr >>> 0), what Emscripten does
12141219
case TruncUFloat32ToInt32:
12151220
case TruncUFloat64ToInt32:
1221+
case TruncSatUFloat32ToInt32:
1222+
case TruncSatUFloat64ToInt32: {
12161223
return ValueBuilder::makeBinary(
12171224
ValueBuilder::makeUnary(
12181225
B_NOT,
12191226
ValueBuilder::makeUnary(
12201227
B_NOT, visit(curr->value, EXPRESSION_RESULT))),
12211228
TRSHIFT,
12221229
ValueBuilder::makeNum(0));
1223-
1230+
}
12241231
default: {
12251232
std::cerr << "Unhandled unary i32 operator: " << curr
12261233
<< std::endl;

0 commit comments

Comments
 (0)