瀏覽代碼

+ generic a_cmp_const_reg_label

git-svn-id: branches/avr@17294 -
florian 14 年之前
父節點
當前提交
8cfbb70326
共有 2 個文件被更改,包括 61 次插入7 次删除
  1. 48 1
      compiler/avr/cgcpu.pas
  2. 13 6
      compiler/cgobj.pas

+ 48 - 1
compiler/avr/cgcpu.pas

@@ -1071,8 +1071,55 @@ unit cgcpu;
     {  comparison operations }
     procedure tcgavr.a_cmp_const_reg_label(list : TAsmList;size : tcgsize;
       cmp_op : topcmp;a : aint;reg : tregister;l : tasmlabel);
+      var
+        swapped : boolean;
+        tmpreg : tregister;
+        i : byte;
       begin
-        { TODO : a_cmp_const_reg_label }
+        if a=0 then
+          begin
+            { swap parameters? }
+            case cmp_op of
+              OC_GT:
+                begin
+                  swapped:=true;
+                  cmp_op:=OC_LT;
+                end;
+              OC_LTE:
+                begin
+                  swapped:=true;
+                  cmp_op:=OC_GTE;
+                end;
+              OC_BE:
+                begin
+                  swapped:=true;
+                  cmp_op:=OC_AE;
+                end;
+              OC_A:
+                begin
+                  swapped:=true;
+                  cmp_op:=OC_A;
+                end;
+            end;
+
+            if swapped then
+              list.concat(taicpu.op_reg_reg(A_CP,reg,NR_R1))
+            else
+              list.concat(taicpu.op_reg_reg(A_CP,NR_R1,reg));
+
+            for i:=2 to tcgsize2size[size] do
+              begin
+                reg:=GetNextReg(reg);
+                if swapped then
+                  list.concat(taicpu.op_reg_reg(A_CPC,reg,NR_R1))
+                else
+                  list.concat(taicpu.op_reg_reg(A_CPC,NR_R1,reg));
+              end;
+
+            a_jmp_cond(list,cmp_op,l);
+          end
+        else
+          inherited a_cmp_const_reg_label(list,size,cmp_op,a,reg,l);
       end;
 
 

+ 13 - 6
compiler/cgobj.pas

@@ -346,7 +346,7 @@ unit cgobj;
 
           {  comparison operations }
           procedure a_cmp_const_reg_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;reg : tregister;
-            l : tasmlabel);virtual; abstract;
+            l : tasmlabel); virtual;
           procedure a_cmp_const_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
             l : tasmlabel); virtual;
           procedure a_cmp_const_loc_label(list: TAsmList; size: tcgsize;cmp_op: topcmp; a: aint; const loc: tlocation;
@@ -3053,12 +3053,21 @@ implementation
       end;
 
 
-    procedure tcg.a_cmp_const_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
-     l : tasmlabel);
-
+    procedure tcg.a_cmp_const_reg_label(list: TAsmList; size: tcgsize;
+      cmp_op: topcmp; a: aint; reg: tregister; l: tasmlabel);
       var
         tmpreg: tregister;
+      begin
+        tmpreg:=getintregister(list,size);
+        a_load_const_reg(list,size,a,tmpreg);
+        a_cmp_reg_reg_label(list,size,cmp_op,tmpreg,reg,l);
+      end;
 
+
+    procedure tcg.a_cmp_const_ref_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;const ref : treference;
+      l : tasmlabel);
+      var
+        tmpreg: tregister;
       begin
         tmpreg:=getintregister(list,size);
         a_load_ref_reg(list,size,size,ref,tmpreg);
@@ -3068,10 +3077,8 @@ implementation
 
     procedure tcg.a_cmp_const_loc_label(list : TAsmList;size : tcgsize;cmp_op : topcmp;a : aint;const loc : tlocation;
       l : tasmlabel);
-
       var
         tmpreg : tregister;
-
       begin
         case loc.loc of
           LOC_REGISTER,LOC_CREGISTER: