[x264-devel] [Git][videolan/x264][master] Provide x264_getauxval() wrapper for getauxvaul() and elf_aux_info()

Anton Mitrofanov (@BugMaster) gitlab at videolan.org
Wed Oct 16 07:22:08 UTC 2024



Anton Mitrofanov pushed to branch master at VideoLAN / x264


Commits:
1243d9ff by Brad Smith at 2024-10-17T06:23:19-04:00
Provide x264_getauxval() wrapper for getauxvaul() and elf_aux_info()

- - - - -


2 changed files:

- common/cpu.c
- configure


Changes:

=====================================
common/cpu.c
=====================================
@@ -27,6 +27,9 @@
 
 #include "base.h"
 
+#if HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
+#include <sys/auxv.h>
+#endif
 #if SYS_CYGWIN || SYS_SunOS || SYS_OPENBSD
 #include <unistd.h>
 #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 <signal.h>
 #include <setjmp.h>
@@ -421,7 +437,6 @@ uint32_t x264_cpu_detect( void )
 #elif HAVE_AARCH64
 
 #if defined(__linux__) || HAVE_ELF_AUX_INFO
-#include <sys/auxv.h>
 
 #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 <sys/auxv.h>
 
 #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;


=====================================
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



View it on GitLab: https://code.videolan.org/videolan/x264/-/commit/1243d9ffb04dac7005ee9ecc79459034429dd5aa

-- 
View it on GitLab: https://code.videolan.org/videolan/x264/-/commit/1243d9ffb04dac7005ee9ecc79459034429dd5aa
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the x264-devel mailing list