diff --git a/src/ir/trapping.h b/src/ir/trapping.h deleted file mode 100644 index 6272bbf0f3c..00000000000 --- a/src/ir/trapping.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2017 WebAssembly Community Group participants - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef wasm_ir_trapping_h -#define wasm_ir_trapping_h - -#include - -#include "pass.h" - -namespace wasm { - -enum class TrapMode { Allow, Clamp, JS }; - -inline void addTrapModePass(PassRunner& runner, TrapMode trapMode) { - if (trapMode == TrapMode::Clamp) { - runner.add("trap-mode-clamp"); - } else if (trapMode == TrapMode::JS) { - runner.add("trap-mode-js"); - } -} - -class TrappingFunctionContainer { -public: - TrappingFunctionContainer(TrapMode mode, Module& wasm, bool immediate = false) - : mode(mode), wasm(wasm), immediate(immediate) {} - - bool hasFunction(Name name) { - return functions.find(name) != functions.end(); - } - bool hasImport(Name name) { return imports.find(name) != imports.end(); } - - void addFunction(Function* function) { - functions[function->name] = function; - if (immediate) { - wasm.addFunction(function); - } - } - void addImport(Function* import) { - imports[import->name] = import; - if (immediate) { - wasm.addFunction(import); - } - } - - void addToModule() { - if (!immediate) { - for (auto& [_, func] : functions) { - wasm.addFunction(func); - } - for (auto& [_, func] : imports) { - wasm.addFunction(func); - } - } - functions.clear(); - imports.clear(); - } - - TrapMode getMode() { return mode; } - - Module& getModule() { return wasm; } - - std::map& getFunctions() { return functions; } - -private: - std::map functions; - std::map imports; - - TrapMode mode; - Module& wasm; - bool immediate; -}; - -Expression* makeTrappingBinary(Binary* curr, - TrappingFunctionContainer& trappingFunctions); -Expression* makeTrappingUnary(Unary* curr, - TrappingFunctionContainer& trappingFunctions); - -inline TrapMode trapModeFromString(std::string const& str) { - if (str == "allow") { - return TrapMode::Allow; - } else if (str == "clamp") { - return TrapMode::Clamp; - } else if (str == "js") { - return TrapMode::JS; - } else { - throw std::invalid_argument( - "Unsupported trap mode \"" + str + - "\". " - "Valid modes are \"allow\", \"js\", and \"clamp\""); - } -} - -} // namespace wasm - -#endif // wasm_ir_trapping_h diff --git a/src/passes/CMakeLists.txt b/src/passes/CMakeLists.txt index 41ccdef82bd..5924e3b7e76 100644 --- a/src/passes/CMakeLists.txt +++ b/src/passes/CMakeLists.txt @@ -124,7 +124,6 @@ set(passes_SOURCES ReorderLocals.cpp ReorderTypes.cpp ReReloop.cpp - TrapMode.cpp TypeGeneralizing.cpp TypeRefining.cpp TypeMerging.cpp diff --git a/src/passes/TrapMode.cpp b/src/passes/TrapMode.cpp deleted file mode 100644 index 18a016436eb..00000000000 --- a/src/passes/TrapMode.cpp +++ /dev/null @@ -1,347 +0,0 @@ -/* - * Copyright 2017 WebAssembly Community Group participants - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// -// Pass that supports potentially-trapping wasm operations. -// For example, integer division traps when dividing by zero, so this pass -// generates a check and replaces the result with zero in that case. -// - -#include "asmjs/shared-constants.h" -#include "ir/trapping.h" -#include "pass.h" -#include "support/mixed_arena.h" -#include "support/name.h" -#include "wasm-builder.h" -#include "wasm-type.h" -#include "wasm.h" - -namespace wasm { - -static const Name I64S_REM("i64s-rem"); -static const Name I64U_REM("i64u-rem"); -static const Name I64S_DIV("i64s-div"); -static const Name I64U_DIV("i64u-div"); -static const Name F64_TO_INT64("f64-to-int64"); -static const Name F64_TO_UINT64("f64-to-uint64"); -static const Name F32_TO_INT64("f32-to-int64"); -static const Name F32_TO_UINT64("f32-to-uint64"); - -static Expression* ensureDouble(Expression* expr, MixedArena& allocator) { - if (expr->type == Type::f32) { - auto conv = allocator.alloc(); - conv->op = PromoteFloat32; - conv->value = expr; - conv->type = Type::f64; - return conv; - } - assert(expr->type == Type::f64); - return expr; -} - -Name getBinaryFuncName(Binary* curr) { - switch (curr->op) { - case RemSInt32: - return I32S_REM; - case RemUInt32: - return I32U_REM; - case DivSInt32: - return I32S_DIV; - case DivUInt32: - return I32U_DIV; - case RemSInt64: - return I64S_REM; - case RemUInt64: - return I64U_REM; - case DivSInt64: - return I64S_DIV; - case DivUInt64: - return I64U_DIV; - default: - return Name(); - } -} - -Name getUnaryFuncName(Unary* curr) { - switch (curr->op) { - case TruncSFloat32ToInt32: - return F32_TO_INT; - case TruncUFloat32ToInt32: - return F32_TO_UINT; - case TruncSFloat32ToInt64: - return F32_TO_INT64; - case TruncUFloat32ToInt64: - return F32_TO_UINT64; - case TruncSFloat64ToInt32: - return F64_TO_INT; - case TruncUFloat64ToInt32: - return F64_TO_UINT; - case TruncSFloat64ToInt64: - return F64_TO_INT64; - case TruncUFloat64ToInt64: - return F64_TO_UINT64; - default: - return Name(); - } -} - -bool isTruncOpSigned(UnaryOp op) { - switch (op) { - case TruncUFloat32ToInt32: - case TruncUFloat32ToInt64: - case TruncUFloat64ToInt32: - case TruncUFloat64ToInt64: - return false; - default: - return true; - } -} - -Function* generateBinaryFunc(Module& wasm, Binary* curr) { - BinaryOp op = curr->op; - Type type = curr->type; - bool isI64 = type == Type::i64; - Builder builder(wasm); - Expression* result = builder.makeBinary( - op, builder.makeLocalGet(0, type), builder.makeLocalGet(1, type)); - BinaryOp divSIntOp = isI64 ? DivSInt64 : DivSInt32; - UnaryOp eqZOp = isI64 ? EqZInt64 : EqZInt32; - Literal minLit = isI64 ? Literal(std::numeric_limits::min()) - : Literal(std::numeric_limits::min()); - Literal zeroLit = isI64 ? Literal(int64_t(0)) : Literal(int32_t(0)); - if (op == divSIntOp) { - // guard against signed division overflow - BinaryOp eqOp = isI64 ? EqInt64 : EqInt32; - Literal negLit = isI64 ? Literal(int64_t(-1)) : Literal(int32_t(-1)); - result = builder.makeIf( - builder.makeBinary( - AndInt32, - builder.makeBinary( - eqOp, builder.makeLocalGet(0, type), builder.makeConst(minLit)), - builder.makeBinary( - eqOp, builder.makeLocalGet(1, type), builder.makeConst(negLit))), - builder.makeConst(zeroLit), - result); - } - auto funcSig = Signature({type, type}, type); - auto func = Builder::makeFunction( - getBinaryFuncName(curr), Type(funcSig, NonNullable, Exact), {}); - func->body = - builder.makeIf(builder.makeUnary(eqZOp, builder.makeLocalGet(1, type)), - builder.makeConst(zeroLit), - result); - // TODO: use unique_ptr properly and do not release ownership. - return func.release(); -} - -template -void makeClampLimitLiterals(Literal& iMin, Literal& fMin, Literal& fMax) { - IntType minVal = std::numeric_limits::min(); - IntType maxVal = std::numeric_limits::max(); - iMin = Literal(minVal); - fMin = Literal(FloatType(minVal) - 1); - fMax = Literal(FloatType(maxVal) + 1); -} - -Function* generateUnaryFunc(Module& wasm, Unary* curr) { - Type type = curr->value->type; - Type retType = curr->type; - UnaryOp truncOp = curr->op; - bool isF64 = type == Type::f64; - - Builder builder(wasm); - - BinaryOp leOp = isF64 ? LeFloat64 : LeFloat32; - BinaryOp geOp = isF64 ? GeFloat64 : GeFloat32; - BinaryOp neOp = isF64 ? NeFloat64 : NeFloat32; - - Literal iMin, fMin, fMax; - switch (truncOp) { - case TruncSFloat32ToInt32: - makeClampLimitLiterals(iMin, fMin, fMax); - break; - case TruncUFloat32ToInt32: - makeClampLimitLiterals(iMin, fMin, fMax); - break; - case TruncSFloat32ToInt64: - makeClampLimitLiterals(iMin, fMin, fMax); - break; - case TruncUFloat32ToInt64: - makeClampLimitLiterals(iMin, fMin, fMax); - break; - case TruncSFloat64ToInt32: - makeClampLimitLiterals(iMin, fMin, fMax); - break; - case TruncUFloat64ToInt32: - makeClampLimitLiterals(iMin, fMin, fMax); - break; - case TruncSFloat64ToInt64: - makeClampLimitLiterals(iMin, fMin, fMax); - break; - case TruncUFloat64ToInt64: - makeClampLimitLiterals(iMin, fMin, fMax); - break; - default: - WASM_UNREACHABLE("unexpected op"); - } - - auto func = - Builder::makeFunction(getUnaryFuncName(curr), - Type(Signature(type, retType), NonNullable, Exact), - {}); - func->body = builder.makeUnary(truncOp, builder.makeLocalGet(0, type)); - // too small XXX this is different than asm.js, which does frem. here we - // clamp, which is much simpler/faster, and similar to native builds - func->body = builder.makeIf(builder.makeBinary(leOp, - builder.makeLocalGet(0, type), - builder.makeConst(fMin)), - builder.makeConst(iMin), - func->body); - // too big XXX see above - func->body = builder.makeIf( - builder.makeBinary( - geOp, builder.makeLocalGet(0, type), builder.makeConst(fMax)), - // NB: min here as well. anything out of range => to the min - builder.makeConst(iMin), - func->body); - // nan - func->body = builder.makeIf( - builder.makeBinary( - neOp, builder.makeLocalGet(0, type), builder.makeLocalGet(0, type)), - // NB: min here as well. anything invalid => to the min - builder.makeConst(iMin), - func->body); - // TODO: use unique_ptr properly and do not release ownership. - return func.release(); -} - -void ensureBinaryFunc(Binary* curr, - Module& wasm, - TrappingFunctionContainer& trappingFunctions) { - Name name = getBinaryFuncName(curr); - if (trappingFunctions.hasFunction(name)) { - return; - } - trappingFunctions.addFunction(generateBinaryFunc(wasm, curr)); -} - -void ensureUnaryFunc(Unary* curr, - Module& wasm, - TrappingFunctionContainer& trappingFunctions) { - Name name = getUnaryFuncName(curr); - if (trappingFunctions.hasFunction(name)) { - return; - } - trappingFunctions.addFunction(generateUnaryFunc(wasm, curr)); -} - -void ensureF64ToI64JSImport(TrappingFunctionContainer& trappingFunctions) { - if (trappingFunctions.hasImport(F64_TO_INT)) { - return; - } - - // f64-to-int = asm2wasm.f64-to-int; - auto import = new Function; - import->name = F64_TO_INT; - import->module = ASM2WASM; - import->base = F64_TO_INT; - import->type = Type(Signature(Type::f64, Type::i32), NonNullable, Inexact); - trappingFunctions.addImport(import); -} - -Expression* makeTrappingBinary(Binary* curr, - TrappingFunctionContainer& trappingFunctions) { - Name name = getBinaryFuncName(curr); - if (!name.is() || trappingFunctions.getMode() == TrapMode::Allow) { - return curr; - } - - // the wasm operation might trap if done over 0, so generate a safe call - Type type = curr->type; - Module& wasm = trappingFunctions.getModule(); - Builder builder(wasm); - ensureBinaryFunc(curr, wasm, trappingFunctions); - return builder.makeCall(name, {curr->left, curr->right}, type); -} - -Expression* makeTrappingUnary(Unary* curr, - TrappingFunctionContainer& trappingFunctions) { - Name name = getUnaryFuncName(curr); - TrapMode mode = trappingFunctions.getMode(); - if (!name.is() || mode == TrapMode::Allow) { - return curr; - } - - Module& wasm = trappingFunctions.getModule(); - Builder builder(wasm); - // WebAssembly traps on float-to-int overflows, but asm.js wouldn't, so we - // must do something We can handle this in one of two ways: clamping, which is - // fast, or JS, which is precisely like JS but in order to do that we do a - // slow ffi If i64, there is no "JS" way to handle this, as no i64s in JS, so - // always clamp if we don't allow traps asm.js doesn't have unsigned - // f64-to-int, so just use the signed one. - if (curr->type != Type::i64 && mode == TrapMode::JS) { - // WebAssembly traps on float-to-int overflows, but asm.js wouldn't, so we - // must emulate that - ensureF64ToI64JSImport(trappingFunctions); - Expression* f64Value = ensureDouble(curr->value, wasm.allocator); - return builder.makeCall(F64_TO_INT, {f64Value}, Type::i32); - } - - ensureUnaryFunc(curr, wasm, trappingFunctions); - return builder.makeCall(name, {curr->value}, curr->type); -} - -struct TrapModePass : public WalkerPass> { -public: - // Needs to be non-parallel so that visitModule gets called after visiting - // each node in the module, so we can add the functions that we created. - bool isFunctionParallel() override { return false; } - - TrapModePass(TrapMode mode) : mode(mode) { assert(mode != TrapMode::Allow); } - - std::unique_ptr create() override { - return std::make_unique(mode); - } - - void visitUnary(Unary* curr) { - replaceCurrent(makeTrappingUnary(curr, *trappingFunctions)); - } - - void visitBinary(Binary* curr) { - replaceCurrent(makeTrappingBinary(curr, *trappingFunctions)); - } - - void visitModule(Module* curr) { trappingFunctions->addToModule(); } - - void doWalkModule(Module* module) { - trappingFunctions = - std::make_unique(mode, *module); - Super::doWalkModule(module); - } - -private: - TrapMode mode; - // Need to defer adding generated functions because adding functions while - // iterating over existing functions causes problems. - std::unique_ptr trappingFunctions; -}; - -Pass* createTrapModeClamp() { return new TrapModePass(TrapMode::Clamp); } - -Pass* createTrapModeJS() { return new TrapModePass(TrapMode::JS); } - -} // namespace wasm diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 23731df0706..d93bb0876cb 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -575,12 +575,6 @@ void PassRegistry::registerPasses() { registerPass("translate-to-exnref", "translate old Phase 3 EH instructions to new ones with exnref", createTranslateToExnrefPass); - registerPass("trap-mode-clamp", - "replace trapping operations with clamping semantics", - createTrapModeClamp); - registerPass("trap-mode-js", - "replace trapping operations with js semantics", - createTrapModeJS); registerPass("tuple-optimization", "optimize trivial tuples away", createTupleOptimizationPass); diff --git a/src/passes/passes.h b/src/passes/passes.h index 86e506b44b8..b6242cf5259 100644 --- a/src/passes/passes.h +++ b/src/passes/passes.h @@ -191,8 +191,6 @@ Pass* createSSAifyPass(); Pass* createSSAifyNoMergePass(); Pass* createTable64LoweringPass(); Pass* createTranslateToExnrefPass(); -Pass* createTrapModeClamp(); -Pass* createTrapModeJS(); Pass* createTupleOptimizationPass(); Pass* createTypeGeneralizingPass(); Pass* createTypeRefiningPass(); diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp index 59d3a0eae40..6b58a82d1c9 100644 --- a/src/tools/wasm-emscripten-finalize.cpp +++ b/src/tools/wasm-emscripten-finalize.cpp @@ -22,7 +22,6 @@ #include #include "abi/js.h" -#include "ir/trapping.h" #include "support/colors.h" #include "support/debug.h" #include "support/file.h" diff --git a/test/lit/help/wasm-metadce.test b/test/lit/help/wasm-metadce.test index 34f5f599dcf..d6b80d5bf89 100644 --- a/test/lit/help/wasm-metadce.test +++ b/test/lit/help/wasm-metadce.test @@ -559,12 +559,6 @@ ;; CHECK-NEXT: --translate-to-new-eh deprecated; same as ;; CHECK-NEXT: translate-to-exnref ;; CHECK-EMPTY: -;; CHECK-NEXT: --trap-mode-clamp replace trapping operations with -;; CHECK-NEXT: clamping semantics -;; CHECK-EMPTY: -;; CHECK-NEXT: --trap-mode-js replace trapping operations with -;; CHECK-NEXT: js semantics -;; CHECK-EMPTY: ;; CHECK-NEXT: --tuple-optimization optimize trivial tuples away ;; CHECK-EMPTY: ;; CHECK-NEXT: --type-finalizing mark all leaf types as final diff --git a/test/lit/help/wasm-opt.test b/test/lit/help/wasm-opt.test index 03d35ac66f2..ff37a52d159 100644 --- a/test/lit/help/wasm-opt.test +++ b/test/lit/help/wasm-opt.test @@ -595,12 +595,6 @@ ;; CHECK-NEXT: --translate-to-new-eh deprecated; same as ;; CHECK-NEXT: translate-to-exnref ;; CHECK-EMPTY: -;; CHECK-NEXT: --trap-mode-clamp replace trapping operations with -;; CHECK-NEXT: clamping semantics -;; CHECK-EMPTY: -;; CHECK-NEXT: --trap-mode-js replace trapping operations with -;; CHECK-NEXT: js semantics -;; CHECK-EMPTY: ;; CHECK-NEXT: --tuple-optimization optimize trivial tuples away ;; CHECK-EMPTY: ;; CHECK-NEXT: --type-finalizing mark all leaf types as final diff --git a/test/lit/help/wasm2js.test b/test/lit/help/wasm2js.test index 8856b1143e9..33c963860e1 100644 --- a/test/lit/help/wasm2js.test +++ b/test/lit/help/wasm2js.test @@ -523,12 +523,6 @@ ;; CHECK-NEXT: --translate-to-new-eh deprecated; same as ;; CHECK-NEXT: translate-to-exnref ;; CHECK-EMPTY: -;; CHECK-NEXT: --trap-mode-clamp replace trapping operations with -;; CHECK-NEXT: clamping semantics -;; CHECK-EMPTY: -;; CHECK-NEXT: --trap-mode-js replace trapping operations with -;; CHECK-NEXT: js semantics -;; CHECK-EMPTY: ;; CHECK-NEXT: --tuple-optimization optimize trivial tuples away ;; CHECK-EMPTY: ;; CHECK-NEXT: --type-finalizing mark all leaf types as final diff --git a/test/passes/trap-mode-clamp.txt b/test/passes/trap-mode-clamp.txt deleted file mode 100644 index 27512712e2a..00000000000 --- a/test/passes/trap-mode-clamp.txt +++ /dev/null @@ -1,573 +0,0 @@ -(module - (type $0 (func (param i32 i32) (result i32))) - (type $1 (func (param i64 i64) (result i64))) - (type $2 (func (param i32 i64))) - (type $3 (func (param f32) (result i32))) - (type $4 (func (param f32) (result i64))) - (type $5 (func (param f64) (result i32))) - (type $6 (func (param f64) (result i64))) - (type $7 (func (param f32))) - (type $8 (func (param f64))) - (func $test_div (param $0 i32) (param $1 i64) - (drop - (call $i32s-div - (local.get $0) - (local.get $0) - ) - ) - (drop - (call $i32u-div - (local.get $0) - (local.get $0) - ) - ) - (drop - (call $i64s-div - (local.get $1) - (local.get $1) - ) - ) - (drop - (call $i64u-div - (local.get $1) - (local.get $1) - ) - ) - ) - (func $test_rem (param $0 i32) (param $1 i64) - (drop - (call $i32s-rem - (local.get $0) - (local.get $0) - ) - ) - (drop - (call $i32u-rem - (local.get $0) - (local.get $0) - ) - ) - (drop - (call $i64s-rem - (local.get $1) - (local.get $1) - ) - ) - (drop - (call $i64u-rem - (local.get $1) - (local.get $1) - ) - ) - ) - (func $test_f32_to_int (param $0 f32) - (drop - (call $f32-to-int - (local.get $0) - ) - ) - (drop - (call $f32-to-uint - (local.get $0) - ) - ) - (drop - (call $f32-to-int64 - (local.get $0) - ) - ) - (drop - (call $f32-to-uint64 - (local.get $0) - ) - ) - ) - (func $test_f64_to_int (param $0 f64) - (drop - (call $f64-to-int - (local.get $0) - ) - ) - (drop - (call $f64-to-uint - (local.get $0) - ) - ) - (drop - (call $f64-to-int64 - (local.get $0) - ) - ) - (drop - (call $f64-to-uint64 - (local.get $0) - ) - ) - ) - (func $f32-to-int (param $0 f32) (result i32) - (if (result i32) - (f32.ne - (local.get $0) - (local.get $0) - ) - (then - (i32.const -2147483648) - ) - (else - (if (result i32) - (f32.ge - (local.get $0) - (f32.const 2147483648) - ) - (then - (i32.const -2147483648) - ) - (else - (if (result i32) - (f32.le - (local.get $0) - (f32.const -2147483648) - ) - (then - (i32.const -2147483648) - ) - (else - (i32.trunc_f32_s - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $f32-to-int64 (param $0 f32) (result i64) - (if (result i64) - (f32.ne - (local.get $0) - (local.get $0) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (if (result i64) - (f32.ge - (local.get $0) - (f32.const 9223372036854775808) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (if (result i64) - (f32.le - (local.get $0) - (f32.const -9223372036854775808) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (i64.trunc_f32_s - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $f32-to-uint (param $0 f32) (result i32) - (if (result i32) - (f32.ne - (local.get $0) - (local.get $0) - ) - (then - (i32.const 0) - ) - (else - (if (result i32) - (f32.ge - (local.get $0) - (f32.const 4294967296) - ) - (then - (i32.const 0) - ) - (else - (if (result i32) - (f32.le - (local.get $0) - (f32.const -1) - ) - (then - (i32.const 0) - ) - (else - (i32.trunc_f32_u - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $f32-to-uint64 (param $0 f32) (result i64) - (if (result i64) - (f32.ne - (local.get $0) - (local.get $0) - ) - (then - (i64.const 0) - ) - (else - (if (result i64) - (f32.ge - (local.get $0) - (f32.const 18446744073709551615) - ) - (then - (i64.const 0) - ) - (else - (if (result i64) - (f32.le - (local.get $0) - (f32.const -1) - ) - (then - (i64.const 0) - ) - (else - (i64.trunc_f32_u - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $f64-to-int (param $0 f64) (result i32) - (if (result i32) - (f64.ne - (local.get $0) - (local.get $0) - ) - (then - (i32.const -2147483648) - ) - (else - (if (result i32) - (f64.ge - (local.get $0) - (f64.const 2147483648) - ) - (then - (i32.const -2147483648) - ) - (else - (if (result i32) - (f64.le - (local.get $0) - (f64.const -2147483649) - ) - (then - (i32.const -2147483648) - ) - (else - (i32.trunc_f64_s - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $f64-to-int64 (param $0 f64) (result i64) - (if (result i64) - (f64.ne - (local.get $0) - (local.get $0) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (if (result i64) - (f64.ge - (local.get $0) - (f64.const 9223372036854775808) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (if (result i64) - (f64.le - (local.get $0) - (f64.const -9223372036854775808) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (i64.trunc_f64_s - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $f64-to-uint (param $0 f64) (result i32) - (if (result i32) - (f64.ne - (local.get $0) - (local.get $0) - ) - (then - (i32.const 0) - ) - (else - (if (result i32) - (f64.ge - (local.get $0) - (f64.const 4294967296) - ) - (then - (i32.const 0) - ) - (else - (if (result i32) - (f64.le - (local.get $0) - (f64.const -1) - ) - (then - (i32.const 0) - ) - (else - (i32.trunc_f64_u - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $f64-to-uint64 (param $0 f64) (result i64) - (if (result i64) - (f64.ne - (local.get $0) - (local.get $0) - ) - (then - (i64.const 0) - ) - (else - (if (result i64) - (f64.ge - (local.get $0) - (f64.const 18446744073709551615) - ) - (then - (i64.const 0) - ) - (else - (if (result i64) - (f64.le - (local.get $0) - (f64.const -1) - ) - (then - (i64.const 0) - ) - (else - (i64.trunc_f64_u - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $i32s-div (param $0 i32) (param $1 i32) (result i32) - (if (result i32) - (i32.eqz - (local.get $1) - ) - (then - (i32.const 0) - ) - (else - (if (result i32) - (i32.and - (i32.eq - (local.get $0) - (i32.const -2147483648) - ) - (i32.eq - (local.get $1) - (i32.const -1) - ) - ) - (then - (i32.const 0) - ) - (else - (i32.div_s - (local.get $0) - (local.get $1) - ) - ) - ) - ) - ) - ) - (func $i32s-rem (param $0 i32) (param $1 i32) (result i32) - (if (result i32) - (i32.eqz - (local.get $1) - ) - (then - (i32.const 0) - ) - (else - (i32.rem_s - (local.get $0) - (local.get $1) - ) - ) - ) - ) - (func $i32u-div (param $0 i32) (param $1 i32) (result i32) - (if (result i32) - (i32.eqz - (local.get $1) - ) - (then - (i32.const 0) - ) - (else - (i32.div_u - (local.get $0) - (local.get $1) - ) - ) - ) - ) - (func $i32u-rem (param $0 i32) (param $1 i32) (result i32) - (if (result i32) - (i32.eqz - (local.get $1) - ) - (then - (i32.const 0) - ) - (else - (i32.rem_u - (local.get $0) - (local.get $1) - ) - ) - ) - ) - (func $i64s-div (param $0 i64) (param $1 i64) (result i64) - (if (result i64) - (i64.eqz - (local.get $1) - ) - (then - (i64.const 0) - ) - (else - (if (result i64) - (i32.and - (i64.eq - (local.get $0) - (i64.const -9223372036854775808) - ) - (i64.eq - (local.get $1) - (i64.const -1) - ) - ) - (then - (i64.const 0) - ) - (else - (i64.div_s - (local.get $0) - (local.get $1) - ) - ) - ) - ) - ) - ) - (func $i64s-rem (param $0 i64) (param $1 i64) (result i64) - (if (result i64) - (i64.eqz - (local.get $1) - ) - (then - (i64.const 0) - ) - (else - (i64.rem_s - (local.get $0) - (local.get $1) - ) - ) - ) - ) - (func $i64u-div (param $0 i64) (param $1 i64) (result i64) - (if (result i64) - (i64.eqz - (local.get $1) - ) - (then - (i64.const 0) - ) - (else - (i64.div_u - (local.get $0) - (local.get $1) - ) - ) - ) - ) - (func $i64u-rem (param $0 i64) (param $1 i64) (result i64) - (if (result i64) - (i64.eqz - (local.get $1) - ) - (then - (i64.const 0) - ) - (else - (i64.rem_u - (local.get $0) - (local.get $1) - ) - ) - ) - ) -) diff --git a/test/passes/trap-mode-clamp.wast b/test/passes/trap-mode-clamp.wast deleted file mode 100644 index b62165ef54b..00000000000 --- a/test/passes/trap-mode-clamp.wast +++ /dev/null @@ -1,26 +0,0 @@ -(module - (func $test_div (param $0 i32) (param $1 i64) - (drop (i32.div_s (local.get $0) (local.get $0))) - (drop (i32.div_u (local.get $0) (local.get $0))) - (drop (i64.div_s (local.get $1) (local.get $1))) - (drop (i64.div_u (local.get $1) (local.get $1))) - ) - (func $test_rem (param $0 i32) (param $1 i64) - (drop (i32.rem_s (local.get $0) (local.get $0))) - (drop (i32.rem_u (local.get $0) (local.get $0))) - (drop (i64.rem_s (local.get $1) (local.get $1))) - (drop (i64.rem_u (local.get $1) (local.get $1))) - ) - (func $test_f32_to_int (param $0 f32) - (drop (i32.trunc_f32_s (local.get $0))) - (drop (i32.trunc_f32_u (local.get $0))) - (drop (i64.trunc_f32_s (local.get $0))) - (drop (i64.trunc_f32_u (local.get $0))) - ) - (func $test_f64_to_int (param $0 f64) - (drop (i32.trunc_f64_s (local.get $0))) - (drop (i32.trunc_f64_u (local.get $0))) - (drop (i64.trunc_f64_s (local.get $0))) - (drop (i64.trunc_f64_u (local.get $0))) - ) -) diff --git a/test/passes/trap-mode-js.txt b/test/passes/trap-mode-js.txt deleted file mode 100644 index b43d7e9503c..00000000000 --- a/test/passes/trap-mode-js.txt +++ /dev/null @@ -1,425 +0,0 @@ -(module - (type $0 (func (param i32 i32) (result i32))) - (type $1 (func (param i64 i64) (result i64))) - (type $2 (func (param i32 i64))) - (type $3 (func (param f32) (result i64))) - (type $4 (func (param f64) (result i64))) - (type $5 (func (param f32))) - (type $6 (func (param f64))) - (type $7 (func (param f64) (result i32))) - (import "asm2wasm" "f64-to-int" (func $f64-to-int (param f64) (result i32))) - (func $test_div (param $0 i32) (param $1 i64) - (drop - (call $i32s-div - (local.get $0) - (local.get $0) - ) - ) - (drop - (call $i32u-div - (local.get $0) - (local.get $0) - ) - ) - (drop - (call $i64s-div - (local.get $1) - (local.get $1) - ) - ) - (drop - (call $i64u-div - (local.get $1) - (local.get $1) - ) - ) - ) - (func $test_rem (param $0 i32) (param $1 i64) - (drop - (call $i32s-rem - (local.get $0) - (local.get $0) - ) - ) - (drop - (call $i32u-rem - (local.get $0) - (local.get $0) - ) - ) - (drop - (call $i64s-rem - (local.get $1) - (local.get $1) - ) - ) - (drop - (call $i64u-rem - (local.get $1) - (local.get $1) - ) - ) - ) - (func $test_f32_to_int (param $0 f32) - (drop - (call $f64-to-int - (f64.promote_f32 - (local.get $0) - ) - ) - ) - (drop - (call $f64-to-int - (f64.promote_f32 - (local.get $0) - ) - ) - ) - (drop - (call $f32-to-int64 - (local.get $0) - ) - ) - (drop - (call $f32-to-uint64 - (local.get $0) - ) - ) - ) - (func $test_f64_to_int (param $0 f64) - (drop - (call $f64-to-int - (local.get $0) - ) - ) - (drop - (call $f64-to-int - (local.get $0) - ) - ) - (drop - (call $f64-to-int64 - (local.get $0) - ) - ) - (drop - (call $f64-to-uint64 - (local.get $0) - ) - ) - ) - (func $f32-to-int64 (param $0 f32) (result i64) - (if (result i64) - (f32.ne - (local.get $0) - (local.get $0) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (if (result i64) - (f32.ge - (local.get $0) - (f32.const 9223372036854775808) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (if (result i64) - (f32.le - (local.get $0) - (f32.const -9223372036854775808) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (i64.trunc_f32_s - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $f32-to-uint64 (param $0 f32) (result i64) - (if (result i64) - (f32.ne - (local.get $0) - (local.get $0) - ) - (then - (i64.const 0) - ) - (else - (if (result i64) - (f32.ge - (local.get $0) - (f32.const 18446744073709551615) - ) - (then - (i64.const 0) - ) - (else - (if (result i64) - (f32.le - (local.get $0) - (f32.const -1) - ) - (then - (i64.const 0) - ) - (else - (i64.trunc_f32_u - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $f64-to-int64 (param $0 f64) (result i64) - (if (result i64) - (f64.ne - (local.get $0) - (local.get $0) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (if (result i64) - (f64.ge - (local.get $0) - (f64.const 9223372036854775808) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (if (result i64) - (f64.le - (local.get $0) - (f64.const -9223372036854775808) - ) - (then - (i64.const -9223372036854775808) - ) - (else - (i64.trunc_f64_s - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $f64-to-uint64 (param $0 f64) (result i64) - (if (result i64) - (f64.ne - (local.get $0) - (local.get $0) - ) - (then - (i64.const 0) - ) - (else - (if (result i64) - (f64.ge - (local.get $0) - (f64.const 18446744073709551615) - ) - (then - (i64.const 0) - ) - (else - (if (result i64) - (f64.le - (local.get $0) - (f64.const -1) - ) - (then - (i64.const 0) - ) - (else - (i64.trunc_f64_u - (local.get $0) - ) - ) - ) - ) - ) - ) - ) - ) - (func $i32s-div (param $0 i32) (param $1 i32) (result i32) - (if (result i32) - (i32.eqz - (local.get $1) - ) - (then - (i32.const 0) - ) - (else - (if (result i32) - (i32.and - (i32.eq - (local.get $0) - (i32.const -2147483648) - ) - (i32.eq - (local.get $1) - (i32.const -1) - ) - ) - (then - (i32.const 0) - ) - (else - (i32.div_s - (local.get $0) - (local.get $1) - ) - ) - ) - ) - ) - ) - (func $i32s-rem (param $0 i32) (param $1 i32) (result i32) - (if (result i32) - (i32.eqz - (local.get $1) - ) - (then - (i32.const 0) - ) - (else - (i32.rem_s - (local.get $0) - (local.get $1) - ) - ) - ) - ) - (func $i32u-div (param $0 i32) (param $1 i32) (result i32) - (if (result i32) - (i32.eqz - (local.get $1) - ) - (then - (i32.const 0) - ) - (else - (i32.div_u - (local.get $0) - (local.get $1) - ) - ) - ) - ) - (func $i32u-rem (param $0 i32) (param $1 i32) (result i32) - (if (result i32) - (i32.eqz - (local.get $1) - ) - (then - (i32.const 0) - ) - (else - (i32.rem_u - (local.get $0) - (local.get $1) - ) - ) - ) - ) - (func $i64s-div (param $0 i64) (param $1 i64) (result i64) - (if (result i64) - (i64.eqz - (local.get $1) - ) - (then - (i64.const 0) - ) - (else - (if (result i64) - (i32.and - (i64.eq - (local.get $0) - (i64.const -9223372036854775808) - ) - (i64.eq - (local.get $1) - (i64.const -1) - ) - ) - (then - (i64.const 0) - ) - (else - (i64.div_s - (local.get $0) - (local.get $1) - ) - ) - ) - ) - ) - ) - (func $i64s-rem (param $0 i64) (param $1 i64) (result i64) - (if (result i64) - (i64.eqz - (local.get $1) - ) - (then - (i64.const 0) - ) - (else - (i64.rem_s - (local.get $0) - (local.get $1) - ) - ) - ) - ) - (func $i64u-div (param $0 i64) (param $1 i64) (result i64) - (if (result i64) - (i64.eqz - (local.get $1) - ) - (then - (i64.const 0) - ) - (else - (i64.div_u - (local.get $0) - (local.get $1) - ) - ) - ) - ) - (func $i64u-rem (param $0 i64) (param $1 i64) (result i64) - (if (result i64) - (i64.eqz - (local.get $1) - ) - (then - (i64.const 0) - ) - (else - (i64.rem_u - (local.get $0) - (local.get $1) - ) - ) - ) - ) -) diff --git a/test/passes/trap-mode-js.wast b/test/passes/trap-mode-js.wast deleted file mode 100644 index b62165ef54b..00000000000 --- a/test/passes/trap-mode-js.wast +++ /dev/null @@ -1,26 +0,0 @@ -(module - (func $test_div (param $0 i32) (param $1 i64) - (drop (i32.div_s (local.get $0) (local.get $0))) - (drop (i32.div_u (local.get $0) (local.get $0))) - (drop (i64.div_s (local.get $1) (local.get $1))) - (drop (i64.div_u (local.get $1) (local.get $1))) - ) - (func $test_rem (param $0 i32) (param $1 i64) - (drop (i32.rem_s (local.get $0) (local.get $0))) - (drop (i32.rem_u (local.get $0) (local.get $0))) - (drop (i64.rem_s (local.get $1) (local.get $1))) - (drop (i64.rem_u (local.get $1) (local.get $1))) - ) - (func $test_f32_to_int (param $0 f32) - (drop (i32.trunc_f32_s (local.get $0))) - (drop (i32.trunc_f32_u (local.get $0))) - (drop (i64.trunc_f32_s (local.get $0))) - (drop (i64.trunc_f32_u (local.get $0))) - ) - (func $test_f64_to_int (param $0 f64) - (drop (i32.trunc_f64_s (local.get $0))) - (drop (i32.trunc_f64_u (local.get $0))) - (drop (i64.trunc_f64_s (local.get $0))) - (drop (i64.trunc_f64_u (local.get $0))) - ) -)