package optint

  1. Overview
  2. Docs
Abstract type on integer between x64 and x86 architecture

Install

Dune Dependency

Authors

Maintainers

Sources

optint-v0.0.5.tbz
sha256=774901af130eacc08e30ae43e9a18c926f284c22e3c66c2ff95e74648fbedf26
sha512=fe5762ee7a1a08c7b389fbef9188f8a59c40bb8e19535cec1661a789f973338d5b6d4b30c1869e089282242efa63bfc86c1fb15224b47c05cb5277971aa14a35

Description

This library provide an abstract type which represents at least a 32-bits integer. On x64, this library use a native unboxed integer (63 bits). On x86, this library use a boxed int32.

Implementation depends on target architecture.

Published: 23 Feb 2021

README

Optint - Abstract integer types between x64 and x86 architectures

This library provides two new integer types, Optint.t and Int63.t, which guarantee efficient representation on x64 architectures and provide a best-effort boxed representation on x86 architectures.

Goal

The standard Int32.t and Int64.t types provided by the standard library have the same heap-allocated representation on all architectures. This consistent representation has costs in both memory and run-time performance.

On 64-bit architectures, it's often more efficient to use the native Int.t directly, and fallback to the boxed representations on 32-bit architectures. This library provides types to do exactly this:

  • Optint.t: an integer containing at least 32 bits. On 64-bit machines, this is an immediate integer; on 32-bit machines, it is a boxed 32-bit value. The overflow behaviour is platform-dependent.

  • Int63.t: an integer containing exactly 63 bits. On 64-bit machines, this is an immediate integer; on 32-bit machines, it is a boxed 64-bit integer that is wrapped to provide 63-bit two's complement semantics. The two implementations are observationally equivalent, modulo use of Marshal and Obj.

In summary:

Integer type x86 representation x64 representation Semantics
Stdlib.Int.t 31-bit immediate ✅ 63-bit immediate ✅ Always immediate
Stdlib.Nativeint.t 64-bit boxed ❌ 32-bit boxed ❌ Exactly word size
Stdlib.Int32.t 32-bit boxed ❌ 32-bit boxed ❌ Exactly 32 bits
Stdlib.Int64.t 64-bit boxed ❌ 64-bit boxed ❌ Exactly 64 bits
Optint.t (new) 32-bit boxed ❌ 63-bit immediate ✅ At least 32 bits
Int63.t (new) 64-bit boxed ❌ 63-bit immediate ✅ Exactly 63 bits

These new types are safe and well-tested, but their architecture-dependent implementation makes them unsuitable for use with the Marshal module. Use the provided encode and decode functions instead.

Dependencies (2)

  1. dune
  2. ocaml >= "4.07.0"

Dev Dependencies (3)

  1. fmt with-test
  2. monolith with-test
  3. crowbar with-test & >= "0.2"

Used by (11)

  1. carton
  2. carton-lwt
  3. chamelon
  4. checkseum >= "0.3.1" & < "0.3.3"
  5. decompress >= "0.8" & < "1.4.1"
  6. git >= "3.0.0"
  7. mirage-kv-mem >= "3.2.1"
  8. mirage-kv-unix >= "3.0.0"
  9. oneffs
  10. rfc1951 < "1.0.0" | >= "1.3.0"
  11. tar-mirage >= "2.3.0"

Conflicts

None

OCaml

Innovation. Community. Security.