Diff
Modified: trunk/JSTests/ChangeLog (209865 => 209866)
--- trunk/JSTests/ChangeLog 2016-12-15 18:37:18 UTC (rev 209865)
+++ trunk/JSTests/ChangeLog 2016-12-15 19:17:00 UTC (rev 209866)
@@ -1,3 +1,24 @@
+2016-12-15 Keith Miller <[email protected]>
+
+ Fix 64-bit shift family Wasm opcodes
+ https://bugs.webkit.org/show_bug.cgi?id=165902
+
+ Reviewed by Geoffrey Garen.
+
+ Add tests for shift family of instructions. Since
+ we can't generate i64 values to pass to wasm we only compile
+ the code for those functions. Attempting to generate any i64
+ code using these instructions would have been enough to cause
+ the B3 Validation error anyway.
+
+ * wasm/assert.js:
+ * wasm/function-tests/rotl.js: Added.
+ * wasm/function-tests/rotr.js: Added.
+ * wasm/function-tests/shl.js: Added.
+ * wasm/function-tests/shr-s.js: Added.
+ * wasm/function-tests/shr-u.js: Added.
+ * wasm/wasm.json:
+
2016-12-14 Keith Miller <[email protected]>
WebAssembly: test_BuilderJSON.js is broken
Modified: trunk/JSTests/wasm/assert.js (209865 => 209866)
--- trunk/JSTests/wasm/assert.js 2016-12-15 18:37:18 UTC (rev 209865)
+++ trunk/JSTests/wasm/assert.js 2016-12-15 19:17:00 UTC (rev 209866)
@@ -79,6 +79,16 @@
_fail(`Not the same: "${lhs}" and "${rhs}"`, msg);
};
+const canonicalizeI32 = (number) => {
+ if (Math.round(number) === number && number >= 2 ** 31)
+ number = number - 2 ** 32;
+ return number;
+}
+
+export const eqI32 = (lhs, rhs, msg) => {
+ return eq(canonicalizeI32(lhs), canonicalizeI32(rhs), msg);
+};
+
export const ge = (lhs, rhs, msg) => {
isNotUndef(lhs);
isNotUndef(rhs);
Added: trunk/JSTests/wasm/function-tests/rotl.js (0 => 209866)
--- trunk/JSTests/wasm/function-tests/rotl.js (rev 0)
+++ trunk/JSTests/wasm/function-tests/rotl.js 2016-12-15 19:17:00 UTC (rev 209866)
@@ -0,0 +1,32 @@
+import * as assert from '../assert.js';
+import Builder from '../Builder.js';
+
+const builder = (new Builder())
+ .Type().End()
+ .Function().End()
+ .Export()
+ .Function("i32Rotl")
+ .Function("i64Rotl")
+ .End()
+ .Code()
+ .Function("i32Rotl", { params: ["i32", "i32"], ret: "i32" })
+ .GetLocal(0)
+ .GetLocal(1)
+ .I32Rotl()
+ .End()
+
+ .Function("i64Rotl", { params: ["i64", "i64"], ret: "i64" })
+ .GetLocal(0)
+ .GetLocal(1)
+ .I64Rotl()
+ .End()
+
+ .End();
+
+const bin = builder.WebAssembly().get();
+const module = new WebAssembly.Module(bin);
+const instance = new WebAssembly.Instance(module);
+assert.eqI32(instance.exports.i32Rotl(1, 1), 2);
+assert.eqI32(instance.exports.i32Rotl(1, 2), 4);
+assert.eqI32(instance.exports.i32Rotl(0xf, 2), 0x3c);
+assert.eqI32(instance.exports.i32Rotl(0xf0000000, 1), 0xe0000001);
Added: trunk/JSTests/wasm/function-tests/rotr.js (0 => 209866)
--- trunk/JSTests/wasm/function-tests/rotr.js (rev 0)
+++ trunk/JSTests/wasm/function-tests/rotr.js 2016-12-15 19:17:00 UTC (rev 209866)
@@ -0,0 +1,31 @@
+import * as assert from '../assert.js';
+import Builder from '../Builder.js';
+
+const builder = (new Builder())
+ .Type().End()
+ .Function().End()
+ .Export()
+ .Function("i32Rotr")
+ .Function("i64Rotr")
+ .End()
+ .Code()
+ .Function("i32Rotr", { params: ["i32", "i32"], ret: "i32" })
+ .GetLocal(0)
+ .GetLocal(1)
+ .I32Rotr()
+ .End()
+
+ .Function("i64Rotr", { params: ["i64", "i64"], ret: "i64" })
+ .GetLocal(0)
+ .GetLocal(1)
+ .I64Rotr()
+ .End()
+
+ .End();
+
+const bin = builder.WebAssembly().get();
+const module = new WebAssembly.Module(bin);
+const instance = new WebAssembly.Instance(module);
+assert.eqI32(instance.exports.i32Rotr(1, 1), 0x80000000);
+assert.eqI32(instance.exports.i32Rotr(1, 2), 0x40000000);
+assert.eqI32(instance.exports.i32Rotr(0xf, 2), 0xc0000003);
Added: trunk/JSTests/wasm/function-tests/shl.js (0 => 209866)
--- trunk/JSTests/wasm/function-tests/shl.js (rev 0)
+++ trunk/JSTests/wasm/function-tests/shl.js 2016-12-15 19:17:00 UTC (rev 209866)
@@ -0,0 +1,32 @@
+import * as assert from '../assert.js';
+import Builder from '../Builder.js';
+
+const builder = (new Builder())
+ .Type().End()
+ .Function().End()
+ .Export()
+ .Function("i32Shl")
+ .Function("i64Shl")
+ .End()
+ .Code()
+ .Function("i32Shl", { params: ["i32", "i32"], ret: "i32" })
+ .GetLocal(0)
+ .GetLocal(1)
+ .I32Shl()
+ .End()
+
+ .Function("i64Shl", { params: ["i64", "i64"], ret: "i64" })
+ .GetLocal(0)
+ .GetLocal(1)
+ .I64Shl()
+ .End()
+
+ .End();
+
+const bin = builder.WebAssembly().get();
+const module = new WebAssembly.Module(bin);
+const instance = new WebAssembly.Instance(module);
+assert.eqI32(instance.exports.i32Shl(1, 1), 2);
+assert.eqI32(instance.exports.i32Shl(1, 2), 4);
+assert.eqI32(instance.exports.i32Shl(0xf, 2), 0x3c);
+assert.eqI32(instance.exports.i32Shl(0xf0000000, 1), 0xe0000000);
Added: trunk/JSTests/wasm/function-tests/shr-s.js (0 => 209866)
--- trunk/JSTests/wasm/function-tests/shr-s.js (rev 0)
+++ trunk/JSTests/wasm/function-tests/shr-s.js 2016-12-15 19:17:00 UTC (rev 209866)
@@ -0,0 +1,32 @@
+import * as assert from '../assert.js';
+import Builder from '../Builder.js';
+
+const builder = (new Builder())
+ .Type().End()
+ .Function().End()
+ .Export()
+ .Function("i32ShrS")
+ .Function("i64ShrS")
+ .End()
+ .Code()
+ .Function("i32ShrS", { params: ["i32", "i32"], ret: "i32" })
+ .GetLocal(0)
+ .GetLocal(1)
+ .I32ShrS()
+ .End()
+
+ .Function("i64ShrS", { params: ["i64", "i64"], ret: "i64" })
+ .GetLocal(0)
+ .GetLocal(1)
+ .I64ShrS()
+ .End()
+
+ .End();
+
+const bin = builder.WebAssembly().get();
+const module = new WebAssembly.Module(bin);
+const instance = new WebAssembly.Instance(module);
+assert.eqI32(instance.exports.i32ShrS(1, 1), 0);
+assert.eqI32(instance.exports.i32ShrS(1, 2), 0);
+assert.eqI32(instance.exports.i32ShrS(0xf, 2), 0x3);
+assert.eqI32(instance.exports.i32ShrS(0xf0000000, 1), 0xf8000000);
Added: trunk/JSTests/wasm/function-tests/shr-u.js (0 => 209866)
--- trunk/JSTests/wasm/function-tests/shr-u.js (rev 0)
+++ trunk/JSTests/wasm/function-tests/shr-u.js 2016-12-15 19:17:00 UTC (rev 209866)
@@ -0,0 +1,32 @@
+import * as assert from '../assert.js';
+import Builder from '../Builder.js';
+
+const builder = (new Builder())
+ .Type().End()
+ .Function().End()
+ .Export()
+ .Function("i32ShrU")
+ .Function("i64ShrU")
+ .End()
+ .Code()
+ .Function("i32ShrU", { params: ["i32", "i32"], ret: "i32" })
+ .GetLocal(0)
+ .GetLocal(1)
+ .I32ShrU()
+ .End()
+
+ .Function("i64ShrU", { params: ["i64", "i64"], ret: "i64" })
+ .GetLocal(0)
+ .GetLocal(1)
+ .I64ShrU()
+ .End()
+
+ .End();
+
+const bin = builder.WebAssembly().get();
+const module = new WebAssembly.Module(bin);
+const instance = new WebAssembly.Instance(module);
+assert.eqI32(instance.exports.i32ShrU(1, 1), 0);
+assert.eqI32(instance.exports.i32ShrU(1, 2), 0);
+assert.eqI32(instance.exports.i32ShrU(0xf, 2), 0x3);
+assert.eqI32(instance.exports.i32ShrU(0xf0000000, 1), 0x78000000);
Modified: trunk/JSTests/wasm/wasm.json (209865 => 209866)
--- trunk/JSTests/wasm/wasm.json 2016-12-15 18:37:18 UTC (rev 209865)
+++ trunk/JSTests/wasm/wasm.json 2016-12-15 19:17:00 UTC (rev 209866)
@@ -101,8 +101,8 @@
"i32.or": { "category": "arithmetic", "value": 114, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "BitOr" },
"i32.xor": { "category": "arithmetic", "value": 115, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "BitXor" },
"i32.shl": { "category": "arithmetic", "value": 116, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "Shl" },
- "i32.shr_u": { "category": "arithmetic", "value": 118, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "SShr" },
- "i32.shr_s": { "category": "arithmetic", "value": 117, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "ZShr" },
+ "i32.shr_u": { "category": "arithmetic", "value": 118, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "ZShr" },
+ "i32.shr_s": { "category": "arithmetic", "value": 117, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "SShr" },
"i32.rotr": { "category": "arithmetic", "value": 120, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "RotR" },
"i32.rotl": { "category": "arithmetic", "value": 119, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "RotL" },
"i32.eq": { "category": "comparison", "value": 70, "return": ["bool"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "Equal" },
@@ -129,11 +129,11 @@
"i64.and": { "category": "arithmetic", "value": 131, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "BitAnd" },
"i64.or": { "category": "arithmetic", "value": 132, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "BitOr" },
"i64.xor": { "category": "arithmetic", "value": 133, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "BitXor" },
- "i64.shl": { "category": "arithmetic", "value": 134, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "Shl" },
- "i64.shr_u": { "category": "arithmetic", "value": 136, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "SShr" },
- "i64.shr_s": { "category": "arithmetic", "value": 135, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "ZShr" },
- "i64.rotr": { "category": "arithmetic", "value": 138, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "RotR" },
- "i64.rotl": { "category": "arithmetic", "value": 137, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "RotL" },
+ "i64.shl": { "category": "arithmetic", "value": 134, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "Shl(@0, Trunc(@1))" },
+ "i64.shr_u": { "category": "arithmetic", "value": 136, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "ZShr(@0, Trunc(@1))" },
+ "i64.shr_s": { "category": "arithmetic", "value": 135, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "SShr(@0, Trunc(@1))" },
+ "i64.rotr": { "category": "arithmetic", "value": 138, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "RotR(@0, Trunc(@1))" },
+ "i64.rotl": { "category": "arithmetic", "value": 137, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "RotL(@0, Trunc(@1))" },
"i64.eq": { "category": "comparison", "value": 81, "return": ["bool"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "Equal" },
"i64.ne": { "category": "comparison", "value": 82, "return": ["bool"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "NotEqual" },
"i64.lt_s": { "category": "comparison", "value": 83, "return": ["bool"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "LessThan" },
Modified: trunk/Source/_javascript_Core/ChangeLog (209865 => 209866)
--- trunk/Source/_javascript_Core/ChangeLog 2016-12-15 18:37:18 UTC (rev 209865)
+++ trunk/Source/_javascript_Core/ChangeLog 2016-12-15 19:17:00 UTC (rev 209866)
@@ -1,3 +1,17 @@
+2016-12-15 Keith Miller <[email protected]>
+
+ Fix 64-bit shift family Wasm opcodes
+ https://bugs.webkit.org/show_bug.cgi?id=165902
+
+ Reviewed by Geoffrey Garen.
+
+ The Int64 versions of the shift family B3 opcodes take an Int32
+ for the shift value. Wasm, however, takes an i64, so we need to
+ Trunc the shift value. Also, this fixes a bug where shr_u mapped
+ to signed shift and shr_s mapped to the unsigned shift.
+
+ * wasm/wasm.json:
+
2016-12-14 Keith Miller <[email protected]>
Wasm should decode constants correctly
Modified: trunk/Source/_javascript_Core/wasm/wasm.json (209865 => 209866)
--- trunk/Source/_javascript_Core/wasm/wasm.json 2016-12-15 18:37:18 UTC (rev 209865)
+++ trunk/Source/_javascript_Core/wasm/wasm.json 2016-12-15 19:17:00 UTC (rev 209866)
@@ -101,8 +101,8 @@
"i32.or": { "category": "arithmetic", "value": 114, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "BitOr" },
"i32.xor": { "category": "arithmetic", "value": 115, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "BitXor" },
"i32.shl": { "category": "arithmetic", "value": 116, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "Shl" },
- "i32.shr_u": { "category": "arithmetic", "value": 118, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "SShr" },
- "i32.shr_s": { "category": "arithmetic", "value": 117, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "ZShr" },
+ "i32.shr_u": { "category": "arithmetic", "value": 118, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "ZShr" },
+ "i32.shr_s": { "category": "arithmetic", "value": 117, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "SShr" },
"i32.rotr": { "category": "arithmetic", "value": 120, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "RotR" },
"i32.rotl": { "category": "arithmetic", "value": 119, "return": ["i32"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "RotL" },
"i32.eq": { "category": "comparison", "value": 70, "return": ["bool"], "parameter": ["i32", "i32"], "immediate": [], "b3op": "Equal" },
@@ -129,11 +129,11 @@
"i64.and": { "category": "arithmetic", "value": 131, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "BitAnd" },
"i64.or": { "category": "arithmetic", "value": 132, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "BitOr" },
"i64.xor": { "category": "arithmetic", "value": 133, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "BitXor" },
- "i64.shl": { "category": "arithmetic", "value": 134, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "Shl" },
- "i64.shr_u": { "category": "arithmetic", "value": 136, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "SShr" },
- "i64.shr_s": { "category": "arithmetic", "value": 135, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "ZShr" },
- "i64.rotr": { "category": "arithmetic", "value": 138, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "RotR" },
- "i64.rotl": { "category": "arithmetic", "value": 137, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "RotL" },
+ "i64.shl": { "category": "arithmetic", "value": 134, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "Shl(@0, Trunc(@1))" },
+ "i64.shr_u": { "category": "arithmetic", "value": 136, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "ZShr(@0, Trunc(@1))" },
+ "i64.shr_s": { "category": "arithmetic", "value": 135, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "SShr(@0, Trunc(@1))" },
+ "i64.rotr": { "category": "arithmetic", "value": 138, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "RotR(@0, Trunc(@1))" },
+ "i64.rotl": { "category": "arithmetic", "value": 137, "return": ["i64"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "RotL(@0, Trunc(@1))" },
"i64.eq": { "category": "comparison", "value": 81, "return": ["bool"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "Equal" },
"i64.ne": { "category": "comparison", "value": 82, "return": ["bool"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "NotEqual" },
"i64.lt_s": { "category": "comparison", "value": 83, "return": ["bool"], "parameter": ["i64", "i64"], "immediate": [], "b3op": "LessThan" },