Title: [209503] trunk
Revision
209503
Author
keith_mil...@apple.com
Date
2016-12-07 17:13:40 -0800 (Wed, 07 Dec 2016)

Log Message

Add more missing trivial wasm ops.
https://bugs.webkit.org/show_bug.cgi?id=165564

JSTests:

Add tests for drop and tee_local.

Reviewed by Geoffrey Garen.

* wasm/function-tests/drop.js: Added.
* wasm/function-tests/nop.js: Added.
* wasm/function-tests/tee-local.js: Added.

Source/_javascript_Core:

Reviewed by Geoffrey Garen.

This patch adds the nop, drop, and tee_local opcodes.
It also fixes an issue where we were not generating
the proper enums for the grow_memory and current_memory
opcodes.

* wasm/WasmFunctionParser.h:
(JSC::Wasm::FunctionParser<Context>::parseExpression):
* wasm/generateWasmOpsHeader.py:

Modified Paths

Added Paths

Diff

Modified: trunk/JSTests/ChangeLog (209502 => 209503)


--- trunk/JSTests/ChangeLog	2016-12-08 01:08:48 UTC (rev 209502)
+++ trunk/JSTests/ChangeLog	2016-12-08 01:13:40 UTC (rev 209503)
@@ -1,3 +1,16 @@
+2016-12-07  Keith Miller  <keith_mil...@apple.com>
+
+        Add more missing trivial wasm ops.
+        https://bugs.webkit.org/show_bug.cgi?id=165564
+
+        Add tests for drop and tee_local.
+
+        Reviewed by Geoffrey Garen.
+
+        * wasm/function-tests/drop.js: Added.
+        * wasm/function-tests/nop.js: Added.
+        * wasm/function-tests/tee-local.js: Added.
+
 2016-12-06  Keith Miller  <keith_mil...@apple.com>
 
         Add support for truncation operators

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


--- trunk/JSTests/wasm/function-tests/drop.js	                        (rev 0)
+++ trunk/JSTests/wasm/function-tests/drop.js	2016-12-08 01:13:40 UTC (rev 209503)
@@ -0,0 +1,39 @@
+import Builder from '../Builder.js'
+
+const b = new Builder();
+b.Type().End()
+    .Function().End()
+    .Code()
+
+    // This function adds one to the argument.
+    .Function({ params: ["i32"], ret: "i32" }, [])
+    .GetLocal(0)
+    .I32Const(1)
+    .TeeLocal(0)
+    .GetLocal(0)
+    .Drop()
+    .I32Add()
+    .End()
+
+    // This is the id function.
+    .Function({ params: ["i32"], ret: "i32" }, [])
+    .GetLocal(0)
+    .I32Const(1)
+    .Drop()
+    .End()
+
+const bin = b.WebAssembly()
+bin.trim();
+testWasmModuleFunctions(bin.get(), 2,
+                        [[{ type: "i32", value: 1 }, [{ type: "i32", value: 0 }]],
+                         [{ type: "i32", value: 2 }, [{ type: "i32", value: 1 }]],
+                         [{ type: "i32", value: 101 }, [{ type: "i32", value: 100 }]],
+                         [{ type: "i32", value: -99 }, [{ type: "i32", value: -100 }]],
+                        ],
+
+                        [[{ type: "i32", value: 0 }, [{ type: "i32", value: 0 }]],
+                         [{ type: "i32", value: 1 }, [{ type: "i32", value: 1 }]],
+                         [{ type: "i32", value: 100 }, [{ type: "i32", value: 100 }]],
+                         [{ type: "i32", value: -100 }, [{ type: "i32", value: -100 }]],
+                        ],
+                       );

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


--- trunk/JSTests/wasm/function-tests/nop.js	                        (rev 0)
+++ trunk/JSTests/wasm/function-tests/nop.js	2016-12-08 01:13:40 UTC (rev 209503)
@@ -0,0 +1,34 @@
+import Builder from '../Builder.js'
+
+const b = new Builder();
+b.Type().End()
+    .Function().End()
+    .Code()
+
+    // This function adds one to the argument.
+    .Function({ params: ["i32"], ret: "i32" }, [])
+    .GetLocal(0)
+    .Nop()
+    .End()
+
+    // This is the id function.
+    .Function({ params: ["i32"], ret: "i32" }, [])
+    .Nop()
+    .GetLocal(0)
+    .End()
+
+const bin = b.WebAssembly()
+bin.trim();
+testWasmModuleFunctions(bin.get(), 2,
+                        [[{ type: "i32", value: 0 }, [{ type: "i32", value: 0 }]],
+                         [{ type: "i32", value: 1 }, [{ type: "i32", value: 1 }]],
+                         [{ type: "i32", value: 100 }, [{ type: "i32", value: 100 }]],
+                         [{ type: "i32", value: -100 }, [{ type: "i32", value: -100 }]],
+                        ],
+
+                        [[{ type: "i32", value: 0 }, [{ type: "i32", value: 0 }]],
+                         [{ type: "i32", value: 1 }, [{ type: "i32", value: 1 }]],
+                         [{ type: "i32", value: 100 }, [{ type: "i32", value: 100 }]],
+                         [{ type: "i32", value: -100 }, [{ type: "i32", value: -100 }]],
+                        ],
+                       );

Added: trunk/JSTests/wasm/function-tests/tee-local.js (0 => 209503)


--- trunk/JSTests/wasm/function-tests/tee-local.js	                        (rev 0)
+++ trunk/JSTests/wasm/function-tests/tee-local.js	2016-12-08 01:13:40 UTC (rev 209503)
@@ -0,0 +1,26 @@
+import Builder from '../Builder.js'
+
+const b = new Builder();
+b.Type().End()
+    .Function().End()
+    .Code()
+
+    // This function multiplies the argument by 2
+    .Function({ params: ["i32"], ret: "i32" }, [])
+    .GetLocal(0)
+    .I32Const(1)
+    .TeeLocal(0)
+    .GetLocal(0)
+    .I32Add()
+    .I32Mul()
+    .End()
+
+const bin = b.WebAssembly()
+bin.trim();
+testWasmModuleFunctions(bin.get(), 1,
+                        [[{ type: "i32", value: 0 }, [{ type: "i32", value: 0 }]],
+                         [{ type: "i32", value: 2 }, [{ type: "i32", value: 1 }]],
+                         [{ type: "i32", value: 200 }, [{ type: "i32", value: 100 }]],
+                         [{ type: "i32", value: -200 }, [{ type: "i32", value: -100 }]],
+                        ],
+                       );

Modified: trunk/Source/_javascript_Core/ChangeLog (209502 => 209503)


--- trunk/Source/_javascript_Core/ChangeLog	2016-12-08 01:08:48 UTC (rev 209502)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-12-08 01:13:40 UTC (rev 209503)
@@ -1,3 +1,19 @@
+2016-12-07  Keith Miller  <keith_mil...@apple.com>
+
+        Add more missing trivial wasm ops.
+        https://bugs.webkit.org/show_bug.cgi?id=165564
+
+        Reviewed by Geoffrey Garen.
+
+        This patch adds the nop, drop, and tee_local opcodes.
+        It also fixes an issue where we were not generating
+        the proper enums for the grow_memory and current_memory
+        opcodes.
+
+        * wasm/WasmFunctionParser.h:
+        (JSC::Wasm::FunctionParser<Context>::parseExpression):
+        * wasm/generateWasmOpsHeader.py:
+
 2016-12-07  Geoffrey Garen  <gga...@apple.com>
 
         Renamed source => parentSource

Modified: trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h (209502 => 209503)


--- trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h	2016-12-08 01:08:48 UTC (rev 209502)
+++ trunk/Source/_javascript_Core/wasm/WasmFunctionParser.h	2016-12-08 01:13:40 UTC (rev 209503)
@@ -336,6 +336,15 @@
         return m_context.setLocal(index, value);
     }
 
+    case OpType::TeeLocal: {
+        uint32_t index;
+        if (!parseVarUInt32(index))
+            return false;
+        if (!m_expressionStack.size())
+            return false;
+        return m_context.setLocal(index, m_expressionStack.last());
+    }
+
     case OpType::Call: {
         uint32_t functionIndex;
         if (!parseVarUInt32(functionIndex))
@@ -492,7 +501,24 @@
         return true;
     }
 
-    default: {
+    case OpType::Drop: {
+        if (!m_expressionStack.size()) {
+            setErrorMessage("Attempted to drop an _expression_ from an empty stack.");
+            return false;
+        }
+        m_expressionStack.takeLast();
+        return true;
+    }
+
+    case OpType::Nop: {
+        return true;
+    }
+
+    case OpType::GrowMemory:
+    case OpType::CurrentMemory:
+    case OpType::GetGlobal:
+    case OpType::SetGlobal:
+    case OpType::CallIndirect: {
         // FIXME: Not yet implemented.
         return false;
     }

Modified: trunk/Source/_javascript_Core/wasm/generateWasmOpsHeader.py (209502 => 209503)


--- trunk/Source/_javascript_Core/wasm/generateWasmOpsHeader.py	2016-12-08 01:08:48 UTC (rev 209502)
+++ trunk/Source/_javascript_Core/wasm/generateWasmOpsHeader.py	2016-12-08 01:13:40 UTC (rev 209503)
@@ -65,7 +65,7 @@
         inc += 1
 
 defines = ["#define FOR_EACH_WASM_SPECIAL_OP(macro)"]
-defines.extend([op for op in opcodeMacroizer(lambda op: op["category"] == "special" or op["category"] == "call")])
+defines.extend([op for op in opcodeMacroizer(lambda op: not (isUnary(op) or isBinary(op) or op["category"] == "control" or op["category"] == "memory"))])
 defines.append("\n\n#define FOR_EACH_WASM_CONTROL_FLOW_OP(macro)")
 defines.extend([op for op in opcodeMacroizer(lambda op: op["category"] == "control")])
 defines.append("\n\n#define FOR_EACH_WASM_SIMPLE_UNARY_OP(macro)")
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to