From c24e06c2e184345ceb33eb20a15d1024d9fd3497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 27 Feb 2024 10:43:07 +0200 Subject: [PATCH 1/3] configure: Check for SVE support in MS armasm64 via as_check This is mostly supported in armasm64 since MSVC 2022 17.10. --- configure | 2 ++ 1 file changed, 2 insertions(+) diff --git a/configure b/configure index c1fb599f0..63d9bd6b8 100755 --- a/configure +++ b/configure @@ -1001,6 +1001,8 @@ if [ $asm = auto -a $ARCH = AARCH64 ] ; then if [ $compiler = CL ] && cpp_check '' '' 'defined(_M_ARM64)' ; then define HAVE_AARCH64 define HAVE_NEON + as_check "ptrue p0.b, vl16" && define HAVE_SVE + as_check "smlalb z10.s, z2.h, z1.h" && define HAVE_SVE2 elif cc_check '' '' '__asm__("cmeq v0.8h, v0.8h, #0");' ; then define HAVE_AARCH64 define HAVE_NEON From 3a8b5be2a256ffc6d8ec4fb35ecfb335d5a4a03b Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Mon, 30 Sep 2024 06:46:57 -0400 Subject: [PATCH 2/3] aarch64: Use elf_aux_info() for CPU feature detection on FreeBSD/OpenBSD --- common/cpu.c | 13 +++++++++++-- configure | 7 +++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/common/cpu.c b/common/cpu.c index fb7c07d53..0e464203f 100644 --- a/common/cpu.c +++ b/common/cpu.c @@ -420,7 +420,7 @@ uint32_t x264_cpu_detect( void ) #elif HAVE_AARCH64 -#ifdef __linux__ +#if defined(__linux__) || HAVE_ELF_AUX_INFO #include #define HWCAP_AARCH64_SVE (1 << 22) @@ -430,8 +430,17 @@ static uint32_t detect_flags( void ) { uint32_t flags = 0; +#if HAVE_ELF_AUX_INFO + unsigned long hwcap = 0; + unsigned long hwcap2 = 0; + + elf_aux_info( AT_HWCAP, &hwcap, sizeof(hwcap) ); + elf_aux_info( AT_HWCAP2, &hwcap2, sizeof(hwcap2) ); +#else unsigned long hwcap = getauxval( AT_HWCAP ); unsigned long hwcap2 = getauxval( AT_HWCAP2 ); +#endif + if ( hwcap & HWCAP_AARCH64_SVE ) flags |= X264_CPU_SVE; if ( hwcap2 & HWCAP2_AARCH64_SVE2 ) @@ -458,7 +467,7 @@ uint32_t x264_cpu_detect( void ) #endif // Where possible, try to do runtime detection as well. -#ifdef __linux__ +#if defined(__linux__) || HAVE_ELF_AUX_INFO flags |= detect_flags(); #endif diff --git a/configure b/configure index 63d9bd6b8..d50aca8d5 100755 --- a/configure +++ b/configure @@ -411,8 +411,7 @@ NL=" # list of all preprocessor HAVE values we can define CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON AARCH64 BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F SWSCALE \ LAVF FFMS GPAC AVS GPL VECTOREXT INTERLACED CPU_COUNT OPENCL THP LSMASH X86_INLINE_ASM AS_FUNC INTEL_DISPATCHER \ - MSA LSX MMAP WINRT VSX ARM_INLINE_ASM STRTOK_R CLOCK_GETTIME BITDEPTH8 BITDEPTH10 \ - SVE SVE2" + MSA LSX MMAP WINRT VSX ARM_INLINE_ASM STRTOK_R CLOCK_GETTIME BITDEPTH8 BITDEPTH10 SVE SVE2 ELF_AUX_INFO" # parse options @@ -1144,6 +1143,10 @@ elif cc_check 'time.h' '-lrt' 'clock_gettime(CLOCK_MONOTONIC, 0);' ; then LDFLAGS="$LDFLAGS -lrt" fi +if cc_check 'sys/auxv.h' '' 'unsigned long auxv = 0; elf_aux_info(AT_HWCAP, &auxv, sizeof(auxv));' ; then + define HAVE_ELF_AUX_INFO +fi + if [ "$SYS" != "WINDOWS" ] && cpp_check "sys/mman.h unistd.h" "" "defined(MAP_PRIVATE)"; then define HAVE_MMAP fi From 1243d9ffb04dac7005ee9ecc79459034429dd5aa Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Wed, 16 Oct 2024 11:09:57 -0400 Subject: [PATCH 3/3] Provide x264_getauxval() wrapper for getauxvaul() and elf_aux_info() --- common/cpu.c | 32 +++++++++++++++++++------------- configure | 6 +++++- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/common/cpu.c b/common/cpu.c index 0e464203f..33171f3be 100644 --- a/common/cpu.c +++ b/common/cpu.c @@ -27,6 +27,9 @@ #include "base.h" +#if HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO +#include +#endif #if SYS_CYGWIN || SYS_SunOS || SYS_OPENBSD #include #endif @@ -107,6 +110,19 @@ const x264_cpu_name_t x264_cpu_names[] = {"", 0}, }; +static unsigned long x264_getauxval( unsigned long type ) +{ +#if HAVE_GETAUXVAL + return getauxval( type ); +#elif HAVE_ELF_AUX_INFO + unsigned long aux = 0; + elf_aux_info( type, &aux, sizeof(aux) ); + return aux; +#else + return 0; +#endif +} + #if (HAVE_ALTIVEC && SYS_LINUX) || (HAVE_ARMV6 && !HAVE_NEON) #include #include @@ -421,7 +437,6 @@ uint32_t x264_cpu_detect( void ) #elif HAVE_AARCH64 #if defined(__linux__) || HAVE_ELF_AUX_INFO -#include #define HWCAP_AARCH64_SVE (1 << 22) #define HWCAP2_AARCH64_SVE2 (1 << 1) @@ -430,16 +445,8 @@ static uint32_t detect_flags( void ) { uint32_t flags = 0; -#if HAVE_ELF_AUX_INFO - unsigned long hwcap = 0; - unsigned long hwcap2 = 0; - - elf_aux_info( AT_HWCAP, &hwcap, sizeof(hwcap) ); - elf_aux_info( AT_HWCAP2, &hwcap2, sizeof(hwcap2) ); -#else - unsigned long hwcap = getauxval( AT_HWCAP ); - unsigned long hwcap2 = getauxval( AT_HWCAP2 ); -#endif + unsigned long hwcap = x264_getauxval( AT_HWCAP ); + unsigned long hwcap2 = x264_getauxval( AT_HWCAP2 ); if ( hwcap & HWCAP_AARCH64_SVE ) flags |= X264_CPU_SVE; @@ -482,7 +489,6 @@ uint32_t x264_cpu_detect( void ) } #elif HAVE_LSX -#include #define LA_HWCAP_LSX ( 1U << 4 ) #define LA_HWCAP_LASX ( 1U << 5 ) @@ -490,7 +496,7 @@ uint32_t x264_cpu_detect( void ) uint32_t x264_cpu_detect( void ) { uint32_t flags = 0; - uint32_t hwcap = (uint32_t)getauxval( AT_HWCAP ); + uint32_t hwcap = (uint32_t)x264_getauxval( AT_HWCAP ); if( hwcap & LA_HWCAP_LSX ) flags |= X264_CPU_LSX; diff --git a/configure b/configure index d50aca8d5..5cd8110ff 100755 --- a/configure +++ b/configure @@ -411,7 +411,7 @@ NL=" # list of all preprocessor HAVE values we can define CONFIG_HAVE="MALLOC_H ALTIVEC ALTIVEC_H MMX ARMV6 ARMV6T2 NEON AARCH64 BEOSTHREAD POSIXTHREAD WIN32THREAD THREAD LOG2F SWSCALE \ LAVF FFMS GPAC AVS GPL VECTOREXT INTERLACED CPU_COUNT OPENCL THP LSMASH X86_INLINE_ASM AS_FUNC INTEL_DISPATCHER \ - MSA LSX MMAP WINRT VSX ARM_INLINE_ASM STRTOK_R CLOCK_GETTIME BITDEPTH8 BITDEPTH10 SVE SVE2 ELF_AUX_INFO" + MSA LSX MMAP WINRT VSX ARM_INLINE_ASM STRTOK_R CLOCK_GETTIME BITDEPTH8 BITDEPTH10 SVE SVE2 ELF_AUX_INFO GETAUXVAL" # parse options @@ -1143,6 +1143,10 @@ elif cc_check 'time.h' '-lrt' 'clock_gettime(CLOCK_MONOTONIC, 0);' ; then LDFLAGS="$LDFLAGS -lrt" fi +if cc_check 'sys/auxv.h' '' 'getauxval(AT_HWCAP);' ; then + define HAVE_GETAUXVAL +fi + if cc_check 'sys/auxv.h' '' 'unsigned long auxv = 0; elf_aux_info(AT_HWCAP, &auxv, sizeof(auxv));' ; then define HAVE_ELF_AUX_INFO fi