Title: [209275] trunk
Revision
209275
Author
[email protected]
Date
2016-12-02 14:59:20 -0800 (Fri, 02 Dec 2016)

Log Message

Add Wasm floating point nearest and trunc
https://bugs.webkit.org/show_bug.cgi?id=165339

Reviewed by Filip Pizlo.

JSTests:

* wasm/function-tests/nearest.js: Added.
* wasm/function-tests/trunc.js: Added.

Source/_javascript_Core:

This patch also allows any wasm primitive type to be passed as a
string.

* assembler/MacroAssemblerARM64.h:
(JSC::MacroAssemblerARM64::nearestIntDouble):
(JSC::MacroAssemblerARM64::nearestIntFloat):
(JSC::MacroAssemblerARM64::truncDouble):
(JSC::MacroAssemblerARM64::truncFloat):
* assembler/MacroAssemblerX86Common.h:
(JSC::MacroAssemblerX86Common::nearestIntDouble):
(JSC::MacroAssemblerX86Common::nearestIntFloat):
* jsc.cpp:
(box):
* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::addOp<F64ConvertUI64>):
(JSC::Wasm::B3IRGenerator::addOp<OpType::F32ConvertUI64>):
(JSC::Wasm::B3IRGenerator::addOp<OpType::F64Nearest>):
(JSC::Wasm::B3IRGenerator::addOp<OpType::F32Nearest>):
(JSC::Wasm::B3IRGenerator::addOp<OpType::F64Trunc>):
(JSC::Wasm::B3IRGenerator::addOp<OpType::F32Trunc>):
* wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::parseExpression):

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (209274 => 209275)


--- trunk/JSTests/ChangeLog	2016-12-02 22:53:19 UTC (rev 209274)
+++ trunk/JSTests/ChangeLog	2016-12-02 22:59:20 UTC (rev 209275)
@@ -1,3 +1,13 @@
+2016-12-02  Keith Miller  <[email protected]>
+
+        Add Wasm floating point nearest and trunc
+        https://bugs.webkit.org/show_bug.cgi?id=165339
+
+        Reviewed by Filip Pizlo.
+
+        * wasm/function-tests/nearest.js: Added.
+        * wasm/function-tests/trunc.js: Added.
+
 2016-12-02  JF Bastien  <[email protected]>
 
         WebAssembly: revert patch causing odd breakage

Added: trunk/JSTests/wasm/function-tests/nearest.js (0 => 209275)


--- trunk/JSTests/wasm/function-tests/nearest.js	                        (rev 0)
+++ trunk/JSTests/wasm/function-tests/nearest.js	2016-12-02 22:59:20 UTC (rev 209275)
@@ -0,0 +1,60 @@
+import Builder from '../Builder.js'
+
+const b = new Builder();
+b.Type().End()
+    .Function().End()
+    .Code()
+    .Function({ params: ["f32"], ret: "f32" }, [])
+    .GetLocal(0)
+    .F32Nearest()
+    .End()
+
+    .Function({ params: ["f64"], ret: "f64" }, [])
+    .GetLocal(0)
+    .F64Nearest()
+    .End()
+
+const bin = b.WebAssembly()
+bin.trim();
+testWasmModuleFunctions(bin.get(), 2,
+                        [[{ type: "f32", value: "-0x0p+0" }, [{ type: "f32", value: "-0x0p+0" }]],
+                         [{ type: "f32", value: "0x0p+0" }, [{ type: "f32", value: "0x0p+0" }]],
+                         [{ type: "f32", value: "-0x0p+0" }, [{ type: "f32", value: "-0x1p-149" }]],
+                         [{ type: "f32", value: "0x0p+0" }, [{ type: "f32", value: "0x1p-149" }]],
+                         [{ type: "f32", value: "-0x0p+0" }, [{ type: "f32", value: "-0x1p-126" }]],
+                         [{ type: "f32", value: "0x0p+0" }, [{ type: "f32", value: "0x1p-126" }]],
+                         [{ type: "f32", value: "-0x0p+0" }, [{ type: "f32", value: "-0x1p-1" }]],
+                         [{ type: "f32", value: "0x0p+0" }, [{ type: "f32", value: "0x1p-1" }]],
+                         [{ type: "f32", value: "-0x1p+0" }, [{ type: "f32", value: "-0x1p+0" }]],
+                         [{ type: "f32", value: "0x1p+0" }, [{ type: "f32", value: "0x1p+0" }]],
+                         [{ type: "f32", value: "-0x1.8p+2" }, [{ type: "f32", value: "-0x1.921fb6p+2" }]],
+                         [{ type: "f32", value: "0x1.8p+2" }, [{ type: "f32", value: "0x1.921fb6p+2" }]],
+                         [{ type: "f32", value: "-0x1.fffffep+127" }, [{ type: "f32", value: "-0x1.fffffep+127" }]],
+                         [{ type: "f32", value: "0x1.fffffep+127" }, [{ type: "f32", value: "0x1.fffffep+127" }]],
+                         [{ type: "f32", value: "-infinity" }, [{ type: "f32", value: "-infinity" }]],
+                         [{ type: "f32", value: "infinity" }, [{ type: "f32", value: "infinity" }]],
+                         [{ type: "f32", value: "-nan" }, [{ type: "f32", value: "-nan" }]],
+                         [{ type: "f32", value: "nan" }, [{ type: "f32", value: "nan" }]],
+                        ],
+
+                        [[{ type: "f64", value: "-0x0p+0" }, [{ type: "f64", value: "-0x0p+0" }]],
+                         [{ type: "f64", value: "0x0p+0" }, [{ type: "f64", value: "0x0p+0" }]],
+                         [{ type: "f64", value: "-0x0p+0" }, [{ type: "f64", value: "-0x0.0000000000001p-1022" }]],
+                         [{ type: "f64", value: "0x0p+0" }, [{ type: "f64", value: "0x0.0000000000001p-1022" }]],
+                         [{ type: "f64", value: "-0x0p+0" }, [{ type: "f64", value: "-0x1p-1022" }]],
+                         [{ type: "f64", value: "0x0p+0" }, [{ type: "f64", value: "0x1p-1022" }]],
+                         [{ type: "f64", value: "-0x0p+0" }, [{ type: "f64", value: "-0x1p-1" }]],
+                         [{ type: "f64", value: "0x0p+0" }, [{ type: "f64", value: "0x1p-1" }]],
+                         [{ type: "f64", value: "-0x1p+0" }, [{ type: "f64", value: "-0x1p+0" }]],
+                         [{ type: "f64", value: "0x1p+0" }, [{ type: "f64", value: "0x1p+0" }]],
+                         [{ type: "f64", value: "-0x1.8p+2" }, [{ type: "f64", value: "-0x1.921fb54442d18p+2" }]],
+                         [{ type: "f64", value: "0x1.8p+2" }, [{ type: "f64", value: "0x1.921fb54442d18p+2" }]],
+                         [{ type: "f64", value: "-0x1.fffffffffffffp+1023" }, [{ type: "f64", value: "-0x1.fffffffffffffp+1023" }]],
+                         [{ type: "f64", value: "0x1.fffffffffffffp+1023" }, [{ type: "f64", value: "0x1.fffffffffffffp+1023" }]],
+                         [{ type: "f64", value: "-infinity" }, [{ type: "f64", value: "-infinity" }]],
+                         [{ type: "f64", value: "infinity" }, [{ type: "f64", value: "infinity" }]],
+                         [{ type: "f64", value: "-nan" }, [{ type: "f64", value: "-nan" }]],
+                         [{ type: "f64", value: "nan" }, [{ type: "f64", value: "nan" }]]
+                        ]
+
+                       );

Added: trunk/JSTests/wasm/function-tests/trunc.js (0 => 209275)


--- trunk/JSTests/wasm/function-tests/trunc.js	                        (rev 0)
+++ trunk/JSTests/wasm/function-tests/trunc.js	2016-12-02 22:59:20 UTC (rev 209275)
@@ -0,0 +1,59 @@
+import Builder from '../Builder.js'
+
+const b = new Builder();
+b.Type().End()
+    .Function().End()
+    .Code()
+    .Function({ params: ["f32"], ret: "f32" }, [])
+    .GetLocal(0)
+    .F32Trunc()
+    .End()
+
+    .Function({ params: ["f64"], ret: "f64" }, [])
+    .GetLocal(0)
+    .F64Trunc()
+    .End()
+
+const bin = b.WebAssembly()
+bin.trim();
+testWasmModuleFunctions(bin.get(), 2,
+                        [[{ type: "f32", value: "-0x0p+0" }, [{ type: "f32", value: "-0x0p+0" }]],
+                         [{ type: "f32", value: "0x0p+0" }, [{ type: "f32", value: "0x0p+0" }]],
+                         [{ type: "f32", value: "-0x0p+0" }, [{ type: "f32", value: "-0x1p-149" }]],
+                         [{ type: "f32", value: "0x0p+0" }, [{ type: "f32", value: "0x1p-149" }]],
+                         [{ type: "f32", value: "-0x0p+0" }, [{ type: "f32", value: "-0x1p-126" }]],
+                         [{ type: "f32", value: "0x0p+0" }, [{ type: "f32", value: "0x1p-126" }]],
+                         [{ type: "f32", value: "-0x0p+0" }, [{ type: "f32", value: "-0x1p-1" }]],
+                         [{ type: "f32", value: "0x0p+0" }, [{ type: "f32", value: "0x1p-1" }]],
+                         [{ type: "f32", value: "-0x1p+0" }, [{ type: "f32", value: "-0x1p+0" }]],
+                         [{ type: "f32", value: "0x1p+0" }, [{ type: "f32", value: "0x1p+0" }]],
+                         [{ type: "f32", value: "-0x1.8p+2" }, [{ type: "f32", value: "-0x1.921fb6p+2" }]],
+                         [{ type: "f32", value: "0x1.8p+2" }, [{ type: "f32", value: "0x1.921fb6p+2" }]],
+                         [{ type: "f32", value: "-0x1.fffffep+127" }, [{ type: "f32", value: "-0x1.fffffep+127" }]],
+                         [{ type: "f32", value: "0x1.fffffep+127" }, [{ type: "f32", value: "0x1.fffffep+127" }]],
+                         [{ type: "f32", value: "-infinity" }, [{ type: "f32", value: "-infinity" }]],
+                         [{ type: "f32", value: "infinity" }, [{ type: "f32", value: "infinity" }]],
+                         [{ type: "f32", value: "-nan" }, [{ type: "f32", value: "-nan" }]],
+                         [{ type: "f32", value: "nan" }, [{ type: "f32", value: "nan" }]]
+                        ],
+
+                        [[{ type: "f64", value: "-0x0p+0" }, [{ type: "f64", value: "-0x0p+0" }]],
+                         [{ type: "f64", value: "0x0p+0" }, [{ type: "f64", value: "0x0p+0" }]],
+                         [{ type: "f64", value: "-0x0p+0" }, [{ type: "f64", value: "-0x0.0000000000001p-1022" }]],
+                         [{ type: "f64", value: "0x0p+0" }, [{ type: "f64", value: "0x0.0000000000001p-1022" }]],
+                         [{ type: "f64", value: "-0x0p+0" }, [{ type: "f64", value: "-0x1p-1022" }]],
+                         [{ type: "f64", value: "0x0p+0" }, [{ type: "f64", value: "0x1p-1022" }]],
+                         [{ type: "f64", value: "-0x0p+0" }, [{ type: "f64", value: "-0x1p-1" }]],
+                         [{ type: "f64", value: "0x0p+0" }, [{ type: "f64", value: "0x1p-1" }]],
+                         [{ type: "f64", value: "-0x1p+0" }, [{ type: "f64", value: "-0x1p+0" }]],
+                         [{ type: "f64", value: "0x1p+0" }, [{ type: "f64", value: "0x1p+0" }]],
+                         [{ type: "f64", value: "-0x1.8p+2" }, [{ type: "f64", value: "-0x1.921fb54442d18p+2" }]],
+                         [{ type: "f64", value: "0x1.8p+2" }, [{ type: "f64", value: "0x1.921fb54442d18p+2" }]],
+                         [{ type: "f64", value: "-0x1.fffffffffffffp+1023" }, [{ type: "f64", value: "-0x1.fffffffffffffp+1023" }]],
+                         [{ type: "f64", value: "0x1.fffffffffffffp+1023" }, [{ type: "f64", value: "0x1.fffffffffffffp+1023" }]],
+                         [{ type: "f64", value: "-infinity" }, [{ type: "f64", value: "-infinity" }]],
+                         [{ type: "f64", value: "infinity" }, [{ type: "f64", value: "infinity" }]],
+                         [{ type: "f64", value: "-nan" }, [{ type: "f64", value: "-nan" }]],
+                         [{ type: "f64", value: "nan" }, [{ type: "f64", value: "nan" }]]
+                        ]
+                       );

Modified: trunk/Source/_javascript_Core/ChangeLog (209274 => 209275)


--- trunk/Source/_javascript_Core/ChangeLog	2016-12-02 22:53:19 UTC (rev 209274)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-12-02 22:59:20 UTC (rev 209275)
@@ -1,3 +1,33 @@
+2016-12-02  Keith Miller  <[email protected]>
+
+        Add Wasm floating point nearest and trunc
+        https://bugs.webkit.org/show_bug.cgi?id=165339
+
+        Reviewed by Filip Pizlo.
+
+        This patch also allows any wasm primitive type to be passed as a
+        string.
+
+        * assembler/MacroAssemblerARM64.h:
+        (JSC::MacroAssemblerARM64::nearestIntDouble):
+        (JSC::MacroAssemblerARM64::nearestIntFloat):
+        (JSC::MacroAssemblerARM64::truncDouble):
+        (JSC::MacroAssemblerARM64::truncFloat):
+        * assembler/MacroAssemblerX86Common.h:
+        (JSC::MacroAssemblerX86Common::nearestIntDouble):
+        (JSC::MacroAssemblerX86Common::nearestIntFloat):
+        * jsc.cpp:
+        (box):
+        * wasm/WasmB3IRGenerator.cpp:
+        (JSC::Wasm::B3IRGenerator::addOp<F64ConvertUI64>):
+        (JSC::Wasm::B3IRGenerator::addOp<OpType::F32ConvertUI64>):
+        (JSC::Wasm::B3IRGenerator::addOp<OpType::F64Nearest>):
+        (JSC::Wasm::B3IRGenerator::addOp<OpType::F32Nearest>):
+        (JSC::Wasm::B3IRGenerator::addOp<OpType::F64Trunc>):
+        (JSC::Wasm::B3IRGenerator::addOp<OpType::F32Trunc>):
+        * wasm/WasmFunctionParser.h:
+        (JSC::Wasm::FunctionParser<Context>::parseExpression):
+
 2016-12-02  JF Bastien  <[email protected]>
 
         WebAssembly: revert patch causing odd breakage

Modified: trunk/Source/_javascript_Core/assembler/MacroAssemblerARM64.h (209274 => 209275)


--- trunk/Source/_javascript_Core/assembler/MacroAssemblerARM64.h	2016-12-02 22:53:19 UTC (rev 209274)
+++ trunk/Source/_javascript_Core/assembler/MacroAssemblerARM64.h	2016-12-02 22:59:20 UTC (rev 209275)
@@ -1540,6 +1540,16 @@
         m_assembler.fadd<32>(dest, op1, op2);
     }
 
+    void nearestIntDouble(FPRegisterID src, FPRegisterID dest)
+    {
+        m_assembler.frinta<64>(dest, src);
+    }
+
+    void nearestIntFloat(FPRegisterID src, FPRegisterID dest)
+    {
+        m_assembler.frinta<32>(dest, src);
+    }
+
     void ceilDouble(FPRegisterID src, FPRegisterID dest)
     {
         m_assembler.frintp<64>(dest, src);
@@ -1693,6 +1703,16 @@
         m_assembler.ucvtf<32, 64>(dest, src);
     }
 
+    void truncDouble(FPRegisterID src, FPRegisterID dest)
+    {
+        m_assembler.frintz<64, 64>(dest, src);
+    }
+
+    void truncFloat(FPRegisterID src, FPRegisterID dest)
+    {
+        m_assembler.frintz<32, 32>(dest, src);
+    }
+
     void divDouble(FPRegisterID src, FPRegisterID dest)
     {
         divDouble(dest, src, dest);

Modified: trunk/Source/_javascript_Core/assembler/MacroAssemblerX86Common.h (209274 => 209275)


--- trunk/Source/_javascript_Core/assembler/MacroAssemblerX86Common.h	2016-12-02 22:53:19 UTC (rev 209274)
+++ trunk/Source/_javascript_Core/assembler/MacroAssemblerX86Common.h	2016-12-02 22:59:20 UTC (rev 209275)
@@ -757,6 +757,16 @@
         m_assembler.xorpd_rr(src, dst);
     }
 
+    void nearestIntDouble(FPRegisterID src, FPRegisterID dst)
+    {
+        m_assembler.roundsd_rr(src, dst, X86Assembler::RoundingType::ToNearestWithTiesToEven);
+    }
+
+    void nearestIntFloat(FPRegisterID src, FPRegisterID dst)
+    {
+        m_assembler.roundss_rr(src, dst, X86Assembler::RoundingType::ToNearestWithTiesToEven);
+    }
+
     void ceilDouble(FPRegisterID src, FPRegisterID dst)
     {
         m_assembler.roundsd_rr(src, dst, X86Assembler::RoundingType::TowardInfiniti);

Modified: trunk/Source/_javascript_Core/jsc.cpp (209274 => 209275)


--- trunk/Source/_javascript_Core/jsc.cpp	2016-12-02 22:53:19 UTC (rev 209274)
+++ trunk/Source/_javascript_Core/jsc.cpp	2016-12-02 22:59:20 UTC (rev 209275)
@@ -2510,33 +2510,60 @@
 
 static JSValue box(ExecState* exec, VM& vm, JSValue wasmValue)
 {
+
     JSString* type = jsCast<JSString*>(wasmValue.get(exec, makeIdentifier(vm, "type")));
     JSValue value = wasmValue.get(exec, makeIdentifier(vm, "value"));
 
-    const String& typeString = type->value(exec);
-    if (typeString == "i64") {
-        int64_t result;
+    auto unboxString = [&] (const char* hexFormat, const char* decFormat, auto& result) {
+        if (!value.isString())
+            return false;
+
         const char* str = toCString(jsCast<JSString*>(value)->value(exec)).data();
         int scanResult;
-        if (std::strlen(str) > 2 && str[0] == '0' && str[1] == 'x')
-            scanResult = sscanf(str, "%llx", &result);
+        int length = std::strlen(str);
+        if ((length > 2 && (str[0] == '0' && str[1] == 'x'))
+            || (length > 3 && (str[0] == '-' && str[1] == '0' && str[2] == 'x')))
+#if COMPILER(CLANG)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wformat-nonliteral"
+#endif
+            scanResult = sscanf(str, hexFormat, &result);
         else
-            scanResult = sscanf(str, "%lld", &result);
+            scanResult = sscanf(str, decFormat, &result);
+#if COMPILER(CLANG)
+#pragma clang diagnostic pop
+#endif
         RELEASE_ASSERT(scanResult != EOF);
+        return true;
+    };
+
+    const String& typeString = type->value(exec);
+    if (typeString == "i64") {
+        int64_t result;
+        if (!unboxString("%llx", "%lld", result))
+            CRASH();
         return JSValue::decode(result);
     }
-    RELEASE_ASSERT(value.isNumber());
 
     if (typeString == "i32") {
-        RELEASE_ASSERT(value.isInt32());
-        return JSValue::decode(static_cast<uint32_t>(value.asInt32()));
+        int32_t result;
+        if (!unboxString("%x", "%d", result))
+            result = value.asInt32();
+        return JSValue::decode(static_cast<uint32_t>(result));
     }
 
-    if (typeString == "f32")
-        return JSValue::decode(bitwise_cast<uint32_t>(value.toFloat(exec)));
+    if (typeString == "f32") {
+        float result;
+        if (!unboxString("%a", "%f", result))
+            result = value.toFloat(exec);
+        return JSValue::decode(bitwise_cast<uint32_t>(result));
+    }
 
     RELEASE_ASSERT(typeString == "f64");
-    return JSValue::decode(bitwise_cast<uint64_t>(value.asNumber()));
+    double result;
+    if (!unboxString("%la", "%lf", result))
+        result = value.asNumber();
+    return JSValue::decode(bitwise_cast<uint64_t>(result));
 }
 
 static JSValue callWasmFunction(VM* vm, const B3::Compilation& code, Vector<JSValue>& boxedArgs)

Modified: trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp (209274 => 209275)


--- trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp	2016-12-02 22:53:19 UTC (rev 209274)
+++ trunk/Source/_javascript_Core/wasm/WasmB3IRGenerator.cpp	2016-12-02 22:59:20 UTC (rev 209275)
@@ -29,6 +29,7 @@
 #if ENABLE(WEBASSEMBLY)
 
 #include "B3BasicBlockInlines.h"
+#include "B3CCallValue.h"
 #include "B3ConstPtrValue.h"
 #include "B3FixSSA.h"
 #include "B3StackmapGenerationParams.h"
@@ -749,7 +750,7 @@
     PatchpointValue* patchpoint = m_currentBlock->appendNew<PatchpointValue>(m_proc, Float, Origin());
     if (isX86())
         patchpoint->numGPScratchRegisters = 1;
-    patchpoint->append(ConstrainedValue(arg, ValueRep::WarmAny));
+    patchpoint->append(arg, ValueRep::SomeRegister);
     patchpoint->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
         AllowMacroScratchRegisterUsage allowScratch(jit);
 #if CPU(X86_64)
@@ -769,7 +770,7 @@
     PatchpointValue* patchpoint = m_currentBlock->appendNew<PatchpointValue>(m_proc, Float, Origin());
     if (isX86())
         patchpoint->numGPScratchRegisters = 1;
-    patchpoint->append(ConstrainedValue(arg, ValueRep::WarmAny));
+    patchpoint->append(arg, ValueRep::SomeRegister);
     patchpoint->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
         AllowMacroScratchRegisterUsage allowScratch(jit);
 #if CPU(X86_64)
@@ -783,6 +784,70 @@
     return true;
 }
 
+template<>
+bool B3IRGenerator::addOp<OpType::F64Nearest>(ExpressionType arg, ExpressionType& result)
+{
+    PatchpointValue* patchpoint = m_currentBlock->appendNew<PatchpointValue>(m_proc, Double, Origin());
+    patchpoint->append(arg, ValueRep::SomeRegister);
+    patchpoint->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
+        jit.nearestIntDouble(params[1].fpr(), params[0].fpr());
+    });
+    patchpoint->effects = Effects::none();
+    result = patchpoint;
+    return true;
+}
+
+template<>
+bool B3IRGenerator::addOp<OpType::F32Nearest>(ExpressionType arg, ExpressionType& result)
+{
+    PatchpointValue* patchpoint = m_currentBlock->appendNew<PatchpointValue>(m_proc, Float, Origin());
+    patchpoint->append(arg, ValueRep::SomeRegister);
+    patchpoint->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
+        jit.nearestIntFloat(params[1].fpr(), params[0].fpr());
+    });
+    patchpoint->effects = Effects::none();
+    result = patchpoint;
+    return true;
+}
+
+template<>
+bool B3IRGenerator::addOp<OpType::F64Trunc>(ExpressionType arg, ExpressionType& result)
+{
+#if CPU(X86_64)
+    double (*truncDouble)(double) = std::nearbyint;
+    Value* truncAddress = m_currentBlock->appendNew<ConstPtrValue>(m_proc, Origin(), truncDouble);
+    result = m_currentBlock->appendNew<CCallValue>(m_proc, Double, Origin(), Effects::none(), truncAddress, arg);
+#else
+    PatchpointValue* patchpoint = m_currentBlock->appendNew<PatchpointValue>(m_proc, Double, Origin());
+    patchpoint->append(arg, ValueRep::SomeRegister);
+    patchpoint->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
+        jit.truncDouble(params[1].fpr(), params[0].fpr());
+    });
+    patchpoint->effects = Effects::none();
+    result = patchpoint;
+#endif
+    return true;
+}
+
+template<>
+bool B3IRGenerator::addOp<OpType::F32Trunc>(ExpressionType arg, ExpressionType& result)
+{
+#if CPU(X86_64)
+    float (*roundFloat)(float) = std::trunc;
+    Value* roundAddress = m_currentBlock->appendNew<ConstPtrValue>(m_proc, Origin(), roundFloat);
+    result = m_currentBlock->appendNew<CCallValue>(m_proc, Float, Origin(), Effects::none(), roundAddress, arg);
+#else
+    PatchpointValue* patchpoint = m_currentBlock->appendNew<PatchpointValue>(m_proc, Float, Origin());
+    patchpoint->append(arg, ValueRep::SomeRegister);
+    patchpoint->setGenerator([=] (CCallHelpers& jit, const StackmapGenerationParams& params) {
+        jit.truncFloat(params[1].fpr(), params[0].fpr());
+    });
+    patchpoint->effects = Effects::none();
+    result = patchpoint;
+#endif
+    return true;
+}
+
 } } // namespace JSC::Wasm
 
 #include "WasmB3IRGeneratorInlines.h"

Modified: trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h (209274 => 209275)


--- trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h	2016-12-02 22:53:19 UTC (rev 209274)
+++ trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h	2016-12-02 22:59:20 UTC (rev 209275)
@@ -213,6 +213,10 @@
 
     case OpType::F32ConvertUI64: return unaryCase<OpType::F32ConvertUI64>();
     case OpType::F64ConvertUI64: return unaryCase<OpType::F64ConvertUI64>();
+    case OpType::F32Nearest: return unaryCase<OpType::F32Nearest>();
+    case OpType::F64Nearest: return unaryCase<OpType::F64Nearest>();
+    case OpType::F32Trunc: return unaryCase<OpType::F32Trunc>();
+    case OpType::F64Trunc: return unaryCase<OpType::F64Trunc>();
 #define CREATE_CASE(name, id, b3op) case OpType::name: return unaryCase<OpType::name>();
     FOR_EACH_WASM_SIMPLE_UNARY_OP(CREATE_CASE)
 #undef CREATE_CASE
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to