1 // Scaffolding for testing x86 Ion code generation patterns . See
2 // codegen-x64-test.js in this directory for more information.
4 load(libdir + "codegen-test-common.js");
6 // Note that Zydis disassembles x86 absolute addresses as relative, so
7 // the binary encoding and the text encoding may not correspond precisely.
9 // Absolute address (disp32) following the instruction mnemonic.
10 var ABS = `0x${HEXES}`;
12 // Absolute address (disp32) in the binary encoding.
13 var ABSADDR = `${HEX}{2} ${HEX}{2} ${HEX}{2} ${HEX}{2}`;
15 // End of prologue. The mov to eax is debug code, inserted by the register
16 // allocator to clobber eax before a move group.
19 b8 ef be ad de mov \\$0xDEADBEEF, %eax
22 // `.bp` because zydis chooses 'rbp' even on 32-bit systems
24 f3 0f 6f 45 ${HEX}{2} movdqux 0x${HEXES}\\(%.bp\\), %xmm0
27 // Start of epilogue. `.bp` for the same reason as above.
28 var x86_suffix = `5d pop %.bp`;
30 // v128 OP literal -> v128
31 // inputs: [[complete-opname, rhs-literal, expected-pattern], ...]
32 function codegenTestX86_v128xLITERAL_v128(inputs, options = {}) {
33 for ( let [op, literal, expected] of inputs ) {
34 codegenTestX86_adhoc(wrap(options, `
35 (func (export "f") (param v128) (result v128)
36 (${op} (local.get 0) ${literal}))`),
38 x86_loadarg0 + expected,
43 // For when nothing else applies: `module_text` is the complete source text of
44 // the module, `export_name` is the name of the function to be tested,
45 // `expected` is the non-preprocessed pattern, and options is an options bag,
47 function codegenTestX86_adhoc(module_text, export_name, expected, options = {}) {
48 assertEq(hasDisassembler(), true);
50 let ins = wasmEvalText(module_text);
51 let output = wasmDis(ins.exports[export_name], {tier:"ion", asString:true});
52 if (!options.no_prefix)
53 expected = x86_prefix + '\n' + expected;
54 if (!options.no_suffix)
55 expected = expected + '\n' + x86_suffix;
56 expected = fixlines(expected);
62 assertEq(output.match(new RegExp(expected)) != null, true);