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/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();