From c4b40909f7ba9cc9d3c58621b53f902f1795427d Mon Sep 17 00:00:00 2001 From: MerryMage Date: Wed, 22 Nov 2017 17:46:46 +0000 Subject: [PATCH] emit_x64: Improve code emission of FPCompare{32,64} Replace if-chain with table lookup --- src/backend_x64/emit_x64.cpp | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/backend_x64/emit_x64.cpp b/src/backend_x64/emit_x64.cpp index 97dade90..5e2f889b 100644 --- a/src/backend_x64/emit_x64.cpp +++ b/src/backend_x64/emit_x64.cpp @@ -2447,25 +2447,16 @@ void EmitX64::EmitFPSub64(RegAlloc& reg_alloc, IR::Block& block, IR::Inst* inst) } static void SetFpscrNzcvFromFlags(BlockOfCode* code, RegAlloc& reg_alloc) { - reg_alloc.ScratchGpr({HostLoc::RAX}); // lahf requires use of ah - Xbyak::Reg32 nzcv_imm = reg_alloc.ScratchGpr().cvt32(); + reg_alloc.ScratchGpr({HostLoc::RCX}); // shifting requires use of cl Xbyak::Reg32 nzcv = reg_alloc.ScratchGpr().cvt32(); using namespace Xbyak::util; - code->lahf(); - code->mov(nzcv_imm, 0x30000000); - code->cmp(ah, 0b01000111); - code->cmove(nzcv, nzcv_imm); - code->mov(nzcv_imm, 0x20000000); - code->cmp(ah, 0b00000010); - code->cmove(nzcv, nzcv_imm); - code->mov(nzcv_imm, 0x80000000); - code->cmp(ah, 0b00000011); - code->cmove(nzcv, nzcv_imm); - code->mov(nzcv_imm, 0x60000000); - code->cmp(ah, 0b01000010); - code->cmove(nzcv, nzcv_imm); + code->mov(nzcv, 0x28630000); + code->sete(cl); + code->rcl(cl, 3); + code->shl(nzcv, cl); + code->and_(nzcv, 0xF0000000); code->mov(dword[r15 + offsetof(JitState, FPSCR_nzcv)], nzcv); }