From 06c4c651fdd4605b34e56c5ab001e88fb14b1c77 Mon Sep 17 00:00:00 2001 From: florian Date: Mon, 8 May 2017 20:44:24 +0000 Subject: [PATCH] * factored out PrePeepholeOptSxx + x86-64 uses PrePeepholeOptSxx now as well git-svn-id: trunk@36158 - --- compiler/i386/aoptcpu.pas | 64 ++----------------------- compiler/x86/aoptx86.pas | 95 ++++++++++++++++++++++++++++++++++--- compiler/x86_64/aoptcpu.pas | 15 ++++++ 3 files changed, 106 insertions(+), 68 deletions(-) diff --git a/compiler/i386/aoptcpu.pas b/compiler/i386/aoptcpu.pas index 746f299555..92e1a14994 100644 --- a/compiler/i386/aoptcpu.pas +++ b/compiler/i386/aoptcpu.pas @@ -607,67 +607,9 @@ begin end; end; end; - A_SAR, A_SHR: - {changes the code sequence - shr/sar const1, x - shl const2, x - to either "sar/and", "shl/and" or just "and" depending on const1 and const2} - begin - if GetNextInstruction(p, hp1) and - (tai(hp1).typ = ait_instruction) and - (taicpu(hp1).opcode = A_SHL) and - (taicpu(p).oper[0]^.typ = top_const) and - (taicpu(hp1).oper[0]^.typ = top_const) and - (taicpu(hp1).opsize = taicpu(p).opsize) and - (taicpu(hp1).oper[1]^.typ = taicpu(p).oper[1]^.typ) and - OpsEqual(taicpu(hp1).oper[1]^, taicpu(p).oper[1]^) then - if (taicpu(p).oper[0]^.val > taicpu(hp1).oper[0]^.val) and - not(cs_opt_size in current_settings.optimizerswitches) then - { shr/sar const1, %reg - shl const2, %reg - with const1 > const2 } - begin - taicpu(p).loadConst(0,taicpu(p).oper[0]^.val-taicpu(hp1).oper[0]^.val); - taicpu(hp1).opcode := A_AND; - l := (1 shl (taicpu(hp1).oper[0]^.val)) - 1; - case taicpu(p).opsize Of - S_L: taicpu(hp1).loadConst(0,l Xor aint($ffffffff)); - S_B: taicpu(hp1).loadConst(0,l Xor $ff); - S_W: taicpu(hp1).loadConst(0,l Xor $ffff); - end; - end - else if (taicpu(p).oper[0]^.val taicpu(hp1).oper[0]^.val) and + not(cs_opt_size in current_settings.optimizerswitches) then + begin + { shr/sar const1, %reg + shl const2, %reg + with const1 > const2 } + taicpu(p).loadConst(0,taicpu(p).oper[0]^.val-taicpu(hp1).oper[0]^.val); + taicpu(hp1).opcode := A_AND; + l := (1 shl (taicpu(hp1).oper[0]^.val)) - 1; + case taicpu(p).opsize Of + S_B: taicpu(hp1).loadConst(0,l Xor $ff); + S_W: taicpu(hp1).loadConst(0,l Xor $ffff); + S_L: taicpu(hp1).loadConst(0,l Xor aint($ffffffff)); + S_Q: taicpu(hp1).loadConst(0,l Xor aint($ffffffffffffffff)); + else + Internalerror(2017050703) + end; + end + else if (taicpu(p).oper[0]^.val