/* * libbinrec: a recompiling translator for machine code * Copyright (c) 2016 Andrew Church * * This software may be copied and redistributed under certain conditions; * see the file "COPYING" in the source code distribution for details. * NO WARRANTY is provided with this software. */ #include "tests/common.h" #include "tests/host-x86/common.h" static const binrec_setup_t setup = { .host = BINREC_ARCH_X86_64_SYSV, .host_features = BINREC_FEATURE_X86_FMA, }; static const unsigned int host_opt = 0; static int add_rtl(RTLUnit *unit) { for (int i = 0; i < 8; i++) { EXPECT(rtl_alloc_alias_register(unit, RTLTYPE_V2_FLOAT64)); } int dummy_regs[12]; for (int i = 0; i < lenof(dummy_regs); i++) { EXPECT(dummy_regs[i] = rtl_alloc_register(unit, RTLTYPE_FLOAT32)); EXPECT(rtl_add_insn(unit, RTLOP_NOP, dummy_regs[i], 0, 0, 0)); } int reg1, reg2, reg3, spiller, reg4; EXPECT(reg1 = rtl_alloc_register(unit, RTLTYPE_FLOAT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_IMM, reg1, 0, 0, 0x3F800000)); EXPECT(reg2 = rtl_alloc_register(unit, RTLTYPE_FLOAT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_IMM, reg2, 0, 0, 0x40000000)); EXPECT(reg3 = rtl_alloc_register(unit, RTLTYPE_FLOAT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_IMM, reg3, 0, 0, 0x40400000)); EXPECT(spiller = rtl_alloc_register(unit, RTLTYPE_FLOAT32)); EXPECT(rtl_add_insn(unit, RTLOP_LOAD_IMM, spiller, 0, 0, 0x40800000)); EXPECT(reg4 = rtl_alloc_register(unit, RTLTYPE_FLOAT32)); EXPECT(rtl_add_insn(unit, RTLOP_FMADD, reg4, reg1, reg2, reg3)); for (int i = 0; i < lenof(dummy_regs); i++) { EXPECT(rtl_add_insn(unit, RTLOP_NOP, 0, dummy_regs[i], 0, 0)); } EXPECT(rtl_add_insn(unit, RTLOP_NOP, 0, reg1, reg3, 0)); EXPECT(rtl_add_insn(unit, RTLOP_NOP, 0, reg2, 0, 0)); return EXIT_SUCCESS; } static const uint8_t expected_code[] = { 0x48,0x81,0xEC,0x88,0x00,0x00,0x00, // sub $136,%rsp 0xB8,0x00,0x00,0x80,0x3F, // mov $0x3F800000,%eax 0x66,0x44,0x0F,0x6E,0xE0, // movd %eax,%xmm12 0xB8,0x00,0x00,0x00,0x40, // mov $0x40000000,%eax 0x66,0x44,0x0F,0x6E,0xE8, // movd %eax,%xmm13 0xB8,0x00,0x00,0x40,0x40, // mov $0x40400000,%eax 0x66,0x44,0x0F,0x6E,0xF0, // movd %eax,%xmm14 0xF3,0x44,0x0F,0x11,0xAC,0x24,0x80, // movss %xmm13,128(%rsp) 0x00,0x00,0x00, 0xB8,0x00,0x00,0x80,0x40, // mov $0x40800000,%eax 0x66,0x44,0x0F,0x6E,0xE8, // movd %eax,%xmm13 0x45,0x0F,0x28,0xEC, // movaps %xmm12,%xmm13 0xC4,0x62,0x09,0x99,0xAC,0x24,0x80, // vfmadd132ss 128(%rsp),%xmm14,%xmm13 0x00,0x00,0x00, 0x48,0x81,0xC4,0x88,0x00,0x00,0x00, // add $136,%rsp 0xC3, // ret }; static const char expected_log[] = ""; #include "tests/rtl-translate-test.i"