1
0
mirror of https://github.com/libjpeg-turbo/libjpeg-turbo.git synced 2026-10-23 11:48:53 +03:00

Use getauxval()/elf_aux_info() to detect Neon ...

with AArch32 on Linux, FreeBSD, and OpenBSD.

Closes #861
This commit is contained in:
Brad Smith
2026-01-29 01:31:14 -05:00
committed by DRC
parent fa33033a7a
commit 7f3c43891e
2 changed files with 34 additions and 2 deletions

View File

@@ -390,6 +390,20 @@ if(NOT NEON_INTRINSICS)
set(SIMD_SOURCES ${SIMD_SOURCES} arm/aarch${BITS}/jsimd_neon.S)
endif()
if(UNIX AND BITS EQUAL 32)
include(CheckSymbolExists)
check_symbol_exists(getauxval sys/auxv.h HAVE_GETAUXVAL)
if(HAVE_GETAUXVAL)
set_source_files_properties(arm/aarch${BITS}/jsimd.c PROPERTIES
COMPILE_DEFINITIONS HAVE_GETAUXVAL)
endif()
check_symbol_exists(elf_aux_info sys/auxv.h HAVE_ELF_AUX_INFO)
if(HAVE_ELF_AUX_INFO)
set_source_files_properties(arm/aarch${BITS}/jsimd.c PROPERTIES
COMPILE_DEFINITIONS HAVE_ELF_AUX_INFO)
endif()
endif()
add_library(simd OBJECT ${SIMD_SOURCES} arm/aarch${BITS}/jsimd.c)
if(CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED)

View File

@@ -26,10 +26,16 @@
#include <ctype.h>
#if !defined(__ARM_NEON__) && \
(defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO))
#include <sys/auxv.h>
#endif
static THREAD_LOCAL unsigned int simd_support = ~0;
static THREAD_LOCAL unsigned int simd_huffman = 1;
#if !defined(__ARM_NEON__) && (defined(__linux__) || defined(ANDROID) || defined(__ANDROID__))
#if !defined(__ARM_NEON__) && !defined(HAVE_GETAUXVAL) && \
(defined(__linux__) || defined(ANDROID) || defined(__ANDROID__))
#define SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT (1024 * 1024)
@@ -102,8 +108,12 @@ init_simd(void)
#ifndef NO_GETENV
char env[2] = { 0 };
#endif
#if !defined(__ARM_NEON__) && (defined(__linux__) || defined(ANDROID) || defined(__ANDROID__))
#if !defined(__ARM_NEON__)
#if defined(HAVE_GETAUXVAL) || defined(HAVE_ELF_AUX_INFO)
unsigned long cpufeatures = 0;
#elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
int bufsize = 1024; /* an initial guess for the line buffer size limit */
#endif
#endif
if (simd_support != ~0U)
@@ -113,6 +123,10 @@ init_simd(void)
#if defined(__ARM_NEON__)
simd_support |= JSIMD_NEON;
#elif defined(HAVE_GETAUXVAL)
cpufeatures = getauxval(AT_HWCAP);
if (cpufeatures & HWCAP_ARM_NEON)
simd_support |= JSIMD_NEON;
#elif defined(__linux__) || defined(ANDROID) || defined(__ANDROID__)
/* We still have a chance to use Neon regardless of globally used
* -mcpu/-mfpu options passed to gcc by performing runtime detection via
@@ -122,6 +136,10 @@ init_simd(void)
if (bufsize > SOMEWHAT_SANE_PROC_CPUINFO_SIZE_LIMIT)
break;
}
#elif defined(HAVE_ELF_AUX_INFO)
elf_aux_info(AT_HWCAP, &cpufeatures, sizeof(cpufeatures));
if (cpufeatures & HWCAP_NEON)
simd_support |= JSIMD_NEON;
#endif
#ifndef NO_GETENV