-
Notifications
You must be signed in to change notification settings - Fork 75
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
arm: add support for detecting NEON (WIP) #144
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,69 @@ SLJIT_API_FUNC_ATTRIBUTE const char* sljit_get_platform_name(void) | |
#endif | ||
} | ||
|
||
#define CPU_FEATURE_NEON (1UL << 12) | ||
static unsigned long cpu_feature_list; | ||
|
||
#if (defined SLJIT_DETECT_SIMD && SLJIT_DETECT_SIMD) | ||
#if defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO) | ||
#include <sys/auxv.h> | ||
carenas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#endif | ||
|
||
#ifdef __NetBSD__ | ||
carenas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#include <sys/param.h> | ||
#include <sys/sysctl.h> | ||
#endif | ||
|
||
static void get_cpu_features(void) | ||
{ | ||
if (cpu_feature_list) | ||
return; | ||
|
||
#if defined(__ARM_ARCH) && __ARM_ARCH == 8 | ||
/* TODO: confirm if optional with armv9 */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if true (because NEON is being "replaced" by SVE2, then this might also apply to the 64 bit version and therefore some of it might need to move to a "common" file |
||
/* mandatory for armv8 */ | ||
cpu_feature_list = CPU_FEATURE_NEON; | ||
#elif defined(HAVE_GETAUXVAL) | ||
cpu_feature_list = getauxval(AT_HWCAP); | ||
if (errno == ENOENT) | ||
cpu_feature_list = 1; | ||
#elif defined(__OpenBSD__) | ||
/* required feature */ | ||
cpu_feature_list = CPU_FEATURE_NEON; | ||
#elif defined(__APPLE__) && defined (__ARM_NEON__) | ||
cpu_feature_list = CPU_FEATURE_NEON; | ||
#elif defined(_WIN32) | ||
#ifndef FP_ARM_NEON_INSTRUCTIONS_AVAILABLE | ||
#define FP_ARM_NEON_INSTRUCTIONS_AVAILABLE 19 | ||
#endif | ||
if (IsProcessorFeaturePresent(FP_ARM_NEON_INSTRUCTIONS_AVAILABLE)) | ||
cpu_feature_list = CPU_FEATURE_NEON; | ||
#elif defined(__FreeBSD__) && defined(HAVE_ELF_AUX_INFO) | ||
unsigned long buf; | ||
|
||
if (elf_aux_info(AT_HWCAP, (void *)&buf, (int)sizeof(buf))) | ||
cpu_feature_list = 1; | ||
return; | ||
} | ||
|
||
if (buf & CPU_FEATURE_NEON) | ||
cpu_feature_list = buf; | ||
#elif defined(__NetBSD__) || defined(__FreeBSD__) | ||
int neon; | ||
size_t len = sizeof(int); | ||
|
||
if (sysctlbyname("machdep.neon_present", &neon, &len, NULL, 0) < 0) { | ||
cpu_feature_list = 1; | ||
return; | ||
} | ||
|
||
if (neon) | ||
cpu_feature_list = CPU_FEATURE_NEON; | ||
#endif | ||
} | ||
|
||
#endif /* SLJIT_DETECT_SIMD */ | ||
|
||
/* Last register + 1. */ | ||
#define TMP_REG1 (SLJIT_NUMBER_OF_REGISTERS + 2) | ||
#define TMP_REG2 (SLJIT_NUMBER_OF_REGISTERS + 3) | ||
|
@@ -973,6 +1036,13 @@ SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32 feature_type) | |
return 2; | ||
#endif | ||
|
||
case SLJIT_HAS_SIMD: | ||
#if (defined SLJIT_CONFIG_ARM_V7 && SLJIT_CONFIG_ARM_V7) && \ | ||
(defined SLJIT_DETECT_SIMD && SLJIT_DETECT_SIMD) | ||
if (!cpu_feature_list) | ||
get_cpu_features(); | ||
#endif /* SLJIT_CONFIG_ARM_V7 && SLJIT_DETECT_SIMD */ | ||
return (cpu_feature_list & CPU_FEATURE_NEON) != 0; | ||
default: | ||
return 0; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10636,10 +10636,18 @@ static void test85(void) | |
|
||
int sljit_test(int argc, char* argv[]) | ||
{ | ||
sljit_s32 has_arg = (argc >= 2 && argv[1][0] == '-' && argv[1][2] == '\0'); | ||
int fpu; | ||
int simd = 0; | ||
char features[24]; | ||
int has_arg = (argc >= 2 && argv[1][0] == '-' && argv[1][2] == '\0'); | ||
verbose = has_arg && argv[1][1] == 'v'; | ||
silent = has_arg && argv[1][1] == 's'; | ||
|
||
#if (defined(SLJIT_CONFIG_ARM) && SLJIT_CONFIG_ARM) \ | ||
|| (defined SLJIT_CONFIG_X86 && SLJIT_CONFIG_X86) | ||
simd = sljit_has_cpu_feature(SLJIT_HAS_SIMD); | ||
#endif | ||
|
||
if (!verbose && !silent) | ||
printf("Pass -v to enable verbose, -s to disable this hint.\n\n"); | ||
|
||
|
@@ -10743,7 +10751,16 @@ int sljit_test(int argc, char* argv[]) | |
printf("all tests are " COLOR_GREEN "PASSED" COLOR_DEFAULT " "); | ||
else | ||
printf(COLOR_RED "%d" COLOR_DEFAULT " (" COLOR_RED "%d%%" COLOR_DEFAULT ") tests are " COLOR_RED "FAILED" COLOR_DEFAULT " ", TEST_COUNT - successful_tests, (TEST_COUNT - successful_tests) * 100 / TEST_COUNT); | ||
printf("on " COLOR_ARCH "%s" COLOR_DEFAULT "%s\n", sljit_get_platform_name(), sljit_has_cpu_feature(SLJIT_HAS_FPU) ? " (with fpu)" : " (without fpu)"); | ||
|
||
fpu = sljit_has_cpu_feature(SLJIT_HAS_FPU); | ||
if (simd && fpu) | ||
strcpy(features, " (with: fpu, simd)"); | ||
else if (fpu) | ||
strcpy(features, " (with fpu)"); | ||
else | ||
strcpy(features, " (without fpu)"); | ||
Comment on lines
+10756
to
+10761
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this might misrepreset the case where (!fpu && simd), but that is by design as that combination (while possible) is not something that is available in the market yet. SLJIT_IS_FPU_AVAILABLE and its usecases is also missing and worth discussing, but IMHO might be able to wait until SIMD support is added to sljit proper. |
||
|
||
printf("on " COLOR_ARCH "%s" COLOR_DEFAULT "%s\n", sljit_get_platform_name(), features); | ||
|
||
return TEST_COUNT - successful_tests; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be worth doing the checks here to avoid adding the "detect" support for cases that are known not to require it (ex: OpenBSD or macOS)