mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 12:19:18 +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;
|
||||
begin
|
||||
{ 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 -
|
||||
both end with exactly N zeros, where N is the largest power of two that divides the number
|
||||
(smallest power of two involved in these sums). }
|
||||
result:=1 shl BsfQWord(qword(offset or oldalignment));
|
||||
|
||||
Negating two's complement number keeps its tail '100...000' and complements all bits above.
|
||||
"x and -x" extracts this tail of 'x'.
|
||||
Said tail of "oldalignment or offset" is the desired answer. }
|
||||
|
||||
result:=oldalignment or longint(offset); { high part of offset won't matter as long as alignment is 32-bit }
|
||||
result:=result and -result;
|
||||
end;
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user