瀏覽代碼

m68k: use inlined realconsts also during normal float calculations on '881/040/060. also optimize them where possible

git-svn-id: trunk@33671 -
Károly Balogh 9 年之前
父節點
當前提交
424f329173
共有 2 個文件被更改,包括 36 次插入8 次删除
  1. 12 0
      compiler/m68k/aoptcpu.pas
  2. 24 8
      compiler/m68k/n68kadd.pas

+ 12 - 0
compiler/m68k/aoptcpu.pas

@@ -161,6 +161,18 @@ unit aoptcpu;
                           end;
                       end;
                   end;
+              A_FMOVE,A_FMUL,A_FADD,A_FSUB,A_FDIV:
+                  if (taicpu(p).oper[0]^.typ = top_realconst) then
+                    begin
+                      tmpsingle:=taicpu(p).oper[0]^.val_real;
+                      if (taicpu(p).opsize = S_FD) and
+                         ((taicpu(p).oper[0]^.val_real - tmpsingle) = 0.0) then
+                        begin
+                          DebugMsg('Optimizer: FMOVE/FMUL/FADD/FSUB/FDIV const to lesser precision',p);
+                          taicpu(p).opsize:=S_FS;
+                          result:=true;
+                        end;
+                    end;
             end;
           end;
       end;

+ 24 - 8
compiler/m68k/n68kadd.pas

@@ -171,23 +171,39 @@ implementation
         case current_settings.fputype of
           fpu_68881,fpu_coldfire:
             begin
-              { have left in the register, right can be a memory location }
-              hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
-
               { initialize the result }
               location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
-              location.register := cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
+
+              { have left in the register, right can be a memory location }
+              if not (current_settings.fputype = fpu_coldfire) and
+                 (left.nodetype = realconstn) then
+                begin
+                  location.register := cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
+                  current_asmdata.CurrAsmList.concat(taicpu.op_realconst_reg(A_FMOVE,tcgsize2opsize[left.location.size],trealconstnode(left).value_real,location.register))
+                end
+              else
+                begin
+                  hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
+
+                  location.register := cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
+                  cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmlist,OS_NO,OS_NO,left.location.register,location.register);
+                end;
 
               { emit the actual operation }
-              cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmlist,OS_NO,OS_NO,left.location.register,location.register);
               case right.location.loc of
                 LOC_FPUREGISTER,LOC_CFPUREGISTER:
                     current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,fpuregopsize,right.location.register,location.register));
                 LOC_REFERENCE,LOC_CREFERENCE:
                     begin
-                      href:=right.location.reference;
-                      tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,current_settings.fputype = fpu_coldfire);
-                      current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(op,tcgsize2opsize[right.location.size],href,location.register));
+                      if not (current_settings.fputype = fpu_coldfire) and
+                         (right.nodetype = realconstn) then
+                        current_asmdata.CurrAsmList.concat(taicpu.op_realconst_reg(op,tcgsize2opsize[right.location.size],trealconstnode(right).value_real,location.register))
+                      else
+                        begin
+                          href:=right.location.reference;
+                          tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,current_settings.fputype = fpu_coldfire);
+                          current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(op,tcgsize2opsize[right.location.size],href,location.register));
+                        end;
                     end
                 else
                   internalerror(2015021501);