From 71c769639737af6e80acfef18aad9a761225415e Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Thu, 19 May 2016 15:48:29 +0200 Subject: [PATCH] Bug 1272640: Implement wasm opcodes trunc/nearestint; r=sunfish MozReview-Commit-ID: 5g9KwkTM36k --HG-- extra : rebase_source : 1bcf9863bb895fb7d7ddf44fb2704db58ed4df4b --- js/src/asmjs/Wasm.cpp | 8 ++------ js/src/asmjs/WasmBinaryIterator.cpp | 8 ++++---- js/src/asmjs/WasmIonCompile.cpp | 15 +++++++++------ js/src/asmjs/WasmTypes.cpp | 8 ++++++++ js/src/asmjs/WasmTypes.h | 4 ++++ 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/js/src/asmjs/Wasm.cpp b/js/src/asmjs/Wasm.cpp index b789a5cc791b..0ac57cd8623c 100644 --- a/js/src/asmjs/Wasm.cpp +++ b/js/src/asmjs/Wasm.cpp @@ -289,21 +289,17 @@ DecodeExpr(FunctionDecoder& f) case Expr::F32Ceil: case Expr::F32Floor: case Expr::F32Sqrt: - return f.iter().readUnary(ValType::F32, nullptr); case Expr::F32Trunc: - return f.iter().notYetImplemented("trunc"); case Expr::F32Nearest: - return f.iter().notYetImplemented("nearest"); + return f.iter().readUnary(ValType::F32, nullptr); case Expr::F64Abs: case Expr::F64Neg: case Expr::F64Ceil: case Expr::F64Floor: case Expr::F64Sqrt: - return f.iter().readUnary(ValType::F64, nullptr); case Expr::F64Trunc: - return f.iter().notYetImplemented("trunc"); case Expr::F64Nearest: - return f.iter().notYetImplemented("nearest"); + return f.iter().readUnary(ValType::F64, nullptr); case Expr::I32Add: case Expr::I32Sub: case Expr::I32Mul: diff --git a/js/src/asmjs/WasmBinaryIterator.cpp b/js/src/asmjs/WasmBinaryIterator.cpp index 678525dead3f..f700f9ffd8d0 100644 --- a/js/src/asmjs/WasmBinaryIterator.cpp +++ b/js/src/asmjs/WasmBinaryIterator.cpp @@ -73,11 +73,15 @@ wasm::Classify(Expr expr) case Expr::F32Neg: case Expr::F32Ceil: case Expr::F32Floor: + case Expr::F32Trunc: + case Expr::F32Nearest: case Expr::F32Sqrt: case Expr::F64Abs: case Expr::F64Neg: case Expr::F64Ceil: case Expr::F64Floor: + case Expr::F64Trunc: + case Expr::F64Nearest: case Expr::F64Sqrt: case Expr::I32BitNot: case Expr::I32Abs: @@ -459,10 +463,6 @@ wasm::Classify(Expr expr) return ExprKind::SimdComparison; case Expr::CurrentMemory: case Expr::GrowMemory: - case Expr::F32Trunc: - case Expr::F32Nearest: - case Expr::F64Trunc: - case Expr::F64Nearest: break; } MOZ_MAKE_COMPILER_ASSUME_IS_UNREACHABLE("unimplemented opcode"); diff --git a/js/src/asmjs/WasmIonCompile.cpp b/js/src/asmjs/WasmIonCompile.cpp index 59b0b8ca5f79..e0605646a08b 100644 --- a/js/src/asmjs/WasmIonCompile.cpp +++ b/js/src/asmjs/WasmIonCompile.cpp @@ -3015,6 +3015,10 @@ EmitExpr(FunctionCompiler& f) return EmitUnaryMathBuiltinCall(f, exprOffset, SymbolicAddress::CeilF, ValType::F32); case Expr::F32Floor: return EmitUnaryMathBuiltinCall(f, exprOffset, SymbolicAddress::FloorF, ValType::F32); + case Expr::F32Trunc: + return EmitUnaryMathBuiltinCall(f, exprOffset, SymbolicAddress::TruncF, ValType::F32); + case Expr::F32Nearest: + return EmitUnaryMathBuiltinCall(f, exprOffset, SymbolicAddress::NearbyIntF, ValType::F32); case Expr::F32DemoteF64: return EmitConversion(f, ValType::F64, ValType::F32); case Expr::F32ConvertSI32: @@ -3066,8 +3070,11 @@ EmitExpr(FunctionCompiler& f) case Expr::F64Ceil: return EmitUnaryMathBuiltinCall(f, exprOffset, SymbolicAddress::CeilD, ValType::F64); case Expr::F64Floor: - return EmitUnaryMathBuiltinCall(f, exprOffset, SymbolicAddress::FloorD, - ValType::F64); + return EmitUnaryMathBuiltinCall(f, exprOffset, SymbolicAddress::FloorD, ValType::F64); + case Expr::F64Trunc: + return EmitUnaryMathBuiltinCall(f, exprOffset, SymbolicAddress::TruncD, ValType::F64); + case Expr::F64Nearest: + return EmitUnaryMathBuiltinCall(f, exprOffset, SymbolicAddress::NearbyIntD, ValType::F64); case Expr::F64Sin: return EmitUnaryMathBuiltinCall(f, exprOffset, SymbolicAddress::SinD, ValType::F64); case Expr::F64Cos: @@ -3327,11 +3334,7 @@ EmitExpr(FunctionCompiler& f) // Future opcodes case Expr::F32CopySign: - case Expr::F32Trunc: - case Expr::F32Nearest: case Expr::F64CopySign: - case Expr::F64Nearest: - case Expr::F64Trunc: case Expr::I64Load8S: case Expr::I64Load16S: case Expr::I64Load32S: diff --git a/js/src/asmjs/WasmTypes.cpp b/js/src/asmjs/WasmTypes.cpp index 33271034ccd0..7ff99f5d49d7 100644 --- a/js/src/asmjs/WasmTypes.cpp +++ b/js/src/asmjs/WasmTypes.cpp @@ -305,6 +305,14 @@ wasm::AddressOf(SymbolicAddress imm, ExclusiveContext* cx) return FuncCast(fdlibm::floor, Args_Double_Double); case SymbolicAddress::FloorF: return FuncCast(fdlibm::floorf, Args_Float32_Float32); + case SymbolicAddress::TruncD: + return FuncCast(fdlibm::trunc, Args_Double_Double); + case SymbolicAddress::TruncF: + return FuncCast(fdlibm::truncf, Args_Float32_Float32); + case SymbolicAddress::NearbyIntD: + return FuncCast(nearbyint, Args_Double_Double); + case SymbolicAddress::NearbyIntF: + return FuncCast(nearbyintf, Args_Float32_Float32); case SymbolicAddress::ExpD: return FuncCast(fdlibm::exp, Args_Double_Double); case SymbolicAddress::LogD: diff --git a/js/src/asmjs/WasmTypes.h b/js/src/asmjs/WasmTypes.h index d08fe103756a..e16a066a3246 100644 --- a/js/src/asmjs/WasmTypes.h +++ b/js/src/asmjs/WasmTypes.h @@ -672,6 +672,10 @@ enum class SymbolicAddress CeilF, FloorD, FloorF, + TruncD, + TruncF, + NearbyIntD, + NearbyIntF, ExpD, LogD, PowD,