package ocaml_intrinsics

All checked builds pass
  1. Overview
  2. Docs

Description

Provides functions to invoke amd64 instructions (such as clz,popcnt,rdtsc,rdpmc) when available, or compatible software implementation on other targets.

Added to opam-repository:

README

ocaml_intrinsics - a library of intrinsics for OCaml

The ocaml_intrinsics library provides an OCaml interface to operations that have dedicated hardware instructions on some micro-architectures. Currently, it provides the following operations:

  • count leading zeros of an integer
  • count trailing zeros of an integer
  • count set bits of an integer
  • performance monitoring
  • cyclic redundancy check
  • memory fences

Some operations require more than one instruction to implement.

On x86_64 architecture, the integer operations are implemented using bsf, bsr, and popcnt instructions. Additionally, the library supports performance monitoring instructions rdtsc/rdpmc, crc32, and s/l/mfence for the x86_64 architecture only.

The library provides default implementations using C stubs for all targets. OCaml compiler with support for intrinsics intercepts calls to these C stubs and emits inline assembly instead.

The library and the compiler support was only tested on x86_64 Linux target.

The goals of the library are to:

    * Expose a portable interface with uniform semantics on all OCaml targets.
  Under the hood, take care of target-specific
  details, including C compiler, operating
  system, and machine architecture support.

* Reduce the overhead of OCaml-to-C calls in the implemention,
  whenever possible, using attributes such as "noalloc", "unboxed", and
  "untagged". Provides variants of operations, such as tagged
  and untagged integers, and handle corner cases.
  The users can choose the most suitable variant in each context.

* Make it easier to use dedicated hardware
  instructions, and evaluate their effects on performance.

* Make it easier to experiment with compiler intrinsics.
  The main difference in generated code
  between this library's C stubs and compiler intrinsics
  is that C stubs cannot be inlined.
  It is not clear whether "inlining" them would noticibly improve
  performance compared to a direct call.
  In particular, inlining might also increase register
  pressure in the caller, especially when new instruction
  require designated registers as operands (such as rdtsc).
  Compiler support for intrinsics
  detects and replaces calls to C stubs annoted with [@@builtin]
  with the corresponding instructions, on targets that support them.

* Make it easier for the users to transition their code
  from using this library to using compiler intrinsics,
  whenever the corresponding operation become available in the
  upstream OCaml compiler.

Dependencies (4)

  1. dune-configurator
  2. dune >= "3.11.0"
  3. ocaml_intrinsics_kernel >= "v0.17" & < "v0.18~"
  4. ocaml >= "5.1.0"

Dev Dependencies

None

Optional Dependencies

None

Used by (4)

  1. charset
  2. owi
  3. runtime_events_tools >= "0.5.1" & < "0.5.3"
  4. smtml

Conflicts

None

Build status

Results of building ocaml_intrinsics with each compiler on check.ci.ocaml.org, run of against opam-repository 7cdc698. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
v0.17.0 (this version) n/a n/a good good good
v0.16.2 n/a good good good good
v0.15.2 good good good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure