Module Flambda2_numbers.Targetint_32_64
Target processor-native integers.
This module provides operations on the type of signed 32-bit integers (on 32-bit target platforms) or signed 64-bit integers (on 64-bit target platforms). This integer type has exactly the same width as that of a pointer type in the C compiler. All arithmetic operations over are taken modulo 232 or 264 depending on the word size of the target architecture.
Warning: this module is unstable and part of compiler-libs.
type targetint = Flambda2_numbers.Targetint_32_64.tThe target integer 0.
val zero_like :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tThe target integer 0, taking the machine width from the argument. (Note that no function is provided to extract a Machine_width given a t, because we can't distinguish between the Thirty_two and Thirty_two_no_gc_bit cases.)
The target integer 1.
val minus_one :
Target_system.Machine_width.t ->
Flambda2_numbers.Targetint_32_64.tThe target integer -1.
Unary negation.
val add :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tAddition.
val sub :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tSubtraction.
val mul :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tMultiplication.
val div :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tInteger division. Raise Division_by_zero if the second argument is zero. This division rounds the real quotient of its arguments towards zero, as specified for Stdlib.(/).
val unsigned_div :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tSame as div, except that arguments and result are interpreted as unsigned integers.
val rem :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tInteger remainder. If y is not zero, the result * of Targetint_32_64.rem x y satisfies the following properties: * Targetint_32_64.zero <= Nativeint.rem x y < Targetint_32_64.abs y and * x = Targetint_32_64.add (Targetint_32_64.mul (Targetint_32_64.div x y) y) * (Targetint_32_64.rem x y). * If y = 0, Targetint_32_64.rem x y raises Division_by_zero.
val unsigned_rem :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tSame as rem, except that arguments and result are interpreted as unsigned integers.
Successor. Targetint_32_64.succ x is Targetint_32_64.add x Targetint_32_64.one.
Predecessor. Targetint_32_64.pred x is Targetint_32_64.sub x Targetint_32_64.one.
Return the absolute value of its argument.
val max_int :
Target_system.Machine_width.t ->
Flambda2_numbers.Targetint_32_64.tThe greatest representable target integer, either 231 - 1 on a 32-bit platform, or 263 - 1 on a 64-bit platform.
val min_int :
Target_system.Machine_width.t ->
Flambda2_numbers.Targetint_32_64.tThe smallest representable target integer, either -231 on a 32-bit platform, or -263 on a 64-bit platform.
val logand :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tBitwise logical and.
val logor :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tBitwise logical or.
val logxor :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tBitwise logical exclusive or.
val lognot :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tBitwise logical negation.
val shift_left :
Flambda2_numbers.Targetint_32_64.t ->
int ->
Flambda2_numbers.Targetint_32_64.tTargetint_32_64.shift_left x y shifts x to the left by y bits.
The result is unspecified if y < 0 or y >= bitsize, where bitsize is 32 on a 32-bit platform and 64 on a 64-bit platform.
val shift_right :
Flambda2_numbers.Targetint_32_64.t ->
int ->
Flambda2_numbers.Targetint_32_64.tTargetint_32_64.shift_right x y shifts x to the right by y bits.
This is an arithmetic shift: the sign bit of x is replicated and inserted in the vacated bits.
The result is unspecified if y < 0 or y >= bitsize.
val shift_right_logical :
Flambda2_numbers.Targetint_32_64.t ->
int ->
Flambda2_numbers.Targetint_32_64.tTargetint_32_64.shift_right_logical x y shifts x to the right by y bits.
This is a logical shift: zeroes are inserted in the vacated bits regardless of the sign of x.
The result is unspecified if y < 0 or y >= bitsize.
val of_int :
Target_system.Machine_width.t ->
int ->
Flambda2_numbers.Targetint_32_64.tConvert the given integer (type int) to a target integer (type t), modulo the target word size.
val of_int_exn :
Target_system.Machine_width.t ->
int ->
Flambda2_numbers.Targetint_32_64.tConvert the given integer (type int) to a target integer (type t). Raises a fatal error if the conversion is not exact.
val to_int : Flambda2_numbers.Targetint_32_64.t -> intConvert the given target integer (type t) to an integer (type int). The high-order bit is lost during the conversion.
val to_int_checked :
Target_system.Machine_width.t ->
Flambda2_numbers.Targetint_32_64.t ->
intLike to_int but will raise an exception if the integer doesn't fit.
val of_float :
Target_system.Machine_width.t ->
float ->
Flambda2_numbers.Targetint_32_64.tConvert the given floating-point number to a target integer, discarding the fractional part (truncate towards 0).
The result of the conversion is undefined if, after truncation, the number is outside the range [Targetint_32_64.min_int, Targetint_32_64.max_int].
val to_float : Flambda2_numbers.Targetint_32_64.t -> floatConvert the given target integer to a floating-point number.
val of_int32 :
Target_system.Machine_width.t ->
int32 ->
Flambda2_numbers.Targetint_32_64.tConvert the given 32-bit integer (type int32) to a target integer.
val to_int32 : Flambda2_numbers.Targetint_32_64.t -> int32Convert the given target integer to a 32-bit integer (type int32).
On 64-bit platforms, the 64-bit native integer is taken modulo 232, i.e. the top 32 bits are lost. On 32-bit platforms, the conversion is exact.
val of_int64 :
Target_system.Machine_width.t ->
int64 ->
Flambda2_numbers.Targetint_32_64.tConvert the given 64-bit integer (type int64) to a target integer, modulo the target word size.
val to_int64 : Flambda2_numbers.Targetint_32_64.t -> int64Convert the given target integer to a 64-bit integer (type int64).
val of_string :
Target_system.Machine_width.t ->
string ->
Flambda2_numbers.Targetint_32_64.tConvert the given string to a target integer.
The string is read in decimal (by default) or in hexadecimal, octal or binary if the string begins with 0x, 0o or 0b respectively.
Raise Failure "int_of_string" if the given string is not a valid representation of an integer, or if the integer represented exceeds the range of integers representable in type nativeint.
val to_string : Flambda2_numbers.Targetint_32_64.t -> stringReturn the string representation of its argument, in decimal.
val unsigned_compare :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
intSame as compare, except that arguments are interpreted as unsigned integers.
The concrete representation of a native integer.
val min :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tReturns the smaller integer.
val max :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tReturns the larger integer.
val get_least_significant_16_bits_then_byte_swap :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tExtract the least significant 16 bits from the given target integer, exchange the order of the two bytes extracted, then form a new target integer by zero-extending those two bytes.
val swap_byte_endianness :
Flambda2_numbers.Targetint_32_64.t ->
Flambda2_numbers.Targetint_32_64.tinclude Flambda2_algorithms.Container_types.S
with type t := Flambda2_numbers.Targetint_32_64.t
module T :
Flambda2_algorithms.Container_types_intf.Thing
with type t = Flambda2_numbers.Targetint_32_64.tinclude Flambda2_algorithms.Container_types_intf.Thing
with type t := Flambda2_numbers.Targetint_32_64.T.t
include Stdlib.Hashtbl.HashedType
with type t := Flambda2_numbers.Targetint_32_64.T.t
val equal :
Flambda2_numbers.Targetint_32_64.T.t ->
Flambda2_numbers.Targetint_32_64.T.t ->
boolThe equality predicate used to compare keys.
val hash : Flambda2_numbers.Targetint_32_64.T.t -> intA hashing function on keys. It must be such that if two keys are equal according to equal, then they have identical hash values as computed by hash. Examples: suitable (equal, hash) pairs for arbitrary key types include
- (
(=),hash) for comparing objects by structure (provided objects do not contain floats) - (
(fun x y -> compare x y = 0),hash) for comparing objects by structure and handlingStdlib.nancorrectly - (
(==),hash) for comparing objects by physical equality (e.g. for mutable or cyclic objects).
include Stdlib.Map.OrderedType
with type t := Flambda2_numbers.Targetint_32_64.T.t
val compare :
Flambda2_numbers.Targetint_32_64.T.t ->
Flambda2_numbers.Targetint_32_64.T.t ->
intA total ordering function over the keys. This is a two-argument function f such that f e1 e2 is zero if the keys e1 and e2 are equal, f e1 e2 is strictly negative if e1 is smaller than e2, and f e1 e2 is strictly positive if e1 is greater than e2. Example: a suitable ordering function is the generic structural comparison function Stdlib.compare.
val print :
Stdlib.Format.formatter ->
Flambda2_numbers.Targetint_32_64.T.t ->
unitmodule Set :
Flambda2_algorithms.Container_types_intf.Set
with type elt = Flambda2_numbers.Targetint_32_64.tmodule Map :
Flambda2_algorithms.Container_types_intf.Map
with type key = Flambda2_numbers.Targetint_32_64.t
and module Set = Flambda2_numbers.Targetint_32_64.Setmodule Targetint_set = Flambda2_numbers.Targetint_32_64.Setmodule Pair : sig ... end