Debian Codegraph @

js/src/jit-test/lib/codegen-x86-test.js

raw
1 // Scaffolding for testing x86 Ion code generation patterns . See
2 // codegen-x64-test.js in this directory for more information.
3
4 load(libdir + "codegen-test-common.js");
5
6 // Note that Zydis disassembles x86 absolute addresses as relative, so
7 // the binary encoding and the text encoding may not correspond precisely.
8
9 // Absolute address (disp32) following the instruction mnemonic.
10 var ABS = `0x${HEXES}`;
11
12 // Absolute address (disp32) in the binary encoding.
13 var ABSADDR = `${HEX}{2} ${HEX}{2} ${HEX}{2} ${HEX}{2}`;
14
15 // End of prologue. The move from esi to rbp is writing the callee's wasm
16 // instance into the frame for debug checks -- see WasmFrame.h. The mov to eax
17 // is debug code, inserted by the register allocator to clobber eax before a
18 // move group. But it is only present if there is a move group there.
19 //
20 // -0x21524111 is 0xDEADBEEF.
21 var x86_prefix = `
22 8b ec mov %esp, %ebp(
23 89 75 08 movl %esi, 0x08\\(%rbp\\))?(
24 b8 ef be ad de mov \\$-0x21524111, %eax)?
25 `
26
27 // `.bp` because zydis chooses 'rbp' even on 32-bit systems
28 var x86_loadarg0 = `
29 f3 0f 6f 45 ${HEX}{2} movdqux 0x${HEXES}\\(%.bp\\), %xmm0
30 `;
31
32 // Start of epilogue. `.bp` for the same reason as above.
33 var x86_suffix = `5d pop %.bp`;
34
35 // v128 OP literal -> v128
36 // inputs: [[complete-opname, rhs-literal, expected-pattern], ...]
37 function codegenTestX86_v128xLITERAL_v128(inputs, options = {}) {
38 for ( let [op, literal, expected] of inputs ) {
39 codegenTestX86_adhoc(wrap(options, `
40 (func (export "f") (param v128) (result v128)
41 (${op} (local.get 0) ${literal}))`),
42 'f',
43 x86_loadarg0 + expected,
44 options)
45 }
46 }
47
48 // For when nothing else applies: `module_text` is the complete source text of
49 // the module, `export_name` is the name of the function to be tested,
50 // `expected` is the non-preprocessed pattern, and options is an options bag,
51 // described above.
52 function codegenTestX86_adhoc(module_text, export_name, expected, options = {}) {
53 assertEq(hasDisassembler(), true);
54
55 let ins = wasmEvalText(module_text);
56 let output = wasmDis(ins.exports[export_name], {tier:"ion", asString:true});
57
58 const expected_initial = expected;
59 if (!options.no_prefix)
60 expected = x86_prefix + '\n' + expected;
61 if (!options.no_suffix)
62 expected = expected + '\n' + x86_suffix;
63 expected = fixlines(expected);
64
65 const output_matches_expected = output.match(new RegExp(expected)) != null;
66 if (!output_matches_expected) {
67 print("---- codegen-x86-test.js: TEST FAILED ----");
68 }
69 if (options.log && output_matches_expected) {
70 print("---- codegen-x86-test.js: TEST PASSED ----");
71 }
72 if (options.log || !output_matches_expected) {
73 print("---- module text");
74 print(module_text);
75 print("---- actual");
76 print(output);
77 print("---- expected (initial)");
78 print(expected_initial);
79 print("---- expected (as used)");
80 print(expected);
81 print("----");
82 }
83
84 assertEq(output_matches_expected, true);
85 }
86