Coder Social home page Coder Social logo

gretay-js / ocaml_intrinsics Goto Github PK

View Code? Open in Web Editor NEW

This project forked from janestreet/ocaml_intrinsics

0.0 0.0 0.0 48 KB

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

License: MIT License

Makefile 0.30% OCaml 74.96% C 24.74%

ocaml_intrinsics's Introduction

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

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 and rdpmc, as well as crc32 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.

ocaml_intrinsics's People

Contributors

aalekseyev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.