Bug 1466464 - Part 1: Recognize memory.grow and memory.size syntax. r=jseward
authorLars T Hansen <lhansen@mozilla.com>
Thu, 28 Jun 2018 10:44:54 +0200
changeset 424381 b6406d11016d5a5167ca7de3271a76f4590cd5a6
parent 424380 d6120c2bb51e2057df51f4d52510bb5f4e8b4ca5
child 424382 f2f1f75b91343ccfc0b298a5cc634c487202148f
push id34203
push userebalazs@mozilla.com
push dateFri, 29 Jun 2018 09:42:22 +0000
treeherdermozilla-central@bf149090f6b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjseward
bugs1466464
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1466464 - Part 1: Recognize memory.grow and memory.size syntax. r=jseward This only recognizes the new syntax and adds a minimal amount of testing for that. A subsequent patch will do a massive renaming in the wasm module to change CurrentMemory to MemSize and GrowMemory to MemGrow, and change all test cases. A final patch will remove support for the old syntax.
js/src/jit-test/tests/wasm/grow-memory.js
js/src/wasm/WasmTextToBinary.cpp
--- a/js/src/jit-test/tests/wasm/grow-memory.js
+++ b/js/src/jit-test/tests/wasm/grow-memory.js
@@ -1,16 +1,16 @@
-function linearModule(min, max, ops) {
+function linearModule(min, max, ops, current_memory, grow_memory) {
   var opsText = ops.map(function (op) {
     if (op[0] == "CM") {
-      res = `(if i32 (i32.ne (current_memory) (i32.const ${op[1]}))
+      res = `(if i32 (i32.ne (${current_memory}) (i32.const ${op[1]}))
                   (i32.load offset=10 (i32.const 4294967295))
                   (i32.const 0))`
     } else if (op[0] == "GM") {
-      res = `(if i32 (i32.ne (grow_memory (i32.const ${op[1]})) (i32.const ${op[2]}))
+      res = `(if i32 (i32.ne (${grow_memory} (i32.const ${op[1]})) (i32.const ${op[2]}))
                  (i32.load offset=10 (i32.const 4294967295))
                  (i32.const 0))`
     } else if (op[0] == "L") {
       var type = op[1];
       var ext = op[2];
       var off = op[3];
       var loc = op[4]
       var align = 0;
@@ -30,16 +30,17 @@ function linearModule(min, max, ops) {
     `(module
        (memory ${min} ${max})
          ` + (min != 0 ? `(data (i32.const 0) "\\00\\01\\02\\03\\04\\05\\06\\07\\08\\09\\0a\\0b\\0c\\0d\\0e\\0f")
                           (data (i32.const 16) "\\f0\\f1\\f2\\f3\\f4\\f5\\f6\\f7\\f8\\f9\\fa\\fb\\fc\\fd\\fe\\ff")`
                       : "") +
        `
        (func (result i32)
          (drop ` + opsText + `)
-         (current_memory)
+         (${current_memory})
        ) (export "run" 0))`;
 
   return text;
 }
 
 // Just grow some memory
-wasmFullPass(linearModule(3,5, [["CM", 3]]), 3);
+wasmFullPass(linearModule(3,5, [["CM", 3]], "current_memory", "grow_memory"), 3); // Old opcode names
+wasmFullPass(linearModule(3,5, [["CM", 3]], "memory.size", "memory.grow"), 3);    // New opcode names
--- a/js/src/wasm/WasmTextToBinary.cpp
+++ b/js/src/wasm/WasmTextToBinary.cpp
@@ -1651,25 +1651,29 @@ WasmTokenStream::next()
       case 'l':
         if (consume(u"local"))
             return WasmToken(WasmToken::Local, begin, cur_);
         if (consume(u"loop"))
             return WasmToken(WasmToken::Loop, begin, cur_);
         break;
 
       case 'm':
+        if (consume(u"memory.")) {
 #ifdef ENABLE_WASM_BULKMEM_OPS
-        if (consume(u"memory.")) {
             if (consume(u"copy"))
                 return WasmToken(WasmToken::MemCopy, begin, cur_);
             if (consume(u"fill"))
                 return WasmToken(WasmToken::MemFill, begin, cur_);
+#endif
+            if (consume(u"grow"))
+                return WasmToken(WasmToken::GrowMemory, begin, cur_);
+            if (consume(u"size"))
+                return WasmToken(WasmToken::CurrentMemory, begin, cur_);
             break;
         }
-#endif
         if (consume(u"module"))
             return WasmToken(WasmToken::Module, begin, cur_);
         if (consume(u"memory"))
             return WasmToken(WasmToken::Memory, begin, cur_);
         if (consume(u"mut"))
             return WasmToken(WasmToken::Mutable, begin, cur_);
         break;