mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 20:29:32 +02:00
* optimized align() so it no longer contains any branches which
are undecidable at compile time + basic test for align() function git-svn-id: trunk@9674 -
This commit is contained in:
parent
6dd8e51ee5
commit
bf9b021749
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -7355,6 +7355,7 @@ tests/test/units/strings/tstrcopy.pp svneol=native#text/plain
|
||||
tests/test/units/strings/tstrings1.pp svneol=native#text/plain
|
||||
tests/test/units/system/interlocked1.pp svneol=native#text/plain
|
||||
tests/test/units/system/tabs.pp svneol=native#text/plain
|
||||
tests/test/units/system/talign.pp svneol=native#text/plain
|
||||
tests/test/units/system/targs.pp svneol=native#text/plain
|
||||
tests/test/units/system/tassert1.pp svneol=native#text/plain
|
||||
tests/test/units/system/tassert2.pp svneol=native#text/plain
|
||||
|
@ -1507,20 +1507,20 @@ procedure inclocked(var l:int64);
|
||||
|
||||
|
||||
function align(addr : PtrUInt;alignment : PtrUInt) : PtrUInt;{$ifdef SYSTEMINLINE}inline;{$endif}
|
||||
var
|
||||
tmp: PtrUInt;
|
||||
begin
|
||||
if addr mod alignment<>0 then
|
||||
result:=addr+(alignment-(addr mod alignment))
|
||||
else
|
||||
result:=addr;
|
||||
tmp:=addr+alignment-1;
|
||||
result:=tmp-(tmp mod alignment)
|
||||
end;
|
||||
|
||||
|
||||
function align(addr : Pointer;alignment : PtrUInt) : Pointer;{$ifdef SYSTEMINLINE}inline;{$endif}
|
||||
var
|
||||
tmp: PtrUInt;
|
||||
begin
|
||||
if PtrUInt(addr) mod alignment<>0 then
|
||||
result:=pointer(addr+(alignment-(PtrUInt(addr) mod alignment)))
|
||||
else
|
||||
result:=addr;
|
||||
tmp:=PtrUInt(addr)+alignment-1;
|
||||
result:=pointer(tmp-(tmp mod alignment));
|
||||
end;
|
||||
|
||||
|
||||
|
23
tests/test/units/system/talign.pp
Normal file
23
tests/test/units/system/talign.pp
Normal file
@ -0,0 +1,23 @@
|
||||
var
|
||||
p: pointer;
|
||||
u: ptruint;
|
||||
i: cardinal;
|
||||
begin
|
||||
p:=pointer(1);
|
||||
for i:=0 to 15 do
|
||||
if align(p+i,16)<>pointer(16) then
|
||||
halt(1);
|
||||
p:=pointer(41);
|
||||
for i:=0 to 39 do
|
||||
if align(p+i,40)<>pointer(80) then
|
||||
halt(2);
|
||||
|
||||
u:=1;
|
||||
for i:=0 to 15 do
|
||||
if align(u+i,16)<>16 then
|
||||
halt(3);
|
||||
u:=41;
|
||||
for i:=0 to 39 do
|
||||
if align(u+i,40)<>80 then
|
||||
halt(4);
|
||||
end.
|
Loading…
Reference in New Issue
Block a user