Browse Source

* try to registers more cleverly during fma code generation

git-svn-id: trunk@27671 -
florian 11 years ago
parent
commit
33602db802
2 changed files with 44 additions and 4 deletions
  1. 23 4
      compiler/x86/nx86inl.pas
  2. 21 0
      tests/test/tfma1.pp

+ 23 - 4
compiler/x86/nx86inl.pas

@@ -830,10 +830,29 @@ implementation
                end
              else
                begin
-                 hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[3].resultdef,resultdef,
-                   paraarray[3].location.register,location.register,mms_movescalar);
-                 emit_reg_reg_reg(op[tfloatdef(resultdef).floattype,0],S_NO,
-                   paraarray[1].location.register,paraarray[2].location.register,location.register);
+                 { try to use the location which is already in a temp. mm register as destination,
+                   so the compiler might be able to re-use the register }
+                 if paraarray[1].location.loc=LOC_MMREGISTER then
+                   begin
+                     hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[1].resultdef,resultdef,
+                       paraarray[1].location.register,location.register,mms_movescalar);
+                     emit_reg_reg_reg(op[tfloatdef(resultdef).floattype,3],S_NO,
+                       paraarray[3].location.register,paraarray[2].location.register,location.register);
+                   end
+                 else if paraarray[2].location.loc=LOC_MMREGISTER then
+                   begin
+                     hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[2].resultdef,resultdef,
+                       paraarray[2].location.register,location.register,mms_movescalar);
+                     emit_reg_reg_reg(op[tfloatdef(resultdef).floattype,3],S_NO,
+                       paraarray[3].location.register,paraarray[1].location.register,location.register);
+                   end
+                 else
+                   begin
+                     hlcg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,paraarray[3].resultdef,resultdef,
+                       paraarray[3].location.register,location.register,mms_movescalar);
+                     emit_reg_reg_reg(op[tfloatdef(resultdef).floattype,0],S_NO,
+                       paraarray[1].location.register,paraarray[2].location.register,location.register);
+                   end;
                end;
            end
          else

+ 21 - 0
tests/test/tfma1.pp

@@ -19,6 +19,16 @@ procedure testsingle;
     if l0<>10.0 then
       halt(1);
 
+    l0:=fma(l1+1.0,l2,l3);
+    writeln(l0);
+    if l0<>13.0 then
+      halt(1);
+
+    l0:=fma(l1,l1+1.0,l3);
+    writeln(l0);
+    if l0<>10.0 then
+      halt(1);
+
     l0:=fma(s1,l2,l3);
     writeln(l0);
     if l0<>10.0 then
@@ -63,6 +73,17 @@ procedure testdouble;
     if l0<>10.0 then
       halt(1);
 
+    l0:=fma(l1+1.0,l2,l3);
+    writeln(l0);
+    if l0<>13.0 then
+      halt(1);
+
+
+    l0:=fma(l1,l1+1.0,l3);
+    writeln(l0);
+    if l0<>10.0 then
+      halt(1);
+
     l0:=fma(d1,l2,l3);
     writeln(l0);
     if l0<>10.0 then