64bit compiler causes SHR to work incorrectly on 32bit variables
Original Reporter info from Mantis: tk
-
Reporter name: TK
Original Reporter info from Mantis: tk
- Reporter name: TK
Description:
I discovered this problem when compiling pascal LZMA port with 64 bit compiler. The decode function didn't work.
The encode function works.
Steps to reproduce:
Excerpt from the critical place in URangeDecoder.pas converted to a simple program:
program test;
var t, Code, Range:LongInt;
begin
Code := $80883A;
Range := $B2CB00;
t := ((Code - Range) shr 31);
end.
Under 32bit compiler t is 1.
Under 64bit compiler t is -1, but should be 1 as well.
Additional information:
32 bit compiler compiles
080A7F11 c1e81f shr $0x1f,%eax
64 bit compiler compiles
000000000047968A 48c1e81f shr $0x1f,%rax
this takes ones from the upper dword - bug.
Mantis conversion info:
- Mantis ID: 26471
- OS: Kubuntu
- OS Build: 14
- Platform: Linux
- Version: 2.6.4