[fpc-pascal] LZMA Algorithm fails on 64bit

Jonas Maebe jonas.maebe at elis.ugent.be
Mon Jan 25 14:02:14 CET 2010


On 25 Jan 2010, at 13:29, Matthias Klumpp wrote:

> 
>> I think the code there is currently actually only correct on 64 bit
>> platforms and wrong on 32 bit platforms: it seems that it should read an
>> int64 in little endian format and converts it on-the-fly to the native
>> endianess, but that currently only happens correctly on 64 bit platforms.
>> I
>> was also wrong about what it does on 32 bit platforms, because that
>> depends
>> on the used architecture. On PowerPC, it will indeed throw away the upper
>> 32 bits as I described above. On i386, it will however result in
>> something
>> like "v shl ((8 *i) and 31)".
> I checked it: The old version and your code produce exactly the same value
> on 64bit and 32bit. There is no difference between both results.

Strange, apparently shl/shr are not automatically changed to 64 bit when compiling for a 64 bit platform. I don't know why that is the case.

You can force a 64 bit shift by typecasting v to int64.

>> I don't think there is a quick fix. Someone who knows what is going on
>> has
>> to go through it and properly fix it. Hacking the code you posted will
>> only
>> result in hiding a bug, and you will probably still get more errors
>> elsewhere.
> The problem is that no Pascal developer knows this code. It was translated
> from Java code.

At least the person who translated it supposedly knows it. Otherwise, you have to go back to the Java code and look how it does things.

> Can you imagine another difference between 64bit and 32bit which may cause
> those error? The bitshifts result in the same value on 32bit and 64bit...

There are probably other places where an automatic upcast to 64 bit does take place (it happens for all add/sub/div/mod operations at least).


Jonas


More information about the fpc-pascal mailing list