You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 266 Reporter: administrator Status: closed Resolution: not a bug Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general)
Bug description
The implementation of logical shift is not quite right using the bytecode
compiler on Linux x86:
module N = Nativeint ;;
...
N.shift_right_logical N.minus_one 1;;
: nativeint = <nativeint 2147483647>
N.shift_right_logical N.minus_one 32;;
: nativeint = <nativeint -1>
N.shift_right_logical N.minus_one 31;;
: nativeint = <nativeint 1>
N.shift_right_logical (N.of_int 1) 1;;
: nativeint = <nativeint 0>
The text was updated successfully, but these errors were encountered:
The implementation of logical shift is not quite right using the bytecode
compiler on Linux x86:
Well, this looks OK to me. The documentation is insufficient, though:
it should say that, like the underlying C shifts, the behavior is
unspecified if the shift amount is < 0 or >= 32 (or 64 on a 64-bit
processor). Like most processors, the x86 chooses to take the shift
amount modulo 32.
module N = Nativeint ;;
...
N.shift_right_logical N.minus_one 1;;
: nativeint = <nativeint 2147483647>
OK: 0xFFFFFFFF >>> 1 = 0x7FFFFFFF
N.shift_right_logical N.minus_one 32;;
: nativeint = <nativeint -1>
Here, the processor interprets 32 as 0, as explained above, so it's OK.
N.shift_right_logical N.minus_one 31;;
: nativeint = <nativeint 1>
0xFFFFFFFF >>> 31 = 0x00000001, all right.
N.shift_right_logical (N.of_int 1) 1;;
: nativeint = <nativeint 0>
0x00000001 >>> 1 = 0x00000000, all right.
Another possibility would be to fully specify shifts the way Java does
it, i.e. enforce that the shift amount is taken modulo 32 or 64.
Since this is what popular processors do already, it would not
generate any additional code in ocamlopt; the bytecode interpreter
would have to take the modulus explicitly.
Original bug ID: 266
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Bug description
The implementation of logical shift is not quite right using the bytecode
compiler on Linux x86:
module N = Nativeint ;;
...
N.shift_right_logical N.minus_one 1;;
N.shift_right_logical N.minus_one 32;;
N.shift_right_logical N.minus_one 31;;
N.shift_right_logical (N.of_int 1) 1;;
The text was updated successfully, but these errors were encountered: