Debian Codegraph @

js/src/jit-test/tests/wasm/branch-hinting/simple_example.js

raw
1 // Branch Hinting proposal
2
3 function runModule(hint) {
4 let code =`
5 (module
6 (func $$dummy)
7 (func $main (param i32) (result i32)
8 i32.const 0
9 local.get 0
10 i32.eq
11 ;; Only allowed on br_if and if
12 (@metadata.code.branch_hint "${hint}") if
13 call $$dummy
14 i32.const 1
15 return
16 else
17 call $$dummy
18 i32.const 0
19 return
20 end
21 i32.const 3
22 return
23 )
24 (export "_main" (func $main))
25 )`;
26 let branchHintsModule = new WebAssembly.Module(wasmTextToBinary(code));
27 assertEq(wasmParsedBranchHints(branchHintsModule), true);
28
29 let instance = new WebAssembly.Instance(branchHintsModule);
30 assertEq(instance.exports._main(0), 1);
31 }
32
33 // Ensure that we have the same result with different branch hints.
34 runModule("\\00");
35 runModule("\\01");
36
37 let module = new WebAssembly.Module(wasmTextToBinary(`
38 (func i32.const 0 (@metadata.code.branch_hint "\\00") if end)
39 `))
40
41 assertEq(wasmParsedBranchHints(module), true);
42
43 let deadCode = new WebAssembly.Module(wasmTextToBinary(`
44 (module
45 (func $main
46 i32.const 0
47 return
48 (@metadata.code.branch_hint "\\00") if
49 end
50 )
51 (export "_main" (func $main))
52 )`));
53
54 assertEq(wasmParsedBranchHints(deadCode), true);