Title: [290802] trunk
Revision
290802
Author
[email protected]
Date
2022-03-03 17:06:26 -0800 (Thu, 03 Mar 2022)

Log Message

[JSC] Update wasm branch hinting
https://bugs.webkit.org/show_bug.cgi?id=237411

Patch by Tom Tartarin <[email protected]> on 2022-03-03
Reviewed by Yusuke Suzuki.

JSTests:

Simplify the module tested with the updated format.

* wasm/branch-hints/branchHintsModule.wasm:
* wasm/branch-hints/branchHintsSection.js:

Source/_javascript_Core:

Change the section's name.
Clarify semantics in the parser.

* wasm/WasmBranchHintsSectionParser.cpp:
(JSC::Wasm::BranchHintsSectionParser::parse):
* wasm/WasmSectionParser.cpp:
(JSC::Wasm::SectionParser::parseCustom):

Modified Paths

Diff

Modified: trunk/JSTests/ChangeLog (290801 => 290802)


--- trunk/JSTests/ChangeLog	2022-03-04 01:04:39 UTC (rev 290801)
+++ trunk/JSTests/ChangeLog	2022-03-04 01:06:26 UTC (rev 290802)
@@ -1,3 +1,15 @@
+2022-03-03  Tom Tartarin  <[email protected]>
+
+        [JSC] Update wasm branch hinting
+        https://bugs.webkit.org/show_bug.cgi?id=237411
+
+        Reviewed by Yusuke Suzuki.
+
+        Simplify the module tested with the updated format.
+
+        * wasm/branch-hints/branchHintsModule.wasm:
+        * wasm/branch-hints/branchHintsSection.js:
+
 2022-02-25  Mark Lam  <[email protected]>
 
         operationMaterializeObjectInOSR should DeferTerminationForAWhile instead of just DeferTermination.

Modified: trunk/JSTests/wasm/branch-hints/branchHintsModule.wasm (290801 => 290802)


--- trunk/JSTests/wasm/branch-hints/branchHintsModule.wasm	2022-03-04 01:04:39 UTC (rev 290801)
+++ trunk/JSTests/wasm/branch-hints/branchHintsModule.wasm	2022-03-04 01:06:26 UTC (rev 290802)
@@ -1,4 +1,5 @@
-��asm������-`����``����p\x80	A\x80\x80\xC0��memory��_main��	��A������%code_annotation.branch_hint��%
-1����+A��"!@ AІF@A! Aj"A\xA0\x8DG-�� 
\ No newline at end of file
+��asm������`��_fun������#metadata.code.branch_hint����
+(&A
+" ��l"��A
+J@ ��@ ��A��L+�� �� 
\ No newline at end of file

Modified: trunk/JSTests/wasm/branch-hints/branchHintsSection.js (290801 => 290802)


--- trunk/JSTests/wasm/branch-hints/branchHintsSection.js	2022-03-04 01:04:39 UTC (rev 290801)
+++ trunk/JSTests/wasm/branch-hints/branchHintsSection.js	2022-03-04 01:06:26 UTC (rev 290802)
@@ -1,44 +1,36 @@
 import * as assert from '../assert.js'
 
 /*
-This test loads a WebAssembly file compiled with wat2wasm with support for code annotations.
-see: https://github.com/yuri91/wabt/tree/annotations
+This test loads a WebAssembly file compiled with wat2wasm with support for code annotations:
+wat2wasm --enable-annotations --enable-code-metadata branchHintsModule
 
 From the following .wat:
 (module
-  (type (;0;) (func))
-  (type (;1;) (func (param i32) (result i32)))
-  (type (;2;) (func (result i32)))
-  (func $__wasm_nullptr (type 0)
-    unreachable)
-  (func $main (type 2) (result i32)
-    (local i32 i32 i32 i32)
-    i32.const 0
-    local.tee 2
-    local.set 3
-    loop  ;; label = @1
-      local.get 2
-      i32.const 50000
-      i32.eq
-      (@code_annotation.branch_hint "\00") if  ;; label = @2
-        i32.const 1
-        local.set 3
-      end
-      local.get 2
-      i32.const 1
-      i32.add
-      local.tee 2
-      i32.const 100000
-      i32.ne
-      (@code_annotation.branch_hint "\01") br_if 0 (;@1;)
-    end
-    local.get 3)
-  (table (;0;) 1 1 funcref)
-  (memory (;0;) 17 128)
-  (global (;0;) (mut i32) (i32.const 1048576))
-  (export "memory" (memory 0))
-  (export "_main" (func $main))
-  (elem (;0;) (i32.const 0) func $__wasm_nullptr))
+  (func $fun (param i32) (result i32)
+        (local i32)
+        i32.const 10
+        local.tee 1
+        local.get 0
+        i32.mul
+        local.tee 0
+        i32.const 10
+        i32.gt_s
+        (@metadata.code.branch_hint "\01") if
+          local.get 0
+          return
+        end
+        (block
+          local.get 0
+          i32.const 0
+          i32.le_s
+          (@metadata.code.branch_hint "\00") br_if 0
+          local.get 0
+          return
+        )
+        local.get 1
+        return
+  )
+  (export "_fun" (func $fun)))
 */
 
 const verbose = false;
@@ -55,8 +47,11 @@
 };
 
 const branchHintsModule = module(wasmFile);
-const parsedBranchHintsSection = WebAssembly.Module.customSections(branchHintsModule, "code_annotation.branch_hint");
+const parsedBranchHintsSection = WebAssembly.Module.customSections(branchHintsModule, "metadata.code.branch_hint");
 assert.eq(parsedBranchHintsSection.length, 1);
 const instance = new WebAssembly.Instance(branchHintsModule);
-const result = instance.exports._main();
-assert.eq(result, 1);
+const fun = instance.exports._fun;
+assert.truthy(fun(-1));
+assert.truthy(fun(0));
+assert.truthy(fun(1));
+assert.truthy(fun(2));

Modified: trunk/Source/_javascript_Core/ChangeLog (290801 => 290802)


--- trunk/Source/_javascript_Core/ChangeLog	2022-03-04 01:04:39 UTC (rev 290801)
+++ trunk/Source/_javascript_Core/ChangeLog	2022-03-04 01:06:26 UTC (rev 290802)
@@ -1,3 +1,18 @@
+2022-03-03  Tom Tartarin  <[email protected]>
+
+        [JSC] Update wasm branch hinting
+        https://bugs.webkit.org/show_bug.cgi?id=237411
+
+        Reviewed by Yusuke Suzuki.
+
+        Change the section's name.
+        Clarify semantics in the parser.
+
+        * wasm/WasmBranchHintsSectionParser.cpp:
+        (JSC::Wasm::BranchHintsSectionParser::parse):
+        * wasm/WasmSectionParser.cpp:
+        (JSC::Wasm::SectionParser::parseCustom):
+
 2022-03-03  Saam Barati  <[email protected]>
 
         Add a DeferTraps scope

Modified: trunk/Source/_javascript_Core/wasm/WasmBranchHintsSectionParser.cpp (290801 => 290802)


--- trunk/Source/_javascript_Core/wasm/WasmBranchHintsSectionParser.cpp	2022-03-04 01:04:39 UTC (rev 290801)
+++ trunk/Source/_javascript_Core/wasm/WasmBranchHintsSectionParser.cpp	2022-03-04 01:06:26 UTC (rev 290802)
@@ -61,9 +61,9 @@
 
             previousBranchOffset = branchOffset;
 
-            uint8_t reservedByte;
-            WASM_PARSER_FAIL_IF(!parseVarUInt1(reservedByte), "can't get reserved byte for hint ", j);
-            WASM_PARSER_FAIL_IF(reservedByte != 0x1, "invalid reserved byte for hint ", j);
+            uint32_t payloadSize;
+            WASM_PARSER_FAIL_IF(!parseVarUInt32(payloadSize), "can't get payload size for hint ", j);
+            WASM_PARSER_FAIL_IF(payloadSize != 0x1, "invalid payload size for hint ", j);
 
             uint8_t parsedBranchHint;
             WASM_PARSER_FAIL_IF(!parseVarUInt1(parsedBranchHint), "can't get or invalid branch hint value for hint ", j);

Modified: trunk/Source/_javascript_Core/wasm/WasmSectionParser.cpp (290801 => 290802)


--- trunk/Source/_javascript_Core/wasm/WasmSectionParser.cpp	2022-03-04 01:04:39 UTC (rev 290801)
+++ trunk/Source/_javascript_Core/wasm/WasmSectionParser.cpp	2022-03-04 01:06:26 UTC (rev 290802)
@@ -898,7 +898,7 @@
         if (auto nameSection = nameSectionParser.parse())
             m_info->nameSection = WTFMove(*nameSection);
     } else if (Options::useWebAssemblyBranchHints()) {
-        Name branchHintsName = { 'c', 'o', 'd', 'e', '_', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '.', 'b', 'r', 'a', 'n', 'c', 'h', '_', 'h', 'i', 'n', 't' };
+        Name branchHintsName = { 'm', 'e', 't', 'a', 'd', 'a', 't', 'a', '.', 'c', 'o', 'd', 'e', '.', 'b', 'r', 'a', 'n', 'c', 'h', '_', 'h', 'i', 'n', 't' };
         if (section.name == branchHintsName) {
             BranchHintsSectionParser branchHintsSectionParser(section.payload.begin(), section.payload.size(), m_info);
             branchHintsSectionParser.parse();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to