mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 16:19:21 +02:00
* attempt to fix bitpacked records with qwords in them (tw36156) when cross-compiling to big endian targets from x86. essentially the x86 shifting workarounds in the code already weren't covering all corner cases.
git-svn-id: trunk@48773 -
This commit is contained in:
parent
6beb28316e
commit
0ca1e2fb42
@ -328,6 +328,25 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
|
|||||||
{$push}
|
{$push}
|
||||||
{$r-}
|
{$r-}
|
||||||
{$q-}
|
{$q-}
|
||||||
|
{ to work around broken x86 shifting, while generating bitmask }
|
||||||
|
function getbitmask(len: byte): aword;
|
||||||
|
begin
|
||||||
|
if len >= (sizeof(result) * 8) then
|
||||||
|
result:=0
|
||||||
|
else
|
||||||
|
result:=aword(1) shl len;
|
||||||
|
result:=aword(result-1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ shift left, and always pad the right bits with zeroes }
|
||||||
|
function shiftleft(value: aword; count: byte): aword;
|
||||||
|
begin
|
||||||
|
if count >= (sizeof(result) * 8) then
|
||||||
|
result:=0
|
||||||
|
else
|
||||||
|
result:=(value shl count) and (not getbitmask(count));
|
||||||
|
end;
|
||||||
|
|
||||||
{ (values between quotes below refer to fields of bp; fields not }
|
{ (values between quotes below refer to fields of bp; fields not }
|
||||||
{ mentioned are unused by this routine) }
|
{ mentioned are unused by this routine) }
|
||||||
{ bitpacks "value" as bitpacked value of bitsize "packedbitsize" into }
|
{ bitpacks "value" as bitpacked value of bitsize "packedbitsize" into }
|
||||||
@ -342,16 +361,15 @@ function get_next_varsym(def: tabstractrecorddef; const SymList:TFPHashObjectLis
|
|||||||
if (target_info.endian=endian_big) then
|
if (target_info.endian=endian_big) then
|
||||||
begin
|
begin
|
||||||
{ bitpacked format: left-aligned (i.e., "big endian bitness") }
|
{ bitpacked format: left-aligned (i.e., "big endian bitness") }
|
||||||
{ work around broken x86 shifting }
|
if (bp.packedbitsize<AIntBits) and
|
||||||
if (AIntBits<>bp.packedbitsize) and
|
|
||||||
(bp.curbitoffset<AIntBits) then
|
(bp.curbitoffset<AIntBits) then
|
||||||
bp.curval:=bp.curval or ((value shl (AIntBits-bp.packedbitsize)) shr bp.curbitoffset);
|
bp.curval:=bp.curval or (shiftleft(value,AIntBits-bp.packedbitsize) shr bp.curbitoffset);
|
||||||
shiftcount:=((AIntBits-bp.packedbitsize)-bp.curbitoffset);
|
shiftcount:=((AIntBits-bp.packedbitsize)-bp.curbitoffset);
|
||||||
{ carry-over to the next element? }
|
{ carry-over to the next element? }
|
||||||
if (shiftcount<0) then
|
if (shiftcount<0) then
|
||||||
begin
|
begin
|
||||||
if shiftcount>=-AIntBits then
|
if shiftcount>=-AIntBits then
|
||||||
bp.nextval:=(value and ((aword(1) shl (-shiftcount))-1)) shl
|
bp.nextval:=(value and getbitmask(-shiftcount)) shl
|
||||||
(AIntBits+shiftcount)
|
(AIntBits+shiftcount)
|
||||||
else
|
else
|
||||||
bp.nextval:=0;
|
bp.nextval:=0;
|
||||||
|
Loading…
Reference in New Issue
Block a user