Skip to content

Request ISA extension checks from C stubs #2268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions ocaml/runtime/caml/isa.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,92 @@

#include "misc.h"

// This file is included by mlvalues.h, so should be visible
// to all user-defined C bindings. When compiling C stubs to
// x86_64/ELF, this detects which ISA extensions are enabled and
// requests the OCaml runtime to check for support at startup.

#if defined __x86_64__ && defined __ELF__

#define CAML_REQUIRE_ARCH_POPCNT \
CAMLweakdef intnat caml_arch_popcnt;

#define CAML_REQUIRE_ARCH_PREFETCHW \
CAMLweakdef intnat caml_arch_prefetchw;

#define CAML_REQUIRE_ARCH_PREFETCHWT1 \
CAMLweakdef intnat caml_arch_prefetchwt1;

#define CAML_REQUIRE_ARCH_SSE3 \
CAMLweakdef intnat caml_arch_sse3;

#define CAML_REQUIRE_ARCH_SSSE3 \
CAMLweakdef intnat caml_arch_ssse3;

#define CAML_REQUIRE_ARCH_SSE4_1 \
CAMLweakdef intnat caml_arch_sse4_1;

#define CAML_REQUIRE_ARCH_SSE4_2 \
CAMLweakdef intnat caml_arch_sse4_2;

#define CAML_REQUIRE_ARCH_CLMUL \
CAMLweakdef intnat caml_arch_clmul;

#define CAML_REQUIRE_ARCH_LZCNT \
CAMLweakdef intnat caml_arch_lzcnt;

#define CAML_REQUIRE_ARCH_BMI \
CAMLweakdef intnat caml_arch_bmi;

#define CAML_REQUIRE_ARCH_BMI2 \
CAMLweakdef intnat caml_arch_bmi2;

#ifdef __POPCNT__
CAML_REQUIRE_ARCH_POPCNT
#endif

#ifdef __PRFCHW__
CAML_REQUIRE_ARCH_PREFETCHW
#endif

#ifdef __PREFETCHWT1__
CAML_REQUIRE_ARCH_PREFETCHWT1
#endif

#ifdef __SSE3__
CAML_REQUIRE_ARCH_SSE3
#endif

#ifdef __SSSE3__
CAML_REQUIRE_ARCH_SSSE3
#endif

#ifdef __SSE4_1__
CAML_REQUIRE_ARCH_SSE4_1
#endif

#ifdef __SSE4_2__
CAML_REQUIRE_ARCH_SSE4_2
#endif

#ifdef __PCLMUL__
CAML_REQUIRE_ARCH_CLMUL
#endif

#ifdef __LZCNT__
CAML_REQUIRE_ARCH_LZCNT
#endif

#ifdef __BMI__
CAML_REQUIRE_ARCH_BMI
#endif

#ifdef __BMI2__
CAML_REQUIRE_ARCH_BMI2
#endif

#endif

#ifdef CAML_INTERNALS
CAMLextern void caml_assert_arch_extensions(void);
extern uintnat caml_skip_arch_extension_check;
Expand Down
1 change: 1 addition & 0 deletions ocaml/runtime/caml/mlvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "config.h"
#include "misc.h"
#include "isa.h"

#ifdef __cplusplus
extern "C" {
Expand Down
86 changes: 86 additions & 0 deletions ocaml/runtime4/caml/isa.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,92 @@

#include "misc.h"

// This file is included by mlvalues.h, so should be visible
// to all user-defined C bindings. When compiling C stubs to
// x86_64/ELF, this detects which ISA extensions are enabled and
// requests the OCaml runtime to check for support at startup.

#if defined __x86_64__ && defined __ELF__

#define CAML_REQUIRE_ARCH_POPCNT \
CAMLweakdef intnat caml_arch_popcnt;

#define CAML_REQUIRE_ARCH_PREFETCHW \
CAMLweakdef intnat caml_arch_prefetchw;

#define CAML_REQUIRE_ARCH_PREFETCHWT1 \
CAMLweakdef intnat caml_arch_prefetchwt1;

#define CAML_REQUIRE_ARCH_SSE3 \
CAMLweakdef intnat caml_arch_sse3;

#define CAML_REQUIRE_ARCH_SSSE3 \
CAMLweakdef intnat caml_arch_ssse3;

#define CAML_REQUIRE_ARCH_SSE4_1 \
CAMLweakdef intnat caml_arch_sse4_1;

#define CAML_REQUIRE_ARCH_SSE4_2 \
CAMLweakdef intnat caml_arch_sse4_2;

#define CAML_REQUIRE_ARCH_CLMUL \
CAMLweakdef intnat caml_arch_clmul;

#define CAML_REQUIRE_ARCH_LZCNT \
CAMLweakdef intnat caml_arch_lzcnt;

#define CAML_REQUIRE_ARCH_BMI \
CAMLweakdef intnat caml_arch_bmi;

#define CAML_REQUIRE_ARCH_BMI2 \
CAMLweakdef intnat caml_arch_bmi2;

#ifdef __POPCNT__
CAML_REQUIRE_ARCH_POPCNT
#endif

#ifdef __PRFCHW__
CAML_REQUIRE_ARCH_PREFETCHW
#endif

#ifdef __PREFETCHWT1__
CAML_REQUIRE_ARCH_PREFETCHWT1
#endif

#ifdef __SSE3__
CAML_REQUIRE_ARCH_SSE3
#endif

#ifdef __SSSE3__
CAML_REQUIRE_ARCH_SSSE3
#endif

#ifdef __SSE4_1__
CAML_REQUIRE_ARCH_SSE4_1
#endif

#ifdef __SSE4_2__
CAML_REQUIRE_ARCH_SSE4_2
#endif

#ifdef __PCLMUL__
CAML_REQUIRE_ARCH_CLMUL
#endif

#ifdef __LZCNT__
CAML_REQUIRE_ARCH_LZCNT
#endif

#ifdef __BMI__
CAML_REQUIRE_ARCH_BMI
#endif

#ifdef __BMI2__
CAML_REQUIRE_ARCH_BMI2
#endif

#endif

#ifdef CAML_INTERNALS
CAMLextern void caml_assert_arch_extensions(void);
extern uintnat caml_skip_arch_extension_check;
Expand Down
1 change: 1 addition & 0 deletions ocaml/runtime4/caml/mlvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#endif
#include "config.h"
#include "misc.h"
#include "isa.h"

#ifdef __cplusplus
extern "C" {
Expand Down