Ver código fonte

+ For muln, don't load left operand in register unless necessary.
(mul supports memory operands).

git-svn-id: trunk@8110 -

daniel 18 anos atrás
pai
commit
5ce54c6a20
2 arquivos alterados com 46 adições e 12 exclusões
  1. 23 6
      compiler/i386/n386add.pas
  2. 23 6
      compiler/x86_64/nx64add.pas

+ 23 - 6
compiler/i386/n386add.pas

@@ -345,7 +345,9 @@ interface
 
     procedure ti386addnode.second_mul;
 
-    var r:Tregister;
+    var reg:Tregister;
+        ref:Treference;
+        use_ref:boolean;
         hl4 : tasmlabel;
 
     begin
@@ -353,17 +355,32 @@ interface
 
       {The location.register will be filled in later (JM)}
       location_reset(location,LOC_REGISTER,OS_INT);
-      {Get a temp register and load the left value into it
-       and free the location.}
-      r:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
-      cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,left.location,r);
+      { Mul supports registers and references, so if not register/reference,
+        load the location into a register}
+      use_ref:=false;
+      if left.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
+        reg:=left.location.register
+      else if left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
+        begin
+          ref:=left.location.reference;
+          use_ref:=true;
+        end
+      else
+        begin
+          {LOC_CONSTANT for example.}
+          reg:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
+          cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,left.location,reg);
+        end;
       {Allocate EAX.}
       cg.getcpuregister(current_asmdata.CurrAsmList,NR_EAX);
       {Load the right value.}
       cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,right.location,NR_EAX);
       {Also allocate EDX, since it is also modified by a mul (JM).}
       cg.getcpuregister(current_asmdata.CurrAsmList,NR_EDX);
-      emit_reg(A_MUL,S_L,r);
+      if use_ref then
+        emit_ref(A_MUL,S_L,ref)
+      else
+        emit_reg(A_MUL,S_L,reg);
       if cs_check_overflow in current_settings.localswitches  then
        begin
          current_asmdata.getjumplabel(hl4);

+ 23 - 6
compiler/x86_64/nx64add.pas

@@ -47,7 +47,9 @@ interface
 
     procedure tx8664addnode.second_mul;
 
-    var r:Tregister;
+    var reg:Tregister;
+        ref:Treference;
+        use_ref:boolean;
         hl4 : tasmlabel;
 
     begin
@@ -55,17 +57,32 @@ interface
 
       { The location.register will be filled in later (JM) }
       location_reset(location,LOC_REGISTER,OS_INT);
-      { Get a temp register and load the left value into it
-        and free the location. }
-      r:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
-      cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,left.location,r);
+      { Mul supports registers and references, so if not register/reference,
+        load the location into a register}
+      use_ref:=false;
+      if left.location.loc in [LOC_REGISTER,LOC_CREGISTER] then
+        reg:=left.location.register
+      else if left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
+        begin
+          ref:=left.location.reference;
+          use_ref:=true;
+        end
+      else
+        begin
+          {LOC_CONSTANT for example.}
+          reg:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
+          cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,left.location,reg);
+        end;
       { Allocate RAX. }
       cg.getcpuregister(current_asmdata.CurrAsmList,NR_RAX);
       { Load the right value. }
       cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,right.location,NR_RAX);
       { Also allocate RDX, since it is also modified by a mul (JM). }
       cg.getcpuregister(current_asmdata.CurrAsmList,NR_RDX);
-      emit_reg(A_MUL,S_Q,r);
+      if use_ref then
+        emit_ref(A_MUL,S_L,ref)
+      else
+        emit_reg(A_MUL,S_L,reg);
       if cs_check_overflow in current_settings.localswitches  then
        begin
          current_asmdata.getjumplabel(hl4);