Skip to content
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

Check amd64 extension support at startup #2220

Merged
merged 17 commits into from
Feb 9, 2024
Prev Previous commit
Next Next commit
rename flags
  • Loading branch information
TheNumbat committed Feb 8, 2024
commit 87602c8079cdef0ad446c70feada6fef764e5bb9
10 changes: 5 additions & 5 deletions ocaml/runtime/isa.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ CAMLweakdef extern intnat caml_arch_bmi2;

// CPUID with EAX = 0x80000001, result in ECX

#define ABM_BIT (1 << 5)
#define _3DNOWPREFFETCH_BIT (1 << 8)
#define LZCNT_BIT (1 << 5)
#define PREFETCHW_BIT (1 << 8)

// CPUID with EAX = 7, ECX = 0, result in EBX

Expand Down Expand Up @@ -130,13 +130,13 @@ CAMLexport void caml_assert_arch_extensions(void) {
caml_cpuid(info, 0x80000001, 0);

if(&caml_arch_prefetchw) {
if(!(info[2] & _3DNOWPREFFETCH_BIT)) {
if(!(info[2] & PREFETCHW_BIT)) {
caml_fatal_error("Binary compiled with -fprefetchw, but this CPU lacks support.");
}
}
if(&caml_arch_bmi) {
// We check both the ABM and BMI bits
if(!(info[2] & ABM_BIT)) {
// We check both the LZCNT and BMI bits
if(!(info[2] & LZCNT_BIT)) {
caml_fatal_error("Binary compiled with -fbmi, but this CPU lacks support.");
}
}
Expand Down
12 changes: 6 additions & 6 deletions ocaml/runtime4/isa.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "caml/mlvalues.h"
#include "caml/isa.h"

uintnat caml_skip_arch_extension_check = 0;
uintnat caml_skip_arch_extension_check;

// Weak symbols are only supported in ELF

Expand Down Expand Up @@ -61,8 +61,8 @@ CAMLweakdef extern intnat caml_arch_bmi2;

// CPUID with EAX = 0x80000001, result in ECX

#define ABM_BIT (1 << 5)
#define _3DNOWPREFFETCH_BIT (1 << 8)
#define LZCNT_BIT (1 << 5)
#define PREFETCHW_BIT (1 << 8)

// CPUID with EAX = 7, ECX = 0, result in EBX

Expand Down Expand Up @@ -130,13 +130,13 @@ CAMLexport void caml_assert_arch_extensions(void) {
caml_cpuid(info, 0x80000001, 0);

if(&caml_arch_prefetchw) {
if(!(info[2] & _3DNOWPREFFETCH_BIT)) {
if(!(info[2] & PREFETCHW_BIT)) {
caml_fatal_error("Binary compiled with -fprefetchw, but this CPU lacks support.");
}
}
if(&caml_arch_bmi) {
// We check both the ABM and BMI bits
if(!(info[2] & ABM_BIT)) {
// We check both the LZCNT and BMI bits
if(!(info[2] & LZCNT_BIT)) {
caml_fatal_error("Binary compiled with -fbmi, but this CPU lacks support.");
}
}
Expand Down