Browse Source

+ pseudo procedure aligned: tells the compiler to assume that the given parameter is naturally aligned, counterpart of unaligned

git-svn-id: trunk@23310 -
florian 12 years ago
parent
commit
b43b4bb455

+ 1 - 0
.gitattributes

@@ -10505,6 +10505,7 @@ tests/test/taes1.pp svneol=native#text/plain
 tests/test/talign.pp svneol=native#text/plain
 tests/test/talign1.pp svneol=native#text/plain
 tests/test/talign2.pp svneol=native#text/plain
+tests/test/taligned1.pp svneol=native#text/pascal
 tests/test/targ1a.pp svneol=native#text/plain
 tests/test/targ1b.pp svneol=native#text/plain
 tests/test/tarray1.pp svneol=native#text/plain

+ 1 - 0
compiler/compinnr.inc

@@ -87,6 +87,7 @@ const
    in_box_x             = 77; { managed platforms: wrap in class instance }
    in_unbox_x_y         = 78; { manage platforms: extract from class instance }
    in_popcnt_x          = 79;
+   in_aligned_x         = 80;
 
 { Internal constant functions }
    in_const_sqr        = 100;

+ 1 - 1
compiler/htypechk.pas

@@ -1761,7 +1761,7 @@ implementation
                begin
                  if ((valid_const in opts) and
                      (tinlinenode(hp).inlinenumber in [in_typeof_x])) or
-                    (tinlinenode(hp).inlinenumber in [in_unaligned_x]) then
+                    (tinlinenode(hp).inlinenumber in [in_unaligned_x,in_aligned_x]) then
                    result:=true
                  else
                    if report_errors then

+ 7 - 0
compiler/ncginl.pas

@@ -144,6 +144,13 @@ implementation
                 if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
                   location.reference.alignment:=1;
               end;
+            in_aligned_x:
+              begin
+                secondpass(tcallparanode(left).left);
+                location:=tcallparanode(left).left.location;
+                if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
+                  location.reference.alignment:=0;
+              end;
 {$ifdef SUPPORT_MMX}
             in_mmx_pcmpeqb..in_mmx_pcmpgtw:
               begin

+ 2 - 1
compiler/ninl.pas

@@ -2998,6 +2998,7 @@ implementation
                 begin
                 end;
 {$endif SUPPORT_MMX}
+              in_aligned_x,
               in_unaligned_x:
                 begin
                   resultdef:=left.resultdef;
@@ -3472,11 +3473,11 @@ implementation
             begin
               expectloc:=LOC_REGISTER;
             end;
-
          in_prefetch_var:
            begin
              expectloc:=LOC_VOID;
            end;
+         in_aligned_x,
          in_unaligned_x:
            begin
              expectloc:=tcallparanode(left).left.expectloc;

+ 1 - 0
compiler/nutils.pas

@@ -683,6 +683,7 @@ implementation
                     in_sqr_real,
                     in_sqrt_real,
                     in_ln_real,
+                    in_aligned_x,
                     in_unaligned_x,
                     in_prefetch_var:
                       begin

+ 2 - 1
compiler/pexpr.pas

@@ -517,6 +517,7 @@ implementation
                 end;
             end;
 
+          in_aligned_x,
           in_unaligned_x :
             begin
               err:=false;
@@ -524,7 +525,7 @@ implementation
               in_args:=true;
               p1:=comp_expr(true,false);
               p2:=ccallparanode.create(p1,nil);
-              p2:=geninlinenode(in_unaligned_x,false,p2);
+              p2:=geninlinenode(l,false,p2);
               consume(_RKLAMMER);
               statement_syssym:=p2;
             end;

+ 1 - 0
compiler/psystem.pas

@@ -100,6 +100,7 @@ implementation
         systemunit.insert(tsyssym.create('Get_Frame',in_get_frame));
 {$endif defined(x86) or defined(arm) or defined(jvm)}
         systemunit.insert(tsyssym.create('Unaligned',in_unaligned_x));
+        systemunit.insert(tsyssym.create('Aligned',in_aligned_x));
         systemunit.insert(tsyssym.create('ObjCSelector',in_objc_selector_x)); { objc only }
         systemunit.insert(tsyssym.create('ObjCEncode',in_objc_encode_x)); { objc only }
         systemunit.insert(tsyssym.create('Default',in_default_x));

+ 12 - 0
tests/test/taligned1.pp

@@ -0,0 +1,12 @@
+var
+  r1 : record
+    dummy : byte;
+    a,b : longint;
+  end;
+
+begin
+  r1.a:=aligned(r1.b)*2;
+  aligned(r1.a):=r1.b*2;
+  r1.a:=r1.b;
+  r1.a:=r1.b div 10;
+end.