Browse Source

+ optimization in tcg8086.a_op_const_reg and .a_op_const_ref for 32-bit OP_ADD
and OP_SUB when the low 16 bits of the const are 0

git-svn-id: trunk@25704 -

nickysn 12 years ago
parent
commit
88c7ca96c5
1 changed files with 22 additions and 5 deletions
  1. 22 5
      compiler/i8086/cgcpu.pas

+ 22 - 5
compiler/i8086/cgcpu.pas

@@ -293,8 +293,16 @@ unit cgcpu;
               OP_ADD, OP_SUB:
               OP_ADD, OP_SUB:
                 begin
                 begin
                   get_32bit_ops(op, op1, op2);
                   get_32bit_ops(op, op1, op2);
-                  list.concat(taicpu.op_const_reg(op1,S_W,aint(a and $FFFF),reg));
-                  list.concat(taicpu.op_const_reg(op2,S_W,aint(a shr 16),GetNextReg(reg)));
+                  { Optimization when the low 16-bits of the constant are 0 }
+                  if aint(a and $FFFF) = 0 then
+                    begin
+                      list.concat(taicpu.op_const_reg(op1,S_W,aint(a shr 16),GetNextReg(reg)));
+                    end
+                  else
+                    begin
+                      list.concat(taicpu.op_const_reg(op1,S_W,aint(a and $FFFF),reg));
+                      list.concat(taicpu.op_const_reg(op2,S_W,aint(a shr 16),GetNextReg(reg)));
+                    end;
                 end;
                 end;
               OP_AND, OP_OR, OP_XOR:
               OP_AND, OP_OR, OP_XOR:
                 begin
                 begin
@@ -502,9 +510,18 @@ unit cgcpu;
               OP_ADD, OP_SUB:
               OP_ADD, OP_SUB:
                 begin
                 begin
                   get_32bit_ops(op, op1, op2);
                   get_32bit_ops(op, op1, op2);
-                  list.concat(taicpu.op_const_ref(op1,S_W,aint(a and $FFFF),tmpref));
-                  inc(tmpref.offset, 2);
-                  list.concat(taicpu.op_const_ref(op2,S_W,aint(a shr 16),tmpref));
+                  { Optimization when the low 16-bits of the constant are 0 }
+                  if aint(a and $FFFF) = 0 then
+                    begin
+                      inc(tmpref.offset, 2);
+                      list.concat(taicpu.op_const_ref(op1,S_W,aint(a shr 16),tmpref));
+                    end
+                  else
+                    begin
+                      list.concat(taicpu.op_const_ref(op1,S_W,aint(a and $FFFF),tmpref));
+                      inc(tmpref.offset, 2);
+                      list.concat(taicpu.op_const_ref(op2,S_W,aint(a shr 16),tmpref));
+                    end;
                 end;
                 end;
               OP_AND, OP_OR, OP_XOR:
               OP_AND, OP_OR, OP_XOR:
                 begin
                 begin