Browse Source

m68k: cleaned up second_addordinal and included OP_SUB in the common codepath

git-svn-id: trunk@33743 -
Károly Balogh 9 years ago
parent
commit
a6ee4a2ded
1 changed files with 22 additions and 54 deletions
  1. 22 54
      compiler/m68k/n68kadd.pas

+ 22 - 54
compiler/m68k/n68kadd.pas

@@ -346,9 +346,7 @@ implementation
 
     procedure t68kaddnode.second_addordinal;
       var
-        unsigned: boolean;
-        cgop   : topcg;
-        tmpreg : tregister;
+        cgop    : topcg;
       begin
         { if we need to handle overflow checking, fall back to the generic cg }
         if (nodetype in [addn,subn,muln]) and
@@ -360,10 +358,6 @@ implementation
             exit;
           end;
 
-        { determine if the comparison will be unsigned }
-        unsigned:=not(is_signed(left.resultdef)) or
-                  not(is_signed(right.resultdef));
-
         case nodetype of
           addn: cgop:=OP_ADD;
           xorn: cgop:=OP_XOR;
@@ -372,7 +366,8 @@ implementation
           subn: cgop:=OP_SUB;
           muln:
             begin
-              if unsigned then
+              if not(is_signed(left.resultdef)) or
+                 not(is_signed(right.resultdef)) then
                 cgop:=OP_MUL
               else
                 cgop:=OP_IMUL;
@@ -382,6 +377,9 @@ implementation
         end;
 
         pass_left_right;
+        if (nodetype=subn) and (nf_swapped in flags) then
+          swapleftright;
+
         hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
 
         { initialize the result }
@@ -389,52 +387,22 @@ implementation
         location.register := cg.getintregister(current_asmdata.CurrAsmList,location.size);
         cg.a_load_reg_reg(current_asmdata.CurrAsmlist,left.location.size,location.size,left.location.register,location.register);
 
-        if nodetype<>subn then
-          begin
-            if location.size <> right.location.size then
-              hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
-
-            case right.location.loc of
-              LOC_REGISTER,
-              LOC_CREGISTER:
-                  cg.a_op_reg_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.register,location.register);
-              LOC_CONSTANT:
-                  cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.value,location.register);
-              LOC_REFERENCE,
-              LOC_CREFERENCE:
-                  cg.a_op_ref_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.reference,location.register);
-              else
-                begin
-                  hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
-                  cg.a_op_reg_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.register,location.register);
-                end;
-            end
-          end
-        else  { subtract is a special case since its not commutative }
-          begin
-            hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
-            if (nf_swapped in flags) then
-              swapleftright;
-            if left.location.loc<>LOC_CONSTANT then
-              begin
-                if right.location.loc<>LOC_CONSTANT then
-                  hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_SUB,resultdef,
-                      right.location.register,left.location.register,
-                      location.register)
-                else
-                  hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SUB,resultdef,
-                    right.location.value,left.location.register,
-                    location.register);
-              end
-            else
-              begin
-                tmpreg:=hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
-                hlcg.a_load_const_reg(current_asmdata.CurrAsmList,resultdef,
-                  left.location.value,tmpreg);
-                hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_SUB,resultdef,
-                  right.location.register,tmpreg,location.register);
-              end;
-          end;
+        if (location.size <> right.location.size) or
+           not (right.location.loc in [LOC_REGISTER,LOC_CREGISTER,LOC_CONSTANT,LOC_REFERENCE,LOC_CREFERENCE]) then
+          hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
+
+        case right.location.loc of
+          LOC_REGISTER,
+          LOC_CREGISTER:
+            cg.a_op_reg_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.register,location.register);
+          LOC_CONSTANT:
+            cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.value,location.register);
+          LOC_REFERENCE,
+          LOC_CREFERENCE:
+            cg.a_op_ref_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),right.location.reference,location.register);
+        else
+          internalerror(2016052101);
+        end;
       end;