* 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:
Jonas Maebe 2008-01-07 21:41:12 +00:00
parent 6dd8e51ee5
commit bf9b021749
3 changed files with 32 additions and 8 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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;

View 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.