瀏覽代碼

m68k: some code to support the ColdFire v4e FPU. not functional yet.

git-svn-id: trunk@33533 -
Károly Balogh 9 年之前
父節點
當前提交
bd564b8933
共有 6 個文件被更改,包括 61 次插入48 次删除
  1. 14 23
      compiler/m68k/cgcpu.pas
  2. 14 4
      compiler/m68k/cpubase.pas
  3. 5 3
      compiler/m68k/cpuinfo.pas
  4. 6 6
      compiler/m68k/n68kadd.pas
  5. 19 9
      compiler/m68k/n68kinl.pas
  6. 3 3
      compiler/m68k/n68kmat.pas

+ 14 - 23
compiler/m68k/cgcpu.pas

@@ -559,14 +559,14 @@ unit cgcpu;
         paramanager.freecgpara(list,paraloc3);
         paramanager.freecgpara(list,paraloc2);
         paramanager.freecgpara(list,paraloc1);
-        if current_settings.fputype in [fpu_68881] then
+        if current_settings.fputype in [fpu_68881,fpu_coldfire] then
           alloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
         alloccpuregisters(list,R_ADDRESSREGISTER,paramanager.get_volatile_registers_address(pocall_default));
         alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
         a_call_name(list,name,false);
         dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
         dealloccpuregisters(list,R_ADDRESSREGISTER,paramanager.get_volatile_registers_address(pocall_default));
-        if current_settings.fputype in [fpu_68881] then
+        if current_settings.fputype in [fpu_68881,fpu_coldfire] then
           dealloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
         cg.a_reg_alloc(list,NR_FUNCTION_RESULT_REG);
         cg.a_load_reg_reg(list,OS_32,OS_32,NR_FUNCTION_RESULT_REG,reg);
@@ -594,14 +594,14 @@ unit cgcpu;
         paramanager.freecgpara(list,paraloc3);
         paramanager.freecgpara(list,paraloc2);
         paramanager.freecgpara(list,paraloc1);
-        if current_settings.fputype in [fpu_68881] then
+        if current_settings.fputype in [fpu_68881,fpu_coldfire] then
           alloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
         alloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
         alloccpuregisters(list,R_ADDRESSREGISTER,paramanager.get_volatile_registers_address(pocall_default));
         a_call_name(list,name,false);
         dealloccpuregisters(list,R_ADDRESSREGISTER,paramanager.get_volatile_registers_address(pocall_default));
         dealloccpuregisters(list,R_INTREGISTER,paramanager.get_volatile_registers_int(pocall_default));
-        if current_settings.fputype in [fpu_68881] then
+        if current_settings.fputype in [fpu_68881,fpu_coldfire] then
           dealloccpuregisters(list,R_FPUREGISTER,paramanager.get_volatile_registers_fpu(pocall_default));
         cg.a_reg_alloc(list,NR_FUNCTION_RESULT_REG);
         cg.a_load_reg_reg(list,OS_32,OS_32,NR_FUNCTION_RESULT_REG,reg2);
@@ -889,7 +889,7 @@ unit cgcpu;
       var
         instr : taicpu;
       begin
-        instr:=taicpu.op_reg_reg(A_FMOVE,S_FX,reg1,reg2);
+        instr:=taicpu.op_reg_reg(A_FMOVE,fpuregsize,reg1,reg2);
         add_move_instruction(instr);
         list.concat(instr);
       end;
@@ -901,11 +901,8 @@ unit cgcpu;
         href : treference;
       begin
         opsize := tcgsize2opsize[fromsize];
-        { extended is not supported, since it is not available on Coldfire }
-        if opsize = S_FX then
-          internalerror(20020729);
         href := ref;
-        fixref(list,href,false);
+        fixref(list,href,current_settings.fputype = fpu_coldfire);
         list.concat(taicpu.op_ref_reg(A_FMOVE,opsize,href,reg));
       end;
 
@@ -915,11 +912,8 @@ unit cgcpu;
         href : treference;
       begin
         opsize := tcgsize2opsize[tosize];
-        { extended is not supported, since it is not available on Coldfire }
-        if opsize = S_FX then
-          internalerror(20020729);
         href := ref;
-        fixref(list,href,false);
+        fixref(list,href,current_settings.fputype = fpu_coldfire);
         list.concat(taicpu.op_reg_ref(A_FMOVE,opsize,reg,href));
       end;
 
@@ -927,7 +921,7 @@ unit cgcpu;
       var
         ref : treference;
       begin
-        if use_push(cgpara) and (current_settings.fputype in [fpu_68881]) then
+        if use_push(cgpara) and (current_settings.fputype in [fpu_68881,fpu_coldfire]) then
           begin
             cgpara.check_simple_location;
             { FIXME: 68k cg really needs to support 2 byte stack alignment, otherwise the "Extended"
@@ -943,7 +937,6 @@ unit cgcpu;
     procedure tcg68k.a_loadfpu_ref_cgpara(list : TAsmList; size : tcgsize;const ref : treference;const cgpara : TCGPara);
       var
         href : treference;
-        fref : treference;
         freg : tregister;
       begin
         if current_settings.fputype = fpu_soft then
@@ -963,13 +956,11 @@ unit cgcpu;
               inherited a_loadfpu_ref_cgpara(list,size,ref,cgpara);
           end
         else
-          if use_push(cgpara) and (current_settings.fputype in [fpu_68881]) then
+          if use_push(cgpara) and (current_settings.fputype in [fpu_68881,fpu_coldfire]) then
             begin
-              fref:=ref;
-              fixref(list,fref,false);
               { fmove can't do <ea> -> <ea>, so move it to an fpreg first }
               freg:=getfpuregister(list,size);
-              a_loadfpu_ref_reg(list,size,size,fref,freg);
+              a_loadfpu_ref_reg(list,size,size,ref,freg);
               reference_reset_base(href, NR_STACK_POINTER_REG, 0, cgpara.alignment);
               href.direction := dir_dec;
               list.concat(taicpu.op_reg_ref(A_FMOVE,tcgsize2opsize[cgpara.location^.size],freg,href));
@@ -1796,9 +1787,9 @@ unit cgcpu;
                 { size is always longword aligned, while fsize is not }
                 inc(href.offset,size);
                 if fsize = 12{sizeof(extended)} then
-                  list.concat(taicpu.op_reg_ref(A_FMOVE,S_FX,hfreg,href))
+                  list.concat(taicpu.op_reg_ref(A_FMOVE,fpuregsize,hfreg,href))
                 else
-                  list.concat(taicpu.op_regset_ref(A_FMOVEM,S_FX,[],[],fpuregs,href));
+                  list.concat(taicpu.op_regset_ref(A_FMOVEM,fpuregsize,[],[],fpuregs,href));
               end;
           end;
       end;
@@ -1884,9 +1875,9 @@ unit cgcpu;
             { size is always longword aligned, while fsize is not }
             inc(href.offset,size);
             if fsize = 12{sizeof(extended)} then
-              list.concat(taicpu.op_ref_reg(A_FMOVE,S_FX,href,hfreg))
+              list.concat(taicpu.op_ref_reg(A_FMOVE,fpuregsize,href,hfreg))
             else
-              list.concat(taicpu.op_ref_regset(A_FMOVEM,S_FX,href,[],[],fpuregs));
+              list.concat(taicpu.op_ref_regset(A_FMOVEM,fpuregsize,href,[],[],fpuregs));
           end;
 
         tg.UnGetTemp(list,current_procinfo.save_regs_ref);

+ 14 - 4
compiler/m68k/cpubase.pas

@@ -28,7 +28,7 @@ unit cpubase;
   interface
 
   uses
-    globtype,
+    globtype,globals,
     strings,cutils,cclasses,aasmbase,cpuinfo,cgbase;
 
 {*****************************************************************************
@@ -356,6 +356,7 @@ unit cpubase;
 
     function isaddressregister(reg : tregister) : boolean;
     function isintregister(reg : tregister) : boolean;
+    function fpuregsize: TOpSize; {$ifdef USEINLINE}inline;{$endif USEINLINE}
     function isregoverlap(reg1: tregister; reg2: tregister): boolean;
 
     function inverse_cond(const c: TAsmCond): TAsmCond; {$ifdef USEINLINE}inline;{$endif USEINLINE}
@@ -471,15 +472,17 @@ implementation
 
 
     function reg_cgsize(const reg: tregister): tcgsize;
+      { 68881 & compatibles -> 80 bit }
+      { CF FPU -> 64 bit }
+      const
+        fpureg_cgsize: array[boolean] of tcgsize = ( OS_F80, OS_F64 );
       begin
         case getregtype(reg) of
           R_ADDRESSREGISTER,
           R_INTREGISTER :
             result:=OS_32;
           R_FPUREGISTER :
-            { 68881 & compatibles -> 80 bit }
-            { CF FPU -> 64 bit, but that's unsupported for now }
-            result:=OS_F80;
+            result:=fpureg_cgsize[current_settings.fputype = fpu_coldfire];
           else
             internalerror(200303181);
         end;
@@ -520,6 +523,13 @@ implementation
         result:=getregtype(reg)=R_INTREGISTER;
       end;
 
+    function fpuregsize: TOpSize; {$ifdef USEINLINE}inline;{$endif USEINLINE}
+      const
+        fpu_regsize: array[boolean] of TOpSize = ( S_FX, S_FD );
+      begin
+        result:=fpu_regsize[current_settings.fputype = fpu_coldfire];
+      end;
+
     // the function returns true, if the registers overlap (subreg of the same superregister and same type)
     function isregoverlap(reg1: tregister; reg2: tregister): boolean;
       begin

+ 5 - 3
compiler/m68k/cpuinfo.pas

@@ -48,7 +48,8 @@ Type
      (fpu_none,
       fpu_soft,
       fpu_libgcc,
-      fpu_68881
+      fpu_68881,
+      fpu_coldfire
      );
 
    tcontrollertype =
@@ -108,10 +109,11 @@ Const
      'isac'
    );
 
-   fputypestr : array[tfputype] of string[6] = ('',
+   fputypestr : array[tfputype] of string[8] = ('',
      'SOFT',
      'LIBGCC',
-     '68881'
+     '68881',
+     'COLDFIRE'
    );
 
    { Supported optimizations, only used for information }

+ 6 - 6
compiler/m68k/n68kadd.pas

@@ -140,7 +140,7 @@ implementation
           swapleftright;
 
         case current_settings.fputype of
-          fpu_68881:
+          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);
@@ -153,11 +153,11 @@ implementation
               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,S_FX,right.location.register,location.register));
+                    current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,fpuregsize,right.location.register,location.register));
                 LOC_REFERENCE,LOC_CREFERENCE:
                     begin
                       href:=right.location.reference;
-                      tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
+                      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
                 else
@@ -182,7 +182,7 @@ implementation
           swapleftright;
 
         case current_settings.fputype of
-          fpu_68881:
+          fpu_68881,fpu_coldfire:
             begin
               { force left fpureg as register, right can be reference }
               hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
@@ -190,11 +190,11 @@ implementation
               { emit compare }
               case right.location.loc of
                 LOC_FPUREGISTER,LOC_CFPUREGISTER:
-                    current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FCMP,S_FX,right.location.register,left.location.register));
+                    current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FCMP,fpuregsize,right.location.register,left.location.register));
                 LOC_REFERENCE,LOC_CREFERENCE:
                     begin
                       href:=right.location.reference;
-                      tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
+                      tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,current_settings.fputype = fpu_coldfire);
                       current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_FCMP,tcgsize2opsize[right.location.size],href,left.location.register));
                     end
                 else

+ 19 - 9
compiler/m68k/n68kinl.pas

@@ -71,7 +71,7 @@ implementation
         else
           begin
             case current_settings.fputype of
-              fpu_68881:
+              fpu_68881,fpu_coldfire:
                 expectloc:=LOC_FPUREGISTER;
               else
                 internalerror(2015022206);
@@ -87,7 +87,7 @@ implementation
         else
           begin
             case current_settings.fputype of
-              fpu_68881:
+              fpu_68881,fpu_coldfire:
                 expectloc:=LOC_FPUREGISTER;
               else
                 internalerror(2015022201);
@@ -103,7 +103,7 @@ implementation
         else
           begin
             case current_settings.fputype of
-              fpu_68881:
+              fpu_68881,fpu_coldfire:
                 expectloc:=LOC_FPUREGISTER;
               else
                 internalerror(2015022203);
@@ -121,6 +121,11 @@ implementation
             case current_settings.fputype of
               fpu_68881:
                 expectloc:=LOC_FPUREGISTER;
+              fpu_soft,fpu_coldfire:
+                begin
+                  result:=inherited first_sin_real;
+                  exit;
+                end;
               else
                 internalerror(2015022203);
             end;
@@ -137,6 +142,11 @@ implementation
             case current_settings.fputype of
               fpu_68881:
                 expectloc:=LOC_FPUREGISTER;
+              fpu_soft,fpu_coldfire:
+                begin
+                  result:=inherited first_sin_real;
+                  exit;
+                end;
               else
                 internalerror(2015022203);
             end;
@@ -154,7 +164,7 @@ implementation
       begin
         secondpass(left);
         case current_settings.fputype of
-          fpu_68881:
+          fpu_68881,fpu_coldfire:
             begin
               //current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('second_sqr_real called!')));
               hlcg.location_force_fpureg(current_asmdata.CurrAsmList,left.location,left.resultdef,true);
@@ -166,7 +176,7 @@ implementation
                   location.loc := LOC_FPUREGISTER;
                   cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmlist,OS_NO,OS_NO,left.location.register,location.register);
                 end;
-              current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FMUL,S_FX,left.location.register,location.register));
+              current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FMUL,fpuregsize,left.location.register,location.register));
             end;
         else
           internalerror(2015022202);
@@ -197,7 +207,7 @@ implementation
       begin
         secondpass(left);
         case current_settings.fputype of
-          fpu_68881:
+          fpu_68881,fpu_coldfire:
             begin
               location_reset(location,LOC_FPUREGISTER,left.location.size);
 
@@ -205,18 +215,18 @@ implementation
                 LOC_FPUREGISTER:
                   begin
                     location.register:=left.location.register;
-                    current_asmdata.CurrAsmList.concat(taicpu.op_reg(op,S_FX,location.register))
+                    current_asmdata.CurrAsmList.concat(taicpu.op_reg(op,fpuregsize,location.register))
                   end;
                 LOC_CFPUREGISTER:
                   begin
                     location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
-                    current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,S_FX,left.location.register,location.register));
+                    current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(op,fpuregsize,left.location.register,location.register));
                   end;
                 LOC_REFERENCE,LOC_CREFERENCE:
                   begin
                     location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
                     href:=left.location.reference;
-                    tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
+                    tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,current_settings.fputype = fpu_coldfire);
                     current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(op,tcgsize2opsize[left.location.size],href,location.register));
                   end;
                 else

+ 3 - 3
compiler/m68k/n68kmat.pas

@@ -194,18 +194,18 @@ implementation
             begin
               location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
               href:=left.location.reference;
-              tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,false);
+              tcg68k(cg).fixref(current_asmdata.CurrAsmList,href,current_settings.fputype = fpu_coldfire);
               current_asmdata.CurrAsmList.concat(taicpu.op_ref_reg(A_FNEG,tcgsize2opsize[left.location.size],href,location.register));
             end;
           LOC_FPUREGISTER:
             begin
               location.register:=left.location.register;
-              current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_FNEG,S_FX,location.register));
+              current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_FNEG,fpuregsize,location.register));
             end;
           LOC_CFPUREGISTER:
             begin
                location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
-               current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FNEG,S_FX,left.location.register,location.register));
+               current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FNEG,fpuregsize,left.location.register,location.register));
             end;
           else
             internalerror(200306021);