Skip to content

Commit 7744d04

Browse files
authored
flambda-backend: Request ISA extension checks from C stubs (#2268)
1 parent 8bfe6f3 commit 7744d04

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed

runtime/caml/isa.h

+86
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,92 @@
1717

1818
#include "misc.h"
1919

20+
// This file is included by mlvalues.h, so should be visible
21+
// to all user-defined C bindings. When compiling C stubs to
22+
// x86_64/ELF, this detects which ISA extensions are enabled and
23+
// requests the OCaml runtime to check for support at startup.
24+
25+
#if defined __x86_64__ && defined __ELF__
26+
27+
#define CAML_REQUIRE_ARCH_POPCNT \
28+
CAMLweakdef intnat caml_arch_popcnt;
29+
30+
#define CAML_REQUIRE_ARCH_PREFETCHW \
31+
CAMLweakdef intnat caml_arch_prefetchw;
32+
33+
#define CAML_REQUIRE_ARCH_PREFETCHWT1 \
34+
CAMLweakdef intnat caml_arch_prefetchwt1;
35+
36+
#define CAML_REQUIRE_ARCH_SSE3 \
37+
CAMLweakdef intnat caml_arch_sse3;
38+
39+
#define CAML_REQUIRE_ARCH_SSSE3 \
40+
CAMLweakdef intnat caml_arch_ssse3;
41+
42+
#define CAML_REQUIRE_ARCH_SSE4_1 \
43+
CAMLweakdef intnat caml_arch_sse4_1;
44+
45+
#define CAML_REQUIRE_ARCH_SSE4_2 \
46+
CAMLweakdef intnat caml_arch_sse4_2;
47+
48+
#define CAML_REQUIRE_ARCH_CLMUL \
49+
CAMLweakdef intnat caml_arch_clmul;
50+
51+
#define CAML_REQUIRE_ARCH_LZCNT \
52+
CAMLweakdef intnat caml_arch_lzcnt;
53+
54+
#define CAML_REQUIRE_ARCH_BMI \
55+
CAMLweakdef intnat caml_arch_bmi;
56+
57+
#define CAML_REQUIRE_ARCH_BMI2 \
58+
CAMLweakdef intnat caml_arch_bmi2;
59+
60+
#ifdef __POPCNT__
61+
CAML_REQUIRE_ARCH_POPCNT
62+
#endif
63+
64+
#ifdef __PRFCHW__
65+
CAML_REQUIRE_ARCH_PREFETCHW
66+
#endif
67+
68+
#ifdef __PREFETCHWT1__
69+
CAML_REQUIRE_ARCH_PREFETCHWT1
70+
#endif
71+
72+
#ifdef __SSE3__
73+
CAML_REQUIRE_ARCH_SSE3
74+
#endif
75+
76+
#ifdef __SSSE3__
77+
CAML_REQUIRE_ARCH_SSSE3
78+
#endif
79+
80+
#ifdef __SSE4_1__
81+
CAML_REQUIRE_ARCH_SSE4_1
82+
#endif
83+
84+
#ifdef __SSE4_2__
85+
CAML_REQUIRE_ARCH_SSE4_2
86+
#endif
87+
88+
#ifdef __PCLMUL__
89+
CAML_REQUIRE_ARCH_CLMUL
90+
#endif
91+
92+
#ifdef __LZCNT__
93+
CAML_REQUIRE_ARCH_LZCNT
94+
#endif
95+
96+
#ifdef __BMI__
97+
CAML_REQUIRE_ARCH_BMI
98+
#endif
99+
100+
#ifdef __BMI2__
101+
CAML_REQUIRE_ARCH_BMI2
102+
#endif
103+
104+
#endif
105+
20106
#ifdef CAML_INTERNALS
21107
CAMLextern void caml_assert_arch_extensions(void);
22108
extern uintnat caml_skip_arch_extension_check;

runtime/caml/mlvalues.h

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "config.h"
2020
#include "misc.h"
21+
#include "isa.h"
2122

2223
#ifdef __cplusplus
2324
extern "C" {

runtime4/caml/isa.h

+86
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,92 @@
1717

1818
#include "misc.h"
1919

20+
// This file is included by mlvalues.h, so should be visible
21+
// to all user-defined C bindings. When compiling C stubs to
22+
// x86_64/ELF, this detects which ISA extensions are enabled and
23+
// requests the OCaml runtime to check for support at startup.
24+
25+
#if defined __x86_64__ && defined __ELF__
26+
27+
#define CAML_REQUIRE_ARCH_POPCNT \
28+
CAMLweakdef intnat caml_arch_popcnt;
29+
30+
#define CAML_REQUIRE_ARCH_PREFETCHW \
31+
CAMLweakdef intnat caml_arch_prefetchw;
32+
33+
#define CAML_REQUIRE_ARCH_PREFETCHWT1 \
34+
CAMLweakdef intnat caml_arch_prefetchwt1;
35+
36+
#define CAML_REQUIRE_ARCH_SSE3 \
37+
CAMLweakdef intnat caml_arch_sse3;
38+
39+
#define CAML_REQUIRE_ARCH_SSSE3 \
40+
CAMLweakdef intnat caml_arch_ssse3;
41+
42+
#define CAML_REQUIRE_ARCH_SSE4_1 \
43+
CAMLweakdef intnat caml_arch_sse4_1;
44+
45+
#define CAML_REQUIRE_ARCH_SSE4_2 \
46+
CAMLweakdef intnat caml_arch_sse4_2;
47+
48+
#define CAML_REQUIRE_ARCH_CLMUL \
49+
CAMLweakdef intnat caml_arch_clmul;
50+
51+
#define CAML_REQUIRE_ARCH_LZCNT \
52+
CAMLweakdef intnat caml_arch_lzcnt;
53+
54+
#define CAML_REQUIRE_ARCH_BMI \
55+
CAMLweakdef intnat caml_arch_bmi;
56+
57+
#define CAML_REQUIRE_ARCH_BMI2 \
58+
CAMLweakdef intnat caml_arch_bmi2;
59+
60+
#ifdef __POPCNT__
61+
CAML_REQUIRE_ARCH_POPCNT
62+
#endif
63+
64+
#ifdef __PRFCHW__
65+
CAML_REQUIRE_ARCH_PREFETCHW
66+
#endif
67+
68+
#ifdef __PREFETCHWT1__
69+
CAML_REQUIRE_ARCH_PREFETCHWT1
70+
#endif
71+
72+
#ifdef __SSE3__
73+
CAML_REQUIRE_ARCH_SSE3
74+
#endif
75+
76+
#ifdef __SSSE3__
77+
CAML_REQUIRE_ARCH_SSSE3
78+
#endif
79+
80+
#ifdef __SSE4_1__
81+
CAML_REQUIRE_ARCH_SSE4_1
82+
#endif
83+
84+
#ifdef __SSE4_2__
85+
CAML_REQUIRE_ARCH_SSE4_2
86+
#endif
87+
88+
#ifdef __PCLMUL__
89+
CAML_REQUIRE_ARCH_CLMUL
90+
#endif
91+
92+
#ifdef __LZCNT__
93+
CAML_REQUIRE_ARCH_LZCNT
94+
#endif
95+
96+
#ifdef __BMI__
97+
CAML_REQUIRE_ARCH_BMI
98+
#endif
99+
100+
#ifdef __BMI2__
101+
CAML_REQUIRE_ARCH_BMI2
102+
#endif
103+
104+
#endif
105+
20106
#ifdef CAML_INTERNALS
21107
CAMLextern void caml_assert_arch_extensions(void);
22108
extern uintnat caml_skip_arch_extension_check;

runtime4/caml/mlvalues.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#endif
2222
#include "config.h"
2323
#include "misc.h"
24+
#include "isa.h"
2425

2526
#ifdef __cplusplus
2627
extern "C" {

0 commit comments

Comments
 (0)