diff --git a/compiler/cg386mat.pas b/compiler/cg386mat.pas index aee786a022..af69b7a786 100644 --- a/compiler/cg386mat.pas +++ b/compiler/cg386mat.pas @@ -193,7 +193,8 @@ implementation secondpass(p^.left); pushed:=maybe_push(p^.right^.registers32,p); secondpass(p^.right); - if pushed then restore(p); + if pushed then + restore(p); { load left operators in a register } if p^.left^.location.loc<>LOC_REGISTER then @@ -212,7 +213,8 @@ implementation hregister1))); end; end - else hregister1:=p^.left^.location.register; + else + hregister1:=p^.left^.location.register; { determine operator } if p^.treetype=shln then @@ -223,7 +225,7 @@ implementation { shifting by a constant directly decode: } if (p^.right^.treetype=ordconstn) then begin - exprasmlist^.concat(new(pai386,op_const_reg(op,S_L,p^.right^.location.reference.offset and 31, + exprasmlist^.concat(new(pai386,op_const_reg(op,S_L,p^.right^.location.reference.offset and 31, hregister1))); p^.location.loc:=LOC_REGISTER; p^.location.register:=hregister1; @@ -233,9 +235,9 @@ implementation { load right operators in a register } if p^.right^.location.loc<>LOC_REGISTER then begin - if p^.right^.location.loc=LOC_CREGISTER then + if p^.right^.location.loc=LOC_CREGISTER then begin - hregister2:=getregister32; + hregister2:=getregister32; emit_reg_reg(A_MOV,S_L,p^.right^.location.register, hregister2); end @@ -247,17 +249,16 @@ implementation hregister2))); end; end - else hregister2:=p^.right^.location.register; + else + hregister2:=p^.right^.location.register; - { left operator is already in a register } + { left operator is already in a register } { hence are both in a register } { is it in the case ECX ? } if (hregister1=R_ECX) then begin { then only swap } - emit_reg_reg(A_XCHG,S_L,hregister1, - hregister2); - + emit_reg_reg(A_XCHG,S_L,hregister1,hregister2); hregister3:=hregister1; hregister1:=hregister2; hregister2:=hregister3; @@ -265,20 +266,14 @@ implementation { if second operator not in ECX ? } else if (hregister2<>R_ECX) then begin - { ECX not occupied then swap with right register } - if R_ECX in unused then - begin - emit_reg_reg(A_MOV,S_L,hregister2,R_ECX); - ungetregister32(hregister2); - end - else - begin - { else save ECX and then copy it } - popecx:=true; - exprasmlist^.concat(new(pai386,op_reg(A_PUSH,S_L,R_ECX))); - emit_reg_reg(A_MOV,S_L,hregister2,R_ECX); - ungetregister32(hregister2); - end; + { ECX occupied then push it } + if not (R_ECX in unused) then + begin + popecx:=true; + exprasmlist^.concat(new(pai386,op_reg(A_PUSH,S_L,R_ECX))); + end; + emit_reg_reg(A_MOV,S_L,hregister2,R_ECX); + ungetregister32(hregister2); end; { right operand is in ECX } emit_reg_reg(op,S_L,R_CL,hregister1); @@ -286,9 +281,7 @@ implementation if popecx then exprasmlist^.concat(new(pai386,op_reg(A_POP,S_L,R_ECX))); p^.location.register:=hregister1; - end; - { this register is always used when shl/shr are present } - usedinproc:=usedinproc or ($80 shr byte(R_ECX)); + end; end; @@ -541,7 +534,10 @@ implementation end. { $Log$ - Revision 1.10 1998-10-20 13:12:38 peter + Revision 1.11 1998-11-05 14:26:02 peter + * fixed shlshr which would push ecx when not needed + + Revision 1.10 1998/10/20 13:12:38 peter * fixed 'not not boolean', the location was not set to register Revision 1.9 1998/10/20 08:06:42 pierre diff --git a/compiler/tcmat.pas b/compiler/tcmat.pas index 08d84c2a89..1d1400b4b8 100644 --- a/compiler/tcmat.pas +++ b/compiler/tcmat.pas @@ -113,6 +113,7 @@ implementation procedure firstshlshr(var p : ptree); var t : ptree; + regs : longint; begin firstpass(p^.left); firstpass(p^.right); @@ -138,7 +139,11 @@ implementation if codegenerror then exit; - calcregisters(p,2,0,0); + regs:=1; + if (p^.right^.treetype<>ordconstn) then + inc(regs); + calcregisters(p,regs,0,0); + p^.resulttype:=s32bitdef; p^.location.loc:=LOC_REGISTER; end; @@ -323,7 +328,10 @@ implementation end. { $Log$ - Revision 1.5 1998-10-20 13:12:39 peter + Revision 1.6 1998-11-05 14:26:01 peter + * fixed shlshr which would push ecx when not needed + + Revision 1.5 1998/10/20 13:12:39 peter * fixed 'not not boolean', the location was not set to register Revision 1.4 1998/10/13 16:50:25 pierre