diff mbox series

[FFmpeg-devel,v3] libavutil/ppc: Make use of getauxval() and elf_aux_info() on ppc

Message ID ZuZzLtX6neHIgY3Q@humpty.home.comstyle.com
State New
Headers show
Series [FFmpeg-devel,v3] libavutil/ppc: Make use of getauxval() and elf_aux_info() on ppc | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Brad Smith Sept. 15, 2024, 5:39 a.m. UTC
libavutil/ppc: Make use of getauxval() and elf_aux_info() on ppc

Modern Linux has getauxval() and FreeBSD/OpenBSD ppc have elf_aux_info().

Signed-off-by: Brad Smith <brad@comstyle.com>
---
v2: adjust to build with older glibc.
v3: freebsd/ppc requires machine/cpu.h header for feature flags.

 libavutil/ppc/cpu.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Comments

Brad Smith Sept. 20, 2024, 10:50 p.m. UTC | #1
ping.

On 2024-09-15 1:40 a.m., Brad Smith wrote:
> libavutil/ppc: Make use of getauxval() and elf_aux_info() on ppc
>
> Modern Linux has getauxval() and FreeBSD/OpenBSD ppc have elf_aux_info().
>
> Signed-off-by: Brad Smith <brad@comstyle.com>
> ---
> v2: adjust to build with older glibc.
> v3: freebsd/ppc requires machine/cpu.h header for feature flags.
>
>   libavutil/ppc/cpu.c | 25 +++++++++++++++++++++++++
>   1 file changed, 25 insertions(+)
>
> diff --git a/libavutil/ppc/cpu.c b/libavutil/ppc/cpu.c
> index 2b13cda662..9381272175 100644
> --- a/libavutil/ppc/cpu.c
> +++ b/libavutil/ppc/cpu.c
> @@ -20,6 +20,11 @@
>   
>   #ifdef __APPLE__
>   #include <sys/sysctl.h>
> +#elif HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
> +#ifdef __FreeBSD__
> +#include <machine/cpu.h>
> +#endif
> +#include <sys/auxv.h>
>   #elif defined(__linux__)
>   #include <asm/cputable.h>
>   #include <linux/auxvec.h>
> @@ -56,6 +61,26 @@ int ff_get_cpu_flags_ppc(void)
>       if (result == VECTORTYPE_ALTIVEC)
>           return AV_CPU_FLAG_ALTIVEC;
>       return 0;
> +#elif HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
> +    int flags = 0;
> +
> +    unsigned long hwcap = ff_getauxval(AT_HWCAP);
> +#ifdef PPC_FEATURE2_ARCH_2_07
> +    unsigned long hwcap2 = ff_getauxval(AT_HWCAP2);
> +#endif
> +
> +    if (hwcap & PPC_FEATURE_HAS_ALTIVEC)
> +       flags |= AV_CPU_FLAG_ALTIVEC;
> +#ifdef PPC_FEATURE_HAS_VSX
> +    if (hwcap & PPC_FEATURE_HAS_VSX)
> +       flags |= AV_CPU_FLAG_VSX;
> +#endif
> +#ifdef PPC_FEATURE2_ARCH_2_07
> +    if (hwcap2 & PPC_FEATURE2_ARCH_2_07)
> +       flags |= AV_CPU_FLAG_POWER8;
> +#endif
> +
> +    return flags;
>   #elif defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__)
>   #if defined(__NetBSD__) || defined(__OpenBSD__)
>       int sels[2] = {CTL_MACHDEP, CPU_ALTIVEC};
Martin Storsjö Sept. 21, 2024, 6:20 a.m. UTC | #2
On Fri, 20 Sep 2024, Brad Smith wrote:

> ping.
>
> On 2024-09-15 1:40 a.m., Brad Smith wrote:
>> libavutil/ppc: Make use of getauxval() and elf_aux_info() on ppc
>> 
>> Modern Linux has getauxval() and FreeBSD/OpenBSD ppc have 
>> elf_aux_info().
>> 
>> Signed-off-by: Brad Smith <brad@comstyle.com>
>> ---
>> v2: adjust to build with older glibc.
>> v3: freebsd/ppc requires machine/cpu.h header for feature flags.
>>
>>   libavutil/ppc/cpu.c | 25 +++++++++++++++++++++++++
>>   1 file changed, 25 insertions(+)
>> 
>> diff --git a/libavutil/ppc/cpu.c b/libavutil/ppc/cpu.c
>> index 2b13cda662..9381272175 100644
>> --- a/libavutil/ppc/cpu.c
>> +++ b/libavutil/ppc/cpu.c
>> @@ -20,6 +20,11 @@
>>     #ifdef __APPLE__
>>   #include <sys/sysctl.h>
>> +#elif HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
>> +#ifdef __FreeBSD__
>> +#include <machine/cpu.h>
>> +#endif
>> +#include <sys/auxv.h>
>>   #elif defined(__linux__)
>>   #include <asm/cputable.h>
>>   #include <linux/auxvec.h>
>> @@ -56,6 +61,26 @@ int ff_get_cpu_flags_ppc(void)
>>       if (result == VECTORTYPE_ALTIVEC)
>>           return AV_CPU_FLAG_ALTIVEC;
>>       return 0;
>> +#elif HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
>> +    int flags = 0;
>> +
>> +    unsigned long hwcap = ff_getauxval(AT_HWCAP);
>> +#ifdef PPC_FEATURE2_ARCH_2_07
>> +    unsigned long hwcap2 = ff_getauxval(AT_HWCAP2);
>> +#endif
>> +
>> +    if (hwcap & PPC_FEATURE_HAS_ALTIVEC)
>> +       flags |= AV_CPU_FLAG_ALTIVEC;
>> +#ifdef PPC_FEATURE_HAS_VSX
>> +    if (hwcap & PPC_FEATURE_HAS_VSX)
>> +       flags |= AV_CPU_FLAG_VSX;
>> +#endif
>> +#ifdef PPC_FEATURE2_ARCH_2_07
>> +    if (hwcap2 & PPC_FEATURE2_ARCH_2_07)
>> +       flags |= AV_CPU_FLAG_POWER8;
>> +#endif
>> +
>> +    return flags;
>>   #elif defined(__APPLE__) || defined(__NetBSD__) || 
>> defined(__OpenBSD__)
>>   #if defined(__NetBSD__) || defined(__OpenBSD__)
>>       int sels[2] = {CTL_MACHDEP, CPU_ALTIVEC};

I don'k know much specifically about ppc, but the patch seems reasonable 
to me.

// Martin
diff mbox series

Patch

diff --git a/libavutil/ppc/cpu.c b/libavutil/ppc/cpu.c
index 2b13cda662..9381272175 100644
--- a/libavutil/ppc/cpu.c
+++ b/libavutil/ppc/cpu.c
@@ -20,6 +20,11 @@ 
 
 #ifdef __APPLE__
 #include <sys/sysctl.h>
+#elif HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
+#ifdef __FreeBSD__
+#include <machine/cpu.h>
+#endif
+#include <sys/auxv.h>
 #elif defined(__linux__)
 #include <asm/cputable.h>
 #include <linux/auxvec.h>
@@ -56,6 +61,26 @@  int ff_get_cpu_flags_ppc(void)
     if (result == VECTORTYPE_ALTIVEC)
         return AV_CPU_FLAG_ALTIVEC;
     return 0;
+#elif HAVE_GETAUXVAL || HAVE_ELF_AUX_INFO
+    int flags = 0;
+
+    unsigned long hwcap = ff_getauxval(AT_HWCAP);
+#ifdef PPC_FEATURE2_ARCH_2_07
+    unsigned long hwcap2 = ff_getauxval(AT_HWCAP2);
+#endif
+
+    if (hwcap & PPC_FEATURE_HAS_ALTIVEC)
+       flags |= AV_CPU_FLAG_ALTIVEC;
+#ifdef PPC_FEATURE_HAS_VSX
+    if (hwcap & PPC_FEATURE_HAS_VSX)
+       flags |= AV_CPU_FLAG_VSX;
+#endif
+#ifdef PPC_FEATURE2_ARCH_2_07
+    if (hwcap2 & PPC_FEATURE2_ARCH_2_07)
+       flags |= AV_CPU_FLAG_POWER8;
+#endif
+
+    return flags;
 #elif defined(__APPLE__) || defined(__NetBSD__) || defined(__OpenBSD__)
 #if defined(__NetBSD__) || defined(__OpenBSD__)
     int sels[2] = {CTL_MACHDEP, CPU_ALTIVEC};