From b43b4bb4552eff5bc2ecc8542890af4f3df0a8f7 Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 4 Jan 2013 19:13:24 +0000 Subject: [PATCH] + pseudo procedure aligned: tells the compiler to assume that the given parameter is naturally aligned, counterpart of unaligned git-svn-id: trunk@23310 - --- .gitattributes | 1 + compiler/compinnr.inc | 1 + compiler/htypechk.pas | 2 +- compiler/ncginl.pas | 7 +++++++ compiler/ninl.pas | 3 ++- compiler/nutils.pas | 1 + compiler/pexpr.pas | 3 ++- compiler/psystem.pas | 1 + tests/test/taligned1.pp | 12 ++++++++++++ 9 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 tests/test/taligned1.pp diff --git a/.gitattributes b/.gitattributes index f392e43c37..4bdfa186bb 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/compinnr.inc b/compiler/compinnr.inc index d1cdc124aa..0d70d45676 100644 --- a/compiler/compinnr.inc +++ b/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; diff --git a/compiler/htypechk.pas b/compiler/htypechk.pas index ec713f8115..284dd46d39 100644 --- a/compiler/htypechk.pas +++ b/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 diff --git a/compiler/ncginl.pas b/compiler/ncginl.pas index 06899d684f..60f76dc6a2 100644 --- a/compiler/ncginl.pas +++ b/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 diff --git a/compiler/ninl.pas b/compiler/ninl.pas index 374f7d8c90..08d5f49415 100644 --- a/compiler/ninl.pas +++ b/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; diff --git a/compiler/nutils.pas b/compiler/nutils.pas index b112be3395..d8d2757d90 100644 --- a/compiler/nutils.pas +++ b/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 diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 8e298d1d44..8ee1de9ce4 100644 --- a/compiler/pexpr.pas +++ b/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; diff --git a/compiler/psystem.pas b/compiler/psystem.pas index 0333b95314..50eb82712c 100644 --- a/compiler/psystem.pas +++ b/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)); diff --git a/tests/test/taligned1.pp b/tests/test/taligned1.pp new file mode 100644 index 0000000000..f4cb434f49 --- /dev/null +++ b/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.