-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add runtime check for CPU architecture
- Loading branch information
Showing
3 changed files
with
44 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
#define STRINGIFY_HELPER(X) #X | ||
#define STRINGIFY(X) STRINGIFY_HELPER(X) | ||
|
||
#ifdef __clang__ | ||
// Clang 16 does not support achitecture levels in __builtin_cpu_supports(). Use approximations. | ||
#if EVMONE_X86_64_ARCH_LEVEL == 2 | ||
#define CPU_FEATURE "sse4.2" | ||
#endif | ||
#elif __GNUC__ | ||
#define CPU_FEATURE "x86-64-v" STRINGIFY(EVMONE_X86_64_ARCH_LEVEL) | ||
#endif | ||
|
||
#ifndef CPU_FEATURE | ||
#error "EVMONE_X86_64_ARCH_LEVEL: Unsupported x86-64 architecture level" | ||
#endif | ||
|
||
#include <cstdio> | ||
#include <cstdlib> | ||
|
||
static bool cpu_check = []() noexcept { | ||
if (!__builtin_cpu_supports(CPU_FEATURE)) | ||
{ | ||
std::fputs("CPU does not support " CPU_FEATURE "\n", stderr); | ||
std::abort(); | ||
} | ||
return false; | ||
}(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters