Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Sibras committed Oct 19, 2024
2 parents 64a4204 + 1243d9f commit 1819124
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
29 changes: 22 additions & 7 deletions common/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -420,8 +436,7 @@ uint32_t x264_cpu_detect( void )

#elif HAVE_AARCH64

#ifdef __linux__
#include <sys/auxv.h>
#if defined(__linux__) || HAVE_ELF_AUX_INFO

#define HWCAP_AARCH64_SVE (1 << 22)
#define HWCAP2_AARCH64_SVE2 (1 << 1)
Expand All @@ -430,8 +445,9 @@ static uint32_t detect_flags( void )
{
uint32_t flags = 0;

unsigned long hwcap = getauxval( AT_HWCAP );
unsigned long hwcap2 = getauxval( AT_HWCAP2 );
unsigned long hwcap = x264_getauxval( AT_HWCAP );
unsigned long hwcap2 = x264_getauxval( AT_HWCAP2 );

if ( hwcap & HWCAP_AARCH64_SVE )
flags |= X264_CPU_SVE;
if ( hwcap2 & HWCAP2_AARCH64_SVE2 )
Expand All @@ -458,7 +474,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

Expand All @@ -473,15 +489,14 @@ 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 )

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;
Expand Down
13 changes: 11 additions & 2 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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 GETAUXVAL"

# parse options

Expand Down Expand Up @@ -1001,6 +1000,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
Expand Down Expand Up @@ -1142,6 +1143,14 @@ 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

if [ "$SYS" != "WINDOWS" ] && cpp_check "sys/mman.h unistd.h" "" "defined(MAP_PRIVATE)"; then
define HAVE_MMAP
fi
Expand Down

0 comments on commit 1819124

Please sign in to comment.