WebAssembly: Some loads don't take into account the offset
authorsbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jan 2017 00:32:05 +0000 (00:32 +0000)
committersbarati@apple.com <sbarati@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Jan 2017 00:32:05 +0000 (00:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=166616
<rdar://problem/29841541>

Reviewed by Keith Miller.

JSTests:

* wasm/function-tests/load-offset.js: Added.

Source/JavaScriptCore:

* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::emitLoadOp):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@210228 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JSTests/ChangeLog
JSTests/wasm.yaml
JSTests/wasm/function-tests/load-offset.js [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp

index 00fd498..93cd6b8 100644 (file)
@@ -1,3 +1,13 @@
+2017-01-02  Saam Barati  <sbarati@apple.com>
+
+        WebAssembly: Some loads don't take into account the offset
+        https://bugs.webkit.org/show_bug.cgi?id=166616
+        <rdar://problem/29841541>
+
+        Reviewed by Keith Miller.
+
+        * wasm/function-tests/load-offset.js: Added.
+
 2016-12-29  Saam Barati  <sbarati@apple.com>
 
         WebAssembly: Rebase spec-tests now that wabt has been updated to produce certain kinds of invalid modules
index 76dc1b2..77fd443 100644 (file)
   cmd: runWebAssemblySpecTest :skip
 
 - path: wasm/spec-tests/nop.wast.js
-  cmd: runWebAssemblySpecTest :skip
+  cmd: runWebAssemblySpecTest :normal
 
 - path: wasm/spec-tests/resizing.wast.js
-  cmd: runWebAssemblySpecTest :skip
+  cmd: runWebAssemblySpecTest :normal
 
 - path: wasm/spec-tests/return.wast.js
   cmd: runWebAssemblySpecTest :normal
diff --git a/JSTests/wasm/function-tests/load-offset.js b/JSTests/wasm/function-tests/load-offset.js
new file mode 100644 (file)
index 0000000..7419a19
--- /dev/null
@@ -0,0 +1,165 @@
+import Builder from '../Builder.js'
+import * as assert from '../assert.js'
+
+{
+    const builder = (new Builder())
+        .Type().End()
+        .Import()
+            .Memory("imp", "mem", {initial: 1})
+        .End()
+        .Function().End()
+        .Export().Function("foo").End()
+        .Code()
+            .Function("foo", {params: ["i32"], ret: "i32"})
+                .GetLocal(0)
+                .I32Load(2, 4)
+                .Return()
+            .End()
+        .End();
+
+    const bin = builder.WebAssembly().get();
+    const module = new WebAssembly.Module(bin);
+    const memory = new WebAssembly.Memory({initial: 1});
+    const instance = new WebAssembly.Instance(module, {imp: {mem: memory}});
+    
+    const number = 0x0abbccdd;
+    (new Uint32Array(memory.buffer))[1] = number;
+    assert.eq(instance.exports.foo(0), number);
+}
+
+{
+    const builder = (new Builder())
+        .Type().End()
+        .Import()
+            .Memory("imp", "mem", {initial: 1})
+        .End()
+        .Function().End()
+        .Export().Function("foo").End()
+        .Code()
+            .Function("foo", {params: ["i32"], ret: "i32"})
+                .GetLocal(0)
+                .I64Load32U(2, 4)
+                .I64Popcnt()
+                .I32WrapI64()
+                .Return()
+            .End()
+        .End();
+
+    const bin = builder.WebAssembly().get();
+    const module = new WebAssembly.Module(bin);
+    const memory = new WebAssembly.Memory({initial: 1});
+    const instance = new WebAssembly.Instance(module, {imp: {mem: memory}});
+    
+    const number = 2**32 - 1;
+    (new Uint32Array(memory.buffer))[1] = number;
+    assert.eq(instance.exports.foo(0), 32);
+}
+
+{
+    const builder = (new Builder())
+        .Type().End()
+        .Import()
+            .Memory("imp", "mem", {initial: 1})
+        .End()
+        .Function().End()
+        .Export().Function("foo").End()
+        .Code()
+            .Function("foo", {params: ["i32"], ret: "i32"})
+                .GetLocal(0)
+                .I64Load32S(2, 4)
+                .I64Popcnt()
+                .I32WrapI64()
+                .Return()
+            .End()
+        .End();
+
+    const bin = builder.WebAssembly().get();
+    const module = new WebAssembly.Module(bin);
+    const memory = new WebAssembly.Memory({initial: 1});
+    const instance = new WebAssembly.Instance(module, {imp: {mem: memory}});
+    
+    const number = 2**32 - 1;
+    (new Uint32Array(memory.buffer))[1] = number;
+    assert.eq(instance.exports.foo(0), 64);
+}
+
+{
+    const builder = (new Builder())
+        .Type().End()
+        .Import()
+            .Memory("imp", "mem", {initial: 1})
+        .End()
+        .Function().End()
+        .Export().Function("foo").End()
+        .Code()
+            .Function("foo", {params: ["i32"], ret: "i32"})
+                .GetLocal(0)
+                .I64Load(2, 4)
+                .I64Popcnt()
+                .I32WrapI64()
+                .Return()
+            .End()
+        .End();
+
+    const bin = builder.WebAssembly().get();
+    const module = new WebAssembly.Module(bin);
+    const memory = new WebAssembly.Memory({initial: 1});
+    const instance = new WebAssembly.Instance(module, {imp: {mem: memory}});
+    
+    const number = 2**32 - 1;
+    (new Uint32Array(memory.buffer))[1] = number;
+    (new Uint32Array(memory.buffer))[2] = 0xff00ff00;
+    assert.eq(instance.exports.foo(0), 32 + 16);
+}
+
+{
+    const builder = (new Builder())
+        .Type().End()
+        .Import()
+            .Memory("imp", "mem", {initial: 1})
+        .End()
+        .Function().End()
+        .Export().Function("foo").End()
+        .Code()
+            .Function("foo", {params: ["i32"], ret: "f32"})
+                .GetLocal(0)
+                .F32Load(2, 4)
+                .Return()
+            .End()
+        .End();
+
+    const bin = builder.WebAssembly().get();
+    const module = new WebAssembly.Module(bin);
+    const memory = new WebAssembly.Memory({initial: 1});
+    const instance = new WebAssembly.Instance(module, {imp: {mem: memory}});
+    
+    const number = Math.PI;
+    (new Float32Array(memory.buffer))[1] = number;
+    assert.eq(instance.exports.foo(0), Math.fround(number));
+}
+
+{
+    const builder = (new Builder())
+        .Type().End()
+        .Import()
+            .Memory("imp", "mem", {initial: 1})
+        .End()
+        .Function().End()
+        .Export().Function("foo").End()
+        .Code()
+            .Function("foo", {params: ["i32"], ret: "f64"})
+                .GetLocal(0)
+                .F64Load(2, 8)
+                .Return()
+            .End()
+        .End();
+
+    const bin = builder.WebAssembly().get();
+    const module = new WebAssembly.Module(bin);
+    const memory = new WebAssembly.Memory({initial: 1});
+    const instance = new WebAssembly.Instance(module, {imp: {mem: memory}});
+    
+    const number = Math.PI;
+    (new Float64Array(memory.buffer))[1] = number;
+    assert.eq(instance.exports.foo(0), number);
+}
index 6926696..8253d65 100644 (file)
@@ -1,3 +1,14 @@
+2017-01-02  Saam Barati  <sbarati@apple.com>
+
+        WebAssembly: Some loads don't take into account the offset
+        https://bugs.webkit.org/show_bug.cgi?id=166616
+        <rdar://problem/29841541>
+
+        Reviewed by Keith Miller.
+
+        * wasm/WasmB3IRGenerator.cpp:
+        (JSC::Wasm::B3IRGenerator::emitLoadOp):
+
 2017-01-01  Jeff Miller  <jeffm@apple.com>
 
         Update user-visible copyright strings to include 2017
index 117d764..3c2562b 100644 (file)
@@ -514,29 +514,29 @@ inline Value* B3IRGenerator::emitLoadOp(LoadOpType op, Origin origin, Expression
     }
 
     case LoadOpType::I32Load: {
-        return m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int32, origin, pointer);
+        return m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int32, origin, pointer, offset);
     }
 
     case LoadOpType::I64Load32U: {
-        Value* value = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int32, origin, pointer);
+        Value* value = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int32, origin, pointer, offset);
         return m_currentBlock->appendNew<Value>(m_proc, ZExt32, origin, value);
     }
 
     case LoadOpType::I64Load32S: {
-        Value* value = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int32, origin, pointer);
+        Value* value = m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int32, origin, pointer, offset);
         return m_currentBlock->appendNew<Value>(m_proc, SExt32, origin, value);
     }
 
     case LoadOpType::I64Load: {
-        return m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int64, origin, pointer);
+        return m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Int64, origin, pointer, offset);
     }
 
     case LoadOpType::F32Load: {
-        return m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Float, origin, pointer);
+        return m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Float, origin, pointer, offset);
     }
 
     case LoadOpType::F64Load: {
-        return m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Double, origin, pointer);
+        return m_currentBlock->appendNew<MemoryValue>(m_proc, Load, Double, origin, pointer, offset);
     }
 
     // FIXME: B3 doesn't support Load16Z yet. We should lower to that value when