From 6844905cedcabc1d7a1a0fa23ace9f43f5ea619f Mon Sep 17 00:00:00 2001 From: Lars T Hansen Date: Tue, 9 Jan 2018 10:52:42 +0100 Subject: [PATCH] Bug 1428971 - Control wasm sign extension opcodes by a dedicated define. r=bbouvier These opcodes are useful by themselves and several people have already mooted the possibility of letting them ride the wasm train independently of the thread feature. So do not make them dependent on the threads ifdef, but give them their own. --HG-- extra : rebase_source : 58c4638b85cb03c8ecb4af61b11fcb6f388fa9fa --- js/src/builtin/TestingFunctions.cpp | 18 ++++++++++++++++++ js/src/jit-test/tests/wasm/conversion.js | 2 +- js/src/moz.build | 1 + js/src/wasm/WasmBaselineCompile.cpp | 2 +- js/src/wasm/WasmBinaryConstants.h | 2 +- js/src/wasm/WasmBinaryIterator.cpp | 2 +- js/src/wasm/WasmBinaryToAST.cpp | 2 +- js/src/wasm/WasmBinaryToText.cpp | 2 +- js/src/wasm/WasmIonCompile.cpp | 4 ++-- js/src/wasm/WasmTextToBinary.cpp | 4 ++-- js/src/wasm/WasmValidate.cpp | 2 +- 11 files changed, 30 insertions(+), 11 deletions(-) diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp index dc1757251019..a266762e2cd5 100644 --- a/js/src/builtin/TestingFunctions.cpp +++ b/js/src/builtin/TestingFunctions.cpp @@ -553,6 +553,19 @@ WasmThreadsSupported(JSContext* cx, unsigned argc, Value* vp) return true; } +static bool +WasmSignExtensionSupported(JSContext* cx, unsigned argc, Value* vp) +{ + CallArgs args = CallArgsFromVp(argc, vp); +#ifdef ENABLE_WASM_SIGNEXTEND_OPS + bool isSupported = true; +#else + bool isSupported = false; +#endif + args.rval().setBoolean(isSupported); + return true; +} + static bool WasmCompileMode(JSContext* cx, unsigned argc, Value* vp) { @@ -5259,6 +5272,11 @@ gc::ZealModeHelpText), JS_FN_HELP("wasmThreadsSupported", WasmThreadsSupported, 0, 0, "wasmThreadsSupported()", " Returns a boolean indicating whether the WebAssembly threads proposal is\n" +" supported on the current device."), + + JS_FN_HELP("wasmSignExtensionSupported", WasmSignExtensionSupported, 0, 0, +"wasmSignExtensionSupported()", +" Returns a boolean indicating whether the WebAssembly sign extension opcodes are\n" " supported on the current device."), JS_FN_HELP("wasmCompileMode", WasmCompileMode, 0, 0, diff --git a/js/src/jit-test/tests/wasm/conversion.js b/js/src/jit-test/tests/wasm/conversion.js index 552dc0968d2d..9a76ccb7d2b3 100644 --- a/js/src/jit-test/tests/wasm/conversion.js +++ b/js/src/jit-test/tests/wasm/conversion.js @@ -238,7 +238,7 @@ testTrap('i64', 'trunc_u', 'f32', "-infinity"); testConversion('i64', 'reinterpret', 'f64', 40.09999999999968, "0x40440ccccccccca0"); testConversion('f64', 'reinterpret', 'i64', "0x40440ccccccccca0", 40.09999999999968); -if (wasmThreadsSupported()) { +if (wasmSignExtensionSupported()) { testSignExtension('i32', 'extend8_s', 'i32', 0x7F, 0x7F); testSignExtension('i32', 'extend8_s', 'i32', 0x80, -0x80); testSignExtension('i32', 'extend16_s', 'i32', 0x7FFF, 0x7FFF); diff --git a/js/src/moz.build b/js/src/moz.build index 257a196fd7d7..36679284398d 100755 --- a/js/src/moz.build +++ b/js/src/moz.build @@ -640,6 +640,7 @@ FINAL_LIBRARY = 'js' if CONFIG['NIGHTLY_BUILD']: DEFINES['ENABLE_BINARYDATA'] = True DEFINES['ENABLE_SIMD'] = True + DEFINES['ENABLE_WASM_SIGNEXTEND_OPS'] = True DEFINES['ENABLE_WASM_THREAD_OPS'] = True if CONFIG['JS_BUILD_BINAST']: diff --git a/js/src/wasm/WasmBaselineCompile.cpp b/js/src/wasm/WasmBaselineCompile.cpp index b4165b5dc4f4..c3c46c009643 100644 --- a/js/src/wasm/WasmBaselineCompile.cpp +++ b/js/src/wasm/WasmBaselineCompile.cpp @@ -8959,7 +8959,7 @@ BaseCompiler::emitBody() CHECK_NEXT(emitComparison(emitCompareF64, ValType::F64, Assembler::DoubleGreaterThanOrEqual)); // Sign extensions -#ifdef ENABLE_WASM_THREAD_OPS +#ifdef ENABLE_WASM_SIGNEXTEND_OPS case uint16_t(Op::I32Extend8S): CHECK_NEXT(emitConversion(emitExtendI32_8, ValType::I32, ValType::I32)); case uint16_t(Op::I32Extend16S): diff --git a/js/src/wasm/WasmBinaryConstants.h b/js/src/wasm/WasmBinaryConstants.h index 71b14c251287..cab84708e3aa 100644 --- a/js/src/wasm/WasmBinaryConstants.h +++ b/js/src/wasm/WasmBinaryConstants.h @@ -314,7 +314,7 @@ enum class Op F32ReinterpretI32 = 0xbe, F64ReinterpretI64 = 0xbf, -#ifdef ENABLE_WASM_THREAD_OPS +#ifdef ENABLE_WASM_SIGNEXTEND_OPS // Sign extension I32Extend8S = 0xc0, I32Extend16S = 0xc1, diff --git a/js/src/wasm/WasmBinaryIterator.cpp b/js/src/wasm/WasmBinaryIterator.cpp index 1e2a7af5d795..0b2b4fe67b92 100644 --- a/js/src/wasm/WasmBinaryIterator.cpp +++ b/js/src/wasm/WasmBinaryIterator.cpp @@ -177,7 +177,7 @@ wasm::Classify(OpBytes op) case Op::F64ConvertUI64: case Op::F64ReinterpretI64: case Op::F64PromoteF32: -#ifdef ENABLE_WASM_THREAD_OPS +#ifdef ENABLE_WASM_SIGNEXTEND_OPS case Op::I32Extend8S: case Op::I32Extend16S: case Op::I64Extend8S: diff --git a/js/src/wasm/WasmBinaryToAST.cpp b/js/src/wasm/WasmBinaryToAST.cpp index e4f7dca9e191..5082d4f78f57 100644 --- a/js/src/wasm/WasmBinaryToAST.cpp +++ b/js/src/wasm/WasmBinaryToAST.cpp @@ -1513,7 +1513,7 @@ AstDecodeExpr(AstDecodeContext& c) if (!AstDecodeConversion(c, ValType::F32, ValType::F64, Op(op.b0))) return false; break; -#ifdef ENABLE_WASM_THREAD_OPS +#ifdef ENABLE_WASM_SIGNEXTEND_OPS case uint16_t(Op::I32Extend8S): case uint16_t(Op::I32Extend16S): if (!AstDecodeConversion(c, ValType::I32, ValType::I32, Op(op.b0))) diff --git a/js/src/wasm/WasmBinaryToText.cpp b/js/src/wasm/WasmBinaryToText.cpp index 427bcd937bc6..3f20d684ead2 100644 --- a/js/src/wasm/WasmBinaryToText.cpp +++ b/js/src/wasm/WasmBinaryToText.cpp @@ -736,7 +736,7 @@ RenderConversionOperator(WasmRenderContext& c, AstConversionOperator& conv) case Op::F64ConvertUI64: opStr = "f64.convert_u/i64"; break; case Op::F64ReinterpretI64: opStr = "f64.reinterpret/i64"; break; case Op::F64PromoteF32: opStr = "f64.promote/f32"; break; -#ifdef ENABLE_WASM_THREAD_OPS +#ifdef ENABLE_WASM_SIGNEXTEND_OPS case Op::I32Extend8S: opStr = "i32.extend8_s"; break; case Op::I32Extend16S: opStr = "i32.extend16_s"; break; case Op::I64Extend8S: opStr = "i64.extend8_s"; break; diff --git a/js/src/wasm/WasmIonCompile.cpp b/js/src/wasm/WasmIonCompile.cpp index 26a9c615af22..807eb6027ead 100644 --- a/js/src/wasm/WasmIonCompile.cpp +++ b/js/src/wasm/WasmIonCompile.cpp @@ -2430,7 +2430,7 @@ EmitTruncate(FunctionCompiler& f, ValType operandType, ValType resultType, return true; } -#ifdef ENABLE_WASM_THREAD_OPS +#ifdef ENABLE_WASM_SIGNEXTEND_OPS static bool EmitSignExtend(FunctionCompiler& f, uint32_t srcSize, uint32_t targetSize) { @@ -3965,7 +3965,7 @@ EmitBodyExprs(FunctionCompiler& f) CHECK(EmitReinterpret(f, ValType::F64, ValType::I64, MIRType::Double)); // Sign extensions -#ifdef ENABLE_WASM_THREAD_OPS +#ifdef ENABLE_WASM_SIGNEXTEND_OPS case uint16_t(Op::I32Extend8S): CHECK(EmitSignExtend(f, 1, 4)); case uint16_t(Op::I32Extend16S): diff --git a/js/src/wasm/WasmTextToBinary.cpp b/js/src/wasm/WasmTextToBinary.cpp index 6f360703693a..a6b73cfcee5e 100644 --- a/js/src/wasm/WasmTextToBinary.cpp +++ b/js/src/wasm/WasmTextToBinary.cpp @@ -1221,7 +1221,7 @@ WasmTokenStream::next() return WasmToken(WasmToken::UnaryOpcode, Op::I32Eqz, begin, cur_); if (consume(u"eq")) return WasmToken(WasmToken::ComparisonOpcode, Op::I32Eq, begin, cur_); -#ifdef ENABLE_WASM_THREAD_OPS +#ifdef ENABLE_WASM_SIGNEXTEND_OPS if (consume(u"extend8_s")) return WasmToken(WasmToken::ConversionOpcode, Op::I32Extend8S, begin, cur_); if (consume(u"extend16_s")) @@ -1449,7 +1449,7 @@ WasmTokenStream::next() if (consume(u"extend_u/i32")) return WasmToken(WasmToken::ConversionOpcode, Op::I64ExtendUI32, begin, cur_); -#ifdef ENABLE_WASM_THREAD_OPS +#ifdef ENABLE_WASM_SIGNEXTEND_OPS if (consume(u"extend8_s")) return WasmToken(WasmToken::ConversionOpcode, Op::I64Extend8S, begin, cur_); if (consume(u"extend16_s")) diff --git a/js/src/wasm/WasmValidate.cpp b/js/src/wasm/WasmValidate.cpp index 07f7aa7fe8c0..9aab571b3771 100644 --- a/js/src/wasm/WasmValidate.cpp +++ b/js/src/wasm/WasmValidate.cpp @@ -607,7 +607,7 @@ DecodeFunctionBodyExprs(const ModuleEnvironment& env, const Sig& sig, const ValT CHECK(iter.readConversion(ValType::I64, ValType::F64, ¬hing)); case uint16_t(Op::F64PromoteF32): CHECK(iter.readConversion(ValType::F32, ValType::F64, ¬hing)); -#ifdef ENABLE_WASM_THREAD_OPS +#ifdef ENABLE_WASM_SIGNEXTEND_OPS case uint16_t(Op::I32Extend8S): case uint16_t(Op::I32Extend16S): CHECK(iter.readConversion(ValType::I32, ValType::I32, ¬hing));