From bd4b7a6bc420196d0e846b5f058033101219c2cd Mon Sep 17 00:00:00 2001 From: florian <florian@freepascal.org> Date: Sat, 29 Dec 2018 21:53:52 +0000 Subject: [PATCH] * more case fixes git-svn-id: trunk@40706 - --- compiler/ncgset.pas | 9 +++++---- compiler/x86/nx86set.pas | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/compiler/ncgset.pas b/compiler/ncgset.pas index a3beba602c..3a2f180a0f 100644 --- a/compiler/ncgset.pas +++ b/compiler/ncgset.pas @@ -723,7 +723,7 @@ implementation hregister:=scratch_reg; opsize:=newdef; end; - if labelcnt>1 then + if (labelcnt>1) or not(cs_opt_level1 in current_settings.optimizerswitches) then begin last:=0; first:=true; @@ -739,7 +739,7 @@ implementation begin scratch_reg:=hlcg.getintregister(current_asmdata.CurrAsmList,opsize); gensub(tcgint(hp^._low.svalue)); - hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, OC_BE, tcgint(hp^._high.svalue-hp^._low.svalue), hregister, blocklabel(hp^.blockid)) + hlcg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opsize, jmp_le, tcgint(hp^._high.svalue-hp^._low.svalue), hregister, blocklabel(hp^.blockid)) end; end; hlcg.a_jmp_always(current_asmdata.CurrAsmList,elselabel); @@ -1224,6 +1224,9 @@ implementation else {$endif not cpu64bitalu} begin + labelcnt := 0; + TrueCount := 0; + if cs_opt_level1 in current_settings.optimizerswitches then begin { procedures are empirically passed on } @@ -1233,8 +1236,6 @@ implementation { moreover can the size only be appro- } { ximated as it is not known if rel8, } { rel16 or rel32 jumps are used } - labelcnt := 0; - TrueCount := 0; CountBoth(labels); diff --git a/compiler/x86/nx86set.pas b/compiler/x86/nx86set.pas index 8830832b14..0630b96e5d 100644 --- a/compiler/x86/nx86set.pas +++ b/compiler/x86/nx86set.pas @@ -223,6 +223,8 @@ implementation opcgsize: tcgsize; procedure genitem(t : pcaselabel); + var + range, gap: aint; begin if assigned(t^.less) then genitem(t^.less); @@ -245,6 +247,7 @@ implementation end else begin + range := aint(t^._high.svalue - t^._low.svalue); { it begins with the smallest label, if the value } { is even smaller then jump immediately to the } { ELSE-label } @@ -256,6 +259,7 @@ implementation end else begin + gap := aint(t^._low.svalue - last.svalue); { if there is no unused label between the last and the } { present label then the lower limit can be checked } { immediately. else check the range in between: } @@ -263,23 +267,23 @@ implementation { we need to use A_SUB, if cond_lt uses the carry flags because A_DEC does not set the correct flags, therefor using a_op_const_reg(OP_SUB) is not possible } - if (cond_lt in [F_C,F_NC,F_A,F_AE,F_B,F_BE]) and (aint(t^._low.svalue-last.svalue)=1) then - emit_const_reg(A_SUB,TCGSize2OpSize[opcgsize],aint(t^._low.svalue-last.svalue),hregister) + if (gap = 1) and (cond_lt in [F_C,F_NC,F_A,F_AE,F_B,F_BE]) then + emit_const_reg(A_SUB, TCGSize2OpSize[opcgsize], gap, hregister) else - cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opcgsize, aint(t^._low.svalue-last.svalue), hregister); + cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opcgsize, gap, hregister); { no jump necessary here if the new range starts at at the value following the previous one } - if ((t^._low-last) <> 1) or + if (gap <> 1) or (not lastrange) then cg.a_jmp_flags(current_asmdata.CurrAsmList,cond_lt,elselabel); end; { we need to use A_SUB, if cond_le uses the carry flags because A_DEC does not set the correct flags, therefor using a_op_const_reg(OP_SUB) is not possible } - if (cond_le in [F_C,F_NC,F_A,F_AE,F_B,F_BE]) and (aint(t^._high.svalue-t^._low.svalue)=1) then - emit_const_reg(A_SUB,TCGSize2OpSize[opcgsize],aint(t^._high.svalue-t^._low.svalue),hregister) + if (cond_le in [F_C,F_NC,F_A,F_AE,F_B,F_BE]) and (range = 1) then + emit_const_reg(A_SUB,TCGSize2OpSize[opcgsize], range, hregister) else - cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opcgsize, aint(t^._high.svalue-t^._low.svalue), hregister); + cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opcgsize, range, hregister); cg.a_jmp_flags(current_asmdata.CurrAsmList,cond_le,blocklabel(t^.blockid)); last:=t^._high; @@ -311,7 +315,7 @@ implementation genlinearcmplist(hp) else begin - if labelcnt>1 then + if (labelcnt>1) or not(cs_opt_level1 in current_settings.optimizerswitches) then begin last:=0; lastrange:=false; @@ -326,7 +330,7 @@ implementation else begin cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SUB, opcgsize, tcgint(hp^._low.svalue), hregister); - cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opcgsize, OC_BE, tcgint(hp^._high.svalue - hp^._low.svalue), hregister,blocklabel(hp^.blockid)); + cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList, opcgsize, jmp_le, tcgint(hp^._high.svalue - hp^._low.svalue), hregister,blocklabel(hp^.blockid)); end; end; cg.a_jmp_always(current_asmdata.CurrAsmList,elselabel);