Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0000266OCamlOCaml generalpublic2001-01-18 14:092001-02-12 11:14
Reporteradministrator 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionno change required 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000266: bug in Nativeint
DescriptionThe 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>
#

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0002202)
administrator (administrator)
2001-01-21 11:28

Hi Norman,

> 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.

Cheers,

- Xavier

(0002203)
administrator (administrator)
2001-02-12 11:14

Unspecified behavior. Added documentation. (Xavier, 2001-02-12)

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker