Bläddra i källkod

* changed reg2opsize to function

peter 22 år sedan
förälder
incheckning
3f0491bb38
4 ändrade filer med 81 tillägg och 50 borttagningar
  1. 64 36
      compiler/i386/cpubase.pas
  2. 6 3
      compiler/i386/csopt386.pas
  3. 6 6
      compiler/i386/ra386att.pas
  4. 5 5
      compiler/i386/ra386int.pas

+ 64 - 36
compiler/i386/cpubase.pas

@@ -123,14 +123,14 @@ uses
                   {Number of first and last imaginary register.}
                   {Number of first and last imaginary register.}
                   first_imreg     = $12;
                   first_imreg     = $12;
                   last_imreg      = $ff;
                   last_imreg      = $ff;
-                  
+
      {Sub register numbers:}
      {Sub register numbers:}
                   R_SUBL        = $00;      {Like AL}
                   R_SUBL        = $00;      {Like AL}
                   R_SUBH        = $01;      {Like AH}
                   R_SUBH        = $01;      {Like AH}
                   R_SUBW        = $02;      {Like AX}
                   R_SUBW        = $02;      {Like AX}
                   R_SUBD        = $03;      {Like EAX}
                   R_SUBD        = $03;      {Like EAX}
                   R_SUBQ        = $04;      {Like RAX}
                   R_SUBQ        = $04;      {Like RAX}
-                  
+
      {The subregister that specifies the entire register.}
      {The subregister that specifies the entire register.}
                   R_SUBWHOLE    = R_SUBD;  {i386}
                   R_SUBWHOLE    = R_SUBD;  {i386}
                   {R_SUBWHOLE    = R_SUBQ;} {Hammer}
                   {R_SUBWHOLE    = R_SUBQ;} {Hammer}
@@ -244,7 +244,7 @@ uses
         R_XMM0,R_XMM1,R_XMM2,R_XMM3,R_XMM4,R_XMM5,R_XMM6,R_XMM7,
         R_XMM0,R_XMM1,R_XMM2,R_XMM3,R_XMM4,R_XMM5,R_XMM6,R_XMM7,
         R_INTREGISTER,R_FLOATREGISTER,R_MMXREGISTER,R_KNIREGISTER
         R_INTREGISTER,R_FLOATREGISTER,R_MMXREGISTER,R_KNIREGISTER
       );
       );
-      
+
       type  Tnewregister=word;
       type  Tnewregister=word;
 
 
             Tregister = packed record
             Tregister = packed record
@@ -252,7 +252,7 @@ uses
               number:Tnewregister;  {This is a word for now, change to cardinal
               number:Tnewregister;  {This is a word for now, change to cardinal
                                      when the old register coding is away.}
                                      when the old register coding is away.}
             end;
             end;
-            
+
             Tsuperregister=byte;
             Tsuperregister=byte;
             Tsubregister=byte;
             Tsubregister=byte;
       {$packenum normal}
       {$packenum normal}
@@ -286,25 +286,6 @@ uses
       regset16bit : tregisterset = [R_AX..R_DI,R_CS..R_SS];
       regset16bit : tregisterset = [R_AX..R_DI,R_CS..R_SS];
       regset32bit : tregisterset = [R_EAX..R_EDI];
       regset32bit : tregisterset = [R_EAX..R_EDI];
 
 
-      { Convert reg to opsize }
-      reg2opsize : array[firstreg..lastreg] of topsize = (S_NO,
-        S_L,S_L,S_L,S_L,S_L,S_L,S_L,S_L,
-        S_W,S_W,S_W,S_W,S_W,S_W,S_W,S_W,
-        S_B,S_B,S_B,S_B,S_B,S_B,S_B,S_B,
-        S_W,S_W,S_W,S_W,S_W,S_W,
-        S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,
-        S_L,S_L,S_L,S_L,S_L,S_L,
-        S_L,S_L,S_L,S_L,
-        S_L,S_L,S_L,S_L,S_L,
-        S_D,S_D,S_D,S_D,S_D,S_D,S_D,S_D,
-        S_D,S_D,S_D,S_D,S_D,S_D,S_D,S_D
-      );
-      
-      {Converts subregister number to opsize}
-      subreg2opsize:array[0..4] of Topsize = (S_B,S_B,S_W,S_L,S_D);
-      {Converts subregister number to cgsize}
-{      subreg2cgsize:array[0..4] of Tcgsize = (OS_8,OS_8,OS_16,OS_32);}
-
       {# Standard opcode string table (for each tasmop enumeration). The
       {# Standard opcode string table (for each tasmop enumeration). The
          opcode strings should conform to the names as defined by the
          opcode strings should conform to the names as defined by the
          processor manufacturer.
          processor manufacturer.
@@ -336,7 +317,7 @@ uses
         'mm0','mm1','mm2','mm3','mm4','mm5','mm6','mm7',
         'mm0','mm1','mm2','mm3','mm4','mm5','mm6','mm7',
         'xmm0','xmm1','xmm2','xmm3','xmm4','xmm5','xmm6','xmm7'
         'xmm0','xmm1','xmm2','xmm3','xmm4','xmm5','xmm6','xmm7'
       );
       );
-      
+
 {*****************************************************************************
 {*****************************************************************************
                                 Conditions
                                 Conditions
 *****************************************************************************}
 *****************************************************************************}
@@ -548,12 +529,12 @@ uses
       mmregs = [R_MM0..R_MM7];
       mmregs = [R_MM0..R_MM7];
       usableregsmm = [R_MM0..R_MM7];
       usableregsmm = [R_MM0..R_MM7];
       c_countusableregsmm  = 8;
       c_countusableregsmm  = 8;
-      
+
       maxaddrregs = 0;
       maxaddrregs = 0;
       addrregs    = [];
       addrregs    = [];
       usableregsaddr = [];
       usableregsaddr = [];
       c_countusableregsaddr = 0;
       c_countusableregsaddr = 0;
-      
+
 
 
       firstsaveintreg = RS_EAX;
       firstsaveintreg = RS_EAX;
       lastsaveintreg  = RS_EDX;
       lastsaveintreg  = RS_EDX;
@@ -645,13 +626,13 @@ uses
       {the return_result_reg, is used inside the called function to store its return
       {the return_result_reg, is used inside the called function to store its return
       value when that is a scalar value otherwise a pointer to the address of the
       value when that is a scalar value otherwise a pointer to the address of the
       result is placed inside it}
       result is placed inside it}
-    	return_result_reg		=	accumulator;
+        return_result_reg               =       accumulator;
       RS_RETURN_RESULT_REG = RS_ACCUMULATOR;
       RS_RETURN_RESULT_REG = RS_ACCUMULATOR;
       NR_RETURN_RESULT_REG = NR_ACCUMULATOR;
       NR_RETURN_RESULT_REG = NR_ACCUMULATOR;
 
 
       {the function_result_reg contains the function result after a call to a scalar
       {the function_result_reg contains the function result after a call to a scalar
       function othewise it contains a pointer to the returned result}
       function othewise it contains a pointer to the returned result}
-    	function_result_reg	=	accumulator;
+        function_result_reg     =       accumulator;
       {# Hi-Results are returned in this register (64-bit value high register) }
       {# Hi-Results are returned in this register (64-bit value high register) }
       accumulatorhigh = R_EDX;
       accumulatorhigh = R_EDX;
       RS_ACCUMULATORHIGH  = RS_EDX;
       RS_ACCUMULATORHIGH  = RS_EDX;
@@ -693,6 +674,7 @@ uses
 
 
     procedure convert_register_to_enum(var r:Tregister);
     procedure convert_register_to_enum(var r:Tregister);
     function cgsize2subreg(s:Tcgsize):Tsubregister;
     function cgsize2subreg(s:Tcgsize):Tsubregister;
+    function reg2opsize(r:Tregister):topsize;
     function is_calljmp(o:tasmop):boolean;
     function is_calljmp(o:tasmop):boolean;
     function flags_to_cond(const f: TResFlags) : TAsmCond;
     function flags_to_cond(const f: TResFlags) : TAsmCond;
 
 
@@ -706,7 +688,7 @@ implementation
 *****************************************************************************}
 *****************************************************************************}
 
 
     procedure convert_register_to_enum(var r:Tregister);
     procedure convert_register_to_enum(var r:Tregister);
-    
+
     begin
     begin
       if r.enum=R_INTREGISTER then
       if r.enum=R_INTREGISTER then
         case r.number of
         case r.number of
@@ -730,9 +712,9 @@ implementation
           internalerror(200301082);
           internalerror(200301082);
         end;
         end;
     end;
     end;
-    
+
     function cgsize2subreg(s:Tcgsize):Tsubregister;
     function cgsize2subreg(s:Tcgsize):Tsubregister;
-    
+
     begin
     begin
       case s of
       case s of
         OS_8,OS_S8:
         OS_8,OS_S8:
@@ -747,16 +729,59 @@ implementation
           internalerror(200301231);
           internalerror(200301231);
       end;
       end;
     end;
     end;
-    
+
+
+    function reg2opsize(r:Tregister):topsize;
+      const
+        subreg2opsize : array[0..4] of Topsize = (S_B,S_B,S_W,S_L,S_D);
+
+        enum2opsize : array[firstreg..lastreg] of topsize = (S_NO,
+          S_L,S_L,S_L,S_L,S_L,S_L,S_L,S_L,
+          S_W,S_W,S_W,S_W,S_W,S_W,S_W,S_W,
+          S_B,S_B,S_B,S_B,S_B,S_B,S_B,S_B,
+          S_W,S_W,S_W,S_W,S_W,S_W,
+          S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,S_FL,
+          S_L,S_L,S_L,S_L,S_L,S_L,
+          S_L,S_L,S_L,S_L,
+          S_L,S_L,S_L,S_L,S_L,
+          S_D,S_D,S_D,S_D,S_D,S_D,S_D,S_D,
+          S_D,S_D,S_D,S_D,S_D,S_D,S_D,S_D
+        );
+      begin
+        reg2opsize:=S_L;
+        if (r.enum=R_INTREGISTER) then
+         begin
+           if (r.number shr 8)=0 then
+            begin
+              case r.number of
+                NR_CS,NR_DS,NR_ES,
+                NR_SS,NR_FS,NR_GS :
+                  reg2opsize:=S_W;
+              end;
+            end
+           else
+            begin
+              if (r.number and $ff)>4 then
+                internalerror(200303181);
+              reg2opsize:=subreg2opsize[r.number and $ff];
+            end;
+         end
+        else
+         begin
+           reg2opsize:=enum2opsize[r.enum];
+         end;
+      end;
+
+
     function supreg_name(r:Tsuperregister):string;
     function supreg_name(r:Tsuperregister):string;
-    
+
     var s:string[4];
     var s:string[4];
-    
+
     const supreg_names:array[0..last_supreg] of string[4]=
     const supreg_names:array[0..last_supreg] of string[4]=
           ('INV',
           ('INV',
            'eax','ebx','ecx','edx','esi','edi','ebp','esp',
            'eax','ebx','ecx','edx','esi','edi','ebp','esp',
            'r8' ,'r9', 'r10','r11','r12','r13','r14','r15');
            'r8' ,'r9', 'r10','r11','r12','r13','r14','r15');
-    
+
     begin
     begin
       if r in [0..last_supreg] then
       if r in [0..last_supreg] then
         supreg_name:=supreg_names[r]
         supreg_name:=supreg_names[r]
@@ -799,7 +824,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.43  2003-03-08 08:59:07  daniel
+  Revision 1.44  2003-03-18 18:15:53  peter
+    * changed reg2opsize to function
+
+  Revision 1.43  2003/03/08 08:59:07  daniel
     + $define newra will enable new register allocator
     + $define newra will enable new register allocator
     + getregisterint will return imaginary registers with $newra
     + getregisterint will return imaginary registers with $newra
     + -sr switch added, will skip register allocation so you can see
     + -sr switch added, will skip register allocation so you can see

+ 6 - 3
compiler/i386/csopt386.pas

@@ -1830,7 +1830,7 @@ Begin
                                 begin
                                 begin
                                   hp1 := Tai_Marker.Create(NoPropInfoEnd);
                                   hp1 := Tai_Marker.Create(NoPropInfoEnd);
                                   insertllitem(asml,p,p.next,hp1);
                                   insertllitem(asml,p,p.next,hp1);
-                                  hp1 := taicpu.op_reg_ref(A_MOV,reg2opsize[regcounter.enum],
+                                  hp1 := taicpu.op_reg_ref(A_MOV,reg2opsize(regcounter),
                                      regcounter,taicpu(p).oper[0].ref^);
                                      regcounter,taicpu(p).oper[0].ref^);
                                   new(pTaiprop(hp1.optinfo));
                                   new(pTaiprop(hp1.optinfo));
                                   pTaiProp(hp1.optinfo)^ := pTaiProp(p.optinfo)^;
                                   pTaiProp(hp1.optinfo)^ := pTaiProp(p.optinfo)^;
@@ -1882,7 +1882,7 @@ Begin
                                 begin
                                 begin
                                   hp1 := Tai_Marker.Create(NoPropInfoEnd);
                                   hp1 := Tai_Marker.Create(NoPropInfoEnd);
                                   insertllitem(asml,p,p.next,hp1);
                                   insertllitem(asml,p,p.next,hp1);
-                                  hp1 := taicpu.op_reg_ref(A_MOV,reg2opsize[regcounter.enum],
+                                  hp1 := taicpu.op_reg_ref(A_MOV,reg2opsize(regcounter),
                                     regcounter,taicpu(p).oper[1].ref^);
                                     regcounter,taicpu(p).oper[1].ref^);
                                   new(pTaiprop(hp1.optinfo));
                                   new(pTaiprop(hp1.optinfo));
                                   pTaiProp(hp1.optinfo)^ := pTaiProp(p.optinfo)^;
                                   pTaiProp(hp1.optinfo)^ := pTaiProp(p.optinfo)^;
@@ -1999,7 +1999,10 @@ End.
 
 
 {
 {
   $Log$
   $Log$
-  Revision 1.41  2003-02-26 21:15:43  daniel
+  Revision 1.42  2003-03-18 18:15:53  peter
+    * changed reg2opsize to function
+
+  Revision 1.41  2003/02/26 21:15:43  daniel
     * Fixed the optimizer
     * Fixed the optimizer
 
 
   Revision 1.40  2003/02/19 22:00:15  daniel
   Revision 1.40  2003/02/19 22:00:15  daniel

+ 6 - 6
compiler/i386/ra386att.pas

@@ -1442,7 +1442,7 @@ Begin
            opr.reg:=actasmregister;
            opr.reg:=actasmregister;
            if opr.reg.enum<>R_INTREGISTER then
            if opr.reg.enum<>R_INTREGISTER then
              internalerror(200302023);
              internalerror(200302023);
-           size:=subreg2opsize[actasmregister.number and $ff];
+           size:=reg2opsize(actasmregister);
            Consume(AS_REGISTER);
            Consume(AS_REGISTER);
          end
          end
         else
         else
@@ -1595,10 +1595,7 @@ Begin
              Message(asmr_e_invalid_operand_type);
              Message(asmr_e_invalid_operand_type);
            opr.typ:=OPR_REGISTER;
            opr.typ:=OPR_REGISTER;
            opr.reg:=tempreg;
            opr.reg:=tempreg;
-           if opr.reg.enum=R_INTREGISTER then
-              size:=subreg2opsize[opr.reg.number and $ff]
-           else
-              size:=reg2opsize[opr.reg.enum];
+           size:=reg2opsize(opr.reg);
          end
          end
         else
         else
          Message(asmr_e_syn_operand);
          Message(asmr_e_syn_operand);
@@ -2138,7 +2135,10 @@ finalization
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.39  2003-02-20 15:52:58  pierre
+  Revision 1.40  2003-03-18 18:15:53  peter
+    * changed reg2opsize to function
+
+  Revision 1.39  2003/02/20 15:52:58  pierre
    * fix a range check error
    * fix a range check error
 
 
   Revision 1.38  2003/02/19 22:00:16  daniel
   Revision 1.38  2003/02/19 22:00:16  daniel

+ 5 - 5
compiler/i386/ra386int.pas

@@ -1584,10 +1584,7 @@ Begin
             Message(asmr_e_invalid_operand_type);
             Message(asmr_e_invalid_operand_type);
            opr.typ:=OPR_REGISTER;
            opr.typ:=OPR_REGISTER;
            opr.reg:=tempreg;
            opr.reg:=tempreg;
-           if opr.reg.enum=R_INTREGISTER then
-              size:=subreg2opsize[opr.reg.number and $ff]
-           else
-              size:=reg2opsize[opr.reg.enum];
+           size:=reg2opsize(opr.reg)
          end;
          end;
       end;
       end;
 
 
@@ -1983,7 +1980,10 @@ finalization
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.42  2003-03-17 21:32:52  peter
+  Revision 1.43  2003-03-18 18:15:53  peter
+    * changed reg2opsize to function
+
+  Revision 1.42  2003/03/17 21:32:52  peter
     * allow character constants in reference declaration
     * allow character constants in reference declaration
 
 
   Revision 1.41  2003/02/26 22:57:44  daniel
   Revision 1.41  2003/02/26 22:57:44  daniel