mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 02:19:27 +02:00
* patch by Rika: another improvement of cutils.newalignment, part of #39496
This commit is contained in:
parent
c0979bbc0c
commit
abc4a0a4e6
@ -295,11 +295,13 @@ implementation
|
|||||||
function newalignment(oldalignment: longint; offset: int64): longint;
|
function newalignment(oldalignment: longint; offset: int64): longint;
|
||||||
begin
|
begin
|
||||||
{ oldalignment must be power of two.
|
{ oldalignment must be power of two.
|
||||||
Works even for negative offsets (but not alignments),
|
|
||||||
as two's complement of, say, 2^4+2^3 is 11000 and -2^4-2^3 is 11...1101000 -
|
Negating two's complement number keeps its tail '100...000' and complements all bits above.
|
||||||
both end with exactly N zeros, where N is the largest power of two that divides the number
|
"x and -x" extracts this tail of 'x'.
|
||||||
(smallest power of two involved in these sums). }
|
Said tail of "oldalignment or offset" is the desired answer. }
|
||||||
result:=1 shl BsfQWord(qword(offset or oldalignment));
|
|
||||||
|
result:=oldalignment or longint(offset); { high part of offset won't matter as long as alignment is 32-bit }
|
||||||
|
result:=result and -result;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user