summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/lib/codegen-x86-test.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/lib/codegen-x86-test.js')
-rw-r--r--js/src/jit-test/lib/codegen-x86-test.js65
1 files changed, 65 insertions, 0 deletions
diff --git a/js/src/jit-test/lib/codegen-x86-test.js b/js/src/jit-test/lib/codegen-x86-test.js
new file mode 100644
index 0000000000..b41749e0af
--- /dev/null
+++ b/js/src/jit-test/lib/codegen-x86-test.js
@@ -0,0 +1,65 @@
+// Scaffolding for testing x86 Ion code generation patterns . See
+// codegen-x64-test.js in this directory for more information.
+
+load(libdir + "codegen-test-common.js");
+
+// Note that Zydis disassembles x86 absolute addresses as relative, so
+// the binary encoding and the text encoding may not correspond precisely.
+
+// Absolute address (disp32) following the instruction mnemonic.
+var ABS = `0x${HEXES}`;
+
+// Absolute address (disp32) in the binary encoding.
+var ABSADDR = `${HEX}{2} ${HEX}{2} ${HEX}{2} ${HEX}{2}`;
+
+// End of prologue. The mov to eax is debug code, inserted by the register
+// allocator to clobber eax before a move group. But it is only present if
+// there is a move group there.
+var x86_prefix = `
+8b ec mov %esp, %ebp(
+b8 ef be ad de mov \\$0xDEADBEEF, %eax)?
+`
+
+// `.bp` because zydis chooses 'rbp' even on 32-bit systems
+var x86_loadarg0 = `
+f3 0f 6f 45 ${HEX}{2} movdqux 0x${HEXES}\\(%.bp\\), %xmm0
+`;
+
+// Start of epilogue. `.bp` for the same reason as above.
+var x86_suffix = `5d pop %.bp`;
+
+// v128 OP literal -> v128
+// inputs: [[complete-opname, rhs-literal, expected-pattern], ...]
+function codegenTestX86_v128xLITERAL_v128(inputs, options = {}) {
+ for ( let [op, literal, expected] of inputs ) {
+ codegenTestX86_adhoc(wrap(options, `
+ (func (export "f") (param v128) (result v128)
+ (${op} (local.get 0) ${literal}))`),
+ 'f',
+ x86_loadarg0 + expected,
+ options)
+ }
+}
+
+// For when nothing else applies: `module_text` is the complete source text of
+// the module, `export_name` is the name of the function to be tested,
+// `expected` is the non-preprocessed pattern, and options is an options bag,
+// described above.
+function codegenTestX86_adhoc(module_text, export_name, expected, options = {}) {
+ assertEq(hasDisassembler(), true);
+
+ let ins = wasmEvalText(module_text);
+ let output = wasmDis(ins.exports[export_name], {tier:"ion", asString:true});
+ if (!options.no_prefix)
+ expected = x86_prefix + '\n' + expected;
+ if (!options.no_suffix)
+ expected = expected + '\n' + x86_suffix;
+ expected = fixlines(expected);
+ if (options.log) {
+ print(module_text);
+ print(output);
+ print(expected);
+ }
+ assertEq(output.match(new RegExp(expected)) != null, true);
+}
+