瀏覽代碼

* fix alignment of tdoublearray by using a variant record

git-svn-id: trunk@3071 -
peter 19 年之前
父節點
當前提交
ecdb5df2d6
共有 5 個文件被更改,包括 42 次插入33 次删除
  1. 4 4
      compiler/arm/narmcon.pas
  2. 17 17
      compiler/globals.pas
  3. 11 2
      compiler/globtype.pas
  4. 4 4
      compiler/ncgcon.pas
  5. 6 6
      compiler/ninl.pas

+ 4 - 4
compiler/arm/narmcon.pas

@@ -81,7 +81,7 @@ interface
                   { range checking? }
                   if ((cs_check_range in aktlocalswitches) or
                     (cs_check_overflow in aktlocalswitches)) and
-                    (tai_real_32bit(current_asmdata.asmlists[al_typedconsts].last).value=double(MathInf)) then
+                    (tai_real_32bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
                     Message(parser_e_range_check_error);
                 end;
 
@@ -95,7 +95,7 @@ interface
                   { range checking? }
                   if ((cs_check_range in aktlocalswitches) or
                     (cs_check_overflow in aktlocalswitches)) and
-                    (tai_real_64bit(current_asmdata.asmlists[al_typedconsts].last).value=double(MathInf)) then
+                    (tai_real_64bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
                     Message(parser_e_range_check_error);
                end;
 
@@ -106,7 +106,7 @@ interface
                   { range checking? }
                   if ((cs_check_range in aktlocalswitches) or
                     (cs_check_overflow in aktlocalswitches)) and
-                    (tai_real_80bit(current_asmdata.asmlists[al_typedconsts].last).value=double(MathInf)) then
+                    (tai_real_80bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
                     Message(parser_e_range_check_error);
                 end;
 {$ifdef cpufloat128}
@@ -117,7 +117,7 @@ interface
                   { range checking? }
                   if ((cs_check_range in aktlocalswitches) or
                     (cs_check_overflow in aktlocalswitches)) and
-                    (tai_real_128bit(current_asmdata.asmlists[al_typedconsts].last).value=double(MathInf)) then
+                    (tai_real_128bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
                     Message(parser_e_range_check_error);
                 end;
 {$endif cpufloat128}

+ 17 - 17
compiler/globals.pas

@@ -80,23 +80,23 @@ interface
        treelogfilename = 'tree.log';
 
 {$if defined(CPUARM) and defined(FPUFPA)}
-       MathQNaN : tdoublearray = (0,0,252,255,0,0,0,0);
-       MathInf : tdoublearray = (0,0,240,127,0,0,0,0);
-       MathNegInf : tdoublearray = (0,0,240,255,0,0,0,0);
-       MathPi : tdoublearray =  (251,33,9,64,24,45,68,84);
+       MathQNaN : tdoublerec = (bytes : (0,0,252,255,0,0,0,0));
+       MathInf : tdoublerec = (bytes : (0,0,240,127,0,0,0,0));
+       MathNegInf : tdoublerec = (bytes : (0,0,240,255,0,0,0,0));
+       MathPi : tdoublerec =  (bytes : (251,33,9,64,24,45,68,84));
 {$else}
 {$ifdef FPC_LITTLE_ENDIAN}
-       MathQNaN : tdoublearray = (0,0,0,0,0,0,252,255);
-       MathInf : tdoublearray = (0,0,0,0,0,0,240,127);
-       MathNegInf : tdoublearray = (0,0,0,0,0,0,240,255);
-       MathPi : tdoublearray =  (24,45,68,84,251,33,9,64);
-       MathPiExtended : textendedarray = (53,194,104,33,162,218,15,201,0,64);
+       MathQNaN : tdoublerec = (bytes : (0,0,0,0,0,0,252,255));
+       MathInf : tdoublerec = (bytes : (0,0,0,0,0,0,240,127));
+       MathNegInf : tdoublerec = (bytes : (0,0,0,0,0,0,240,255));
+       MathPi : tdoublerec = (bytes : (24,45,68,84,251,33,9,64));
+       MathPiExtended : textendedrec = (bytes : (53,194,104,33,162,218,15,201,0,64));
 {$else FPC_LITTLE_ENDIAN}
-       MathQNaN : tdoublearray = (255,252,0,0,0,0,0,0);
-       MathInf : tdoublearray = (127,240,0,0,0,0,0,0);
-       MathNegInf : tdoublearray = (255,240,0,0,0,0,0,0);
-       MathPi : tdoublearray =  (64,9,33,251,84,68,45,24);
-       MathPiExtended : textendedarray = (64,0,201,15,218,162,33,104,194,53);
+       MathQNaN : tdoublerec = (bytes : (255,252,0,0,0,0,0,0));
+       MathInf : tdoublerec = (bytes : (127,240,0,0,0,0,0,0));
+       MathNegInf : tdoublerec = (bytes : (255,240,0,0,0,0,0,0));
+       MathPi : tdoublerec =  (bytes : (64,9,33,251,84,68,45,24));
+       MathPiExtended : textendedrec = (bytes : (64,0,201,15,218,162,33,104,194,53));
 {$endif FPC_LITTLE_ENDIAN}
 {$endif}
 
@@ -1858,15 +1858,15 @@ end;
           result := -1;
       end;
 
-    function convertdoublearray(d : tdoublearray) : tdoublearray;{$ifdef USEINLINE}inline;{$endif}
+    function convertdoublerec(d : tdoublerec) : tdoublerec;{$ifdef USEINLINE}inline;{$endif}
 {$ifdef CPUARM}
       var
         i : longint;
       begin
         for i:=0 to 3 do
           begin
-            result[i+4]:=d[i];
-            result[i]:=d[i+4];
+            result.bytes[i+4]:=d.bytes[i];
+            result.bytes[i]:=d.bytes[i+4];
           end;
 {$else CPUARM}
       begin

+ 11 - 2
compiler/globtype.pas

@@ -67,8 +67,17 @@ than 255 characters. That's why using Ansi Strings}
          int64 constants internally (JM) }
        TConstPtrUInt = AWord;
 
-       tdoublearray = array[0..7] of byte;
-       textendedarray = array[0..9] of byte;
+       { Use a variant record to be sure that the array if aligned correctly }
+       tdoublerec=record
+         case byte of
+           0 : (bytes:array[0..7] of byte);
+           1 : (value:double);
+       end;
+       textendedrec=record
+         case byte of
+           0 : (bytes:array[0..9] of byte);
+           1 : (value:extended);
+       end;
 
        pconstset = ^tconstset;
        tconstset = set of 0..255;

+ 4 - 4
compiler/ncgcon.pas

@@ -148,7 +148,7 @@ implementation
                         { range checking? }
                         if ((cs_check_range in aktlocalswitches) or
                           (cs_check_overflow in aktlocalswitches)) and
-                          (tai_real_32bit(current_asmdata.asmlists[al_typedconsts].last).value=double(MathInf)) then
+                          (tai_real_32bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
                           Message(parser_e_range_check_error);
                       end;
 
@@ -164,7 +164,7 @@ implementation
                         { range checking? }
                         if ((cs_check_range in aktlocalswitches) or
                           (cs_check_overflow in aktlocalswitches)) and
-                          (tai_real_64bit(current_asmdata.asmlists[al_typedconsts].last).value=double(MathInf)) then
+                          (tai_real_64bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
                           Message(parser_e_range_check_error);
                      end;
 
@@ -175,7 +175,7 @@ implementation
                         { range checking? }
                         if ((cs_check_range in aktlocalswitches) or
                           (cs_check_overflow in aktlocalswitches)) and
-                          (tai_real_80bit(current_asmdata.asmlists[al_typedconsts].last).value=double(MathInf)) then
+                          (tai_real_80bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
                           Message(parser_e_range_check_error);
                       end;
 {$ifdef cpufloat128}
@@ -186,7 +186,7 @@ implementation
                         { range checking? }
                         if ((cs_check_range in aktlocalswitches) or
                           (cs_check_overflow in aktlocalswitches)) and
-                          (tai_real_128bit(current_asmdata.asmlists[al_typedconsts].last).value=double(MathInf)) then
+                          (tai_real_128bit(current_asmdata.asmlists[al_typedconsts].last).value=MathInf.Value) then
                           Message(parser_e_range_check_error);
                       end;
 {$endif cpufloat128}

+ 6 - 6
compiler/ninl.pas

@@ -1085,9 +1085,9 @@ implementation
         result:=pi;
       {$else x86}
         {$ifdef cpuextended}
-          result:=extended(MathPiExtended);
+          result:=MathPiExtended.Value;
         {$else cpuextended}
-          result:=double(MathPi);
+          result:=MathPi.Value;
         {$endif cpuextended}
       {$endif x86}
       end;
@@ -1189,9 +1189,9 @@ implementation
               else
                 begin
                   if r=0.0 then
-                    result:=crealconstnode.create(double(MathQNaN),pbestrealtype^)
+                    result:=crealconstnode.create(MathQNaN.Value,pbestrealtype^)
                   else
-                    result:=crealconstnode.create(double(MathNegInf),pbestrealtype^)
+                    result:=crealconstnode.create(MathNegInf.Value,pbestrealtype^)
                 end
             else
               result:=crealconstnode.create(ln(r),pbestrealtype^)
@@ -1208,7 +1208,7 @@ implementation
                    CGMessage(type_e_wrong_math_argument)
                  end
               else
-                result:=crealconstnode.create(double(MathQNaN),pbestrealtype^)
+                result:=crealconstnode.create(MathQNaN.Value,pbestrealtype^)
             else
               result:=crealconstnode.create(sqrt(r),pbestrealtype^)
           end;
@@ -1828,7 +1828,7 @@ implementation
                   if left.nodetype in [ordconstn,realconstn] then
                     begin
                       result:=crealconstnode.create(exp(getconstrealvalue),pbestrealtype^);
-                      if (trealconstnode(result).value_real=double(MathInf)) and
+                      if (trealconstnode(result).value_real=MathInf.Value) and
                          ((cs_check_range in aktlocalswitches) or
                           (cs_check_overflow in aktlocalswitches)) then
                         begin