mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 17:49:13 +02:00
* x86: Fixed bug where the magic number of an integer division wasn't fully sign-extended, causing incorrect logic within the compiler.
This commit is contained in:
parent
9ad1995c6d
commit
32f4931fd2
@ -408,7 +408,7 @@ uses
|
||||
{$r-,q-}
|
||||
procedure calc_divconst_magic_signed(N: byte; d: aInt; out magic_m: aInt; out magic_s: byte);
|
||||
var
|
||||
p: aInt;
|
||||
p, sign_corrective_shift: aInt;
|
||||
ad,anc,delta,q1,r1,q2,r2,t: aWord;
|
||||
two_N_minus_1: aWord;
|
||||
begin
|
||||
@ -441,7 +441,16 @@ uses
|
||||
end;
|
||||
delta:=ad-r2;
|
||||
until not ((q1<delta) or ((q1=delta) and (r1=0)));
|
||||
|
||||
magic_m:=q2+1;
|
||||
|
||||
{ Sign-extend magic_m to the full size of aint - fixes #39834 }
|
||||
if N < (SizeOf(aint) * 8) then
|
||||
begin
|
||||
sign_corrective_shift := (SizeOf(aint) * 8) - N;
|
||||
magic_m := SarInt64(magic_m shl sign_corrective_shift, sign_corrective_shift);
|
||||
end;
|
||||
|
||||
if (d<0) then
|
||||
magic_m:=-magic_m; { resulting magic number }
|
||||
magic_s:=p-N; { resulting shift }
|
||||
|
Loading…
Reference in New Issue
Block a user