Browse Source

* MIPS: generate real instructions, not macros, for comparisons with $zero.
* g_concatcopy, g_concatcopy_unaligned: call a_cmp_reg_reg_label instead of duplicating code.

git-svn-id: trunk@24895 -

sergei 12 years ago
parent
commit
6a8e4f0381
1 changed files with 32 additions and 27 deletions
  1. 32 27
      compiler/mips/cgcpu.pas

+ 32 - 27
compiler/mips/cgcpu.pas

@@ -1080,29 +1080,44 @@ end;
 procedure TCGMIPS.a_cmp_const_reg_label(list: tasmlist; size: tcgsize; cmp_op: topcmp; a: tcgint; reg: tregister; l: tasmlabel);
 procedure TCGMIPS.a_cmp_const_reg_label(list: tasmlist; size: tcgsize; cmp_op: topcmp; a: tcgint; reg: tregister; l: tasmlabel);
 var
 var
   tmpreg: tregister;
   tmpreg: tregister;
-  ai : Taicpu;
-begin
-if a = 0 then
-  tmpreg := NR_R0
-else
 begin
 begin
-  tmpreg := GetIntRegister(list, OS_INT);
-  a_load_const_reg(list,OS_INT,a,tmpreg);
-end;
-  ai := taicpu.op_reg_reg_sym(A_BC, reg, tmpreg, l);
-  ai.SetCondition(TOpCmp2AsmCond[cmp_op]);
-  list.concat(ai);
-  { Delay slot }
-  list.Concat(TAiCpu.Op_none(A_NOP));
+  if a = 0 then
+    a_cmp_reg_reg_label(list,size,cmp_op,NR_R0,reg,l)
+  else
+    begin
+      tmpreg := GetIntRegister(list,OS_INT);
+      a_load_const_reg(list,OS_INT,a,tmpreg);
+      a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
+    end;
 end;
 end;
 
 
+const
+  TOpCmp2AsmCond_z : array[OC_GT..OC_LTE] of TAsmCond=(
+    C_GTZ,C_LTZ,C_GEZ,C_LEZ
+  );
 
 
 procedure TCGMIPS.a_cmp_reg_reg_label(list: tasmlist; size: tcgsize; cmp_op: topcmp; reg1, reg2: tregister; l: tasmlabel);
 procedure TCGMIPS.a_cmp_reg_reg_label(list: tasmlist; size: tcgsize; cmp_op: topcmp; reg1, reg2: tregister; l: tasmlabel);
 var
 var
   ai : Taicpu;
   ai : Taicpu;
 begin
 begin
-  ai := taicpu.op_reg_reg_sym(A_BC, reg2, reg1, l);
-  ai.SetCondition(TOpCmp2AsmCond[cmp_op]);
+  if ((reg1=NR_R0) or (reg2=NR_R0)) and (cmp_op in [OC_GT,OC_LT,OC_GTE,OC_LTE]) then
+    begin
+      if (reg2=NR_R0) then
+        begin
+          ai:=taicpu.op_reg_sym(A_BC,reg1,l);
+          ai.setcondition(inverse_cond(TOpCmp2AsmCond_z[cmp_op]));
+        end
+      else
+        begin
+          ai:=taicpu.op_reg_sym(A_BC,reg2,l);
+          ai.setcondition(TOpCmp2AsmCond_z[cmp_op]);
+        end;
+    end
+  else
+    begin
+      ai:=taicpu.op_reg_reg_sym(A_BC,reg2,reg1,l);
+      ai.SetCondition(TOpCmp2AsmCond[cmp_op]);
+    end;
   list.concat(ai);
   list.concat(ai);
   { Delay slot }
   { Delay slot }
   list.Concat(TAiCpu.Op_none(A_NOP));
   list.Concat(TAiCpu.Op_none(A_NOP));
@@ -1399,7 +1414,6 @@ var
   src, dst: TReference;
   src, dst: TReference;
   lab:      tasmlabel;
   lab:      tasmlabel;
   Count, count2: aint;
   Count, count2: aint;
-  ai : TaiCpu;
 
 
   function reference_is_reusable(const ref: treference): boolean;
   function reference_is_reusable(const ref: treference): boolean;
     begin
     begin
@@ -1457,11 +1471,7 @@ begin
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, src.base, src.base, 4));
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, src.base, src.base, 4));
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, dst.base, dst.base, 4));
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, dst.base, dst.base, 4));
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, countreg, countreg, -1));
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, countreg, countreg, -1));
-      //list.concat(taicpu.op_reg_sym(A_BGTZ, countreg, lab));
-      ai := taicpu.op_reg_reg_sym(A_BC,countreg, NR_R0, lab);
-      ai.setcondition(C_GT);
-      list.concat(ai);
-      list.concat(taicpu.op_none(A_NOP));
+      a_cmp_reg_reg_label(list,OS_INT,OC_GT,NR_R0,countreg,lab);
       len := len mod 4;
       len := len mod 4;
     end;
     end;
     { unrolled loop }
     { unrolled loop }
@@ -1511,7 +1521,6 @@ var
   tmpreg1, countreg: TRegister;
   tmpreg1, countreg: TRegister;
   i:   aint;
   i:   aint;
   lab: tasmlabel;
   lab: tasmlabel;
-  ai : TaiCpu;
 begin
 begin
   if (len > 31) and
   if (len > 31) and
     { see comment in g_concatcopy }
     { see comment in g_concatcopy }
@@ -1541,11 +1550,7 @@ begin
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, src.base, src.base, 1));
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, src.base, src.base, 1));
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, dst.base, dst.base, 1));
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, dst.base, dst.base, 1));
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, countreg, countreg, -1));
       list.concat(taicpu.op_reg_reg_const(A_ADDIU, countreg, countreg, -1));
-      //list.concat(taicpu.op_reg_sym(A_BGTZ, countreg, lab));
-      ai := taicpu.op_reg_reg_sym(A_BC,countreg, NR_R0, lab);
-      ai.setcondition(C_GT);
-      list.concat(ai);
-      list.concat(taicpu.op_none(A_NOP));
+      a_cmp_reg_reg_label(list,OS_INT,OC_GT,NR_R0,countreg,lab);
     end
     end
     else
     else
     begin
     begin