Add runtime detection of POWER8 and POWER9
authorAnton Blanchard <anton@ozlabs.org>
Sat, 7 Jul 2018 00:49:59 +0000 (10:49 +1000)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Mon, 20 Aug 2018 08:16:34 +0000 (18:16 +1000)
Use getauxval() to determine if we are on POWER8 or POWER9 or newer.
POWER8 is represented by version 2.07 and POWER9 by version 3.00.

Signed-off-by: Anton Blanchard <anton@ozlabs.org>
src/libFLAC/cpu.c
src/libFLAC/include/private/cpu.h

index bf0708c..64da9cb 100644 (file)
@@ -53,6 +53,9 @@
 #define dfprintf(file, format, ...)
 #endif
 
+#if defined FLAC__CPU_PPC
+#include <sys/auxv.h>
+#endif
 
 #if (defined FLAC__CPU_IA32 || defined FLAC__CPU_X86_64) && (defined FLAC__HAS_NASM || FLAC__HAS_X86INTRIN) && !defined FLAC__NO_ASM
 
@@ -230,6 +233,29 @@ x86_cpu_info (FLAC__CPUInfo *info)
 #endif
 }
 
+static void
+ppc_cpu_info (FLAC__CPUInfo *info)
+{
+#if defined FLAC__CPU_PPC
+#ifndef PPC_FEATURE2_ARCH_3_00
+#define PPC_FEATURE2_ARCH_3_00         0x00800000
+#endif
+
+#ifndef PPC_FEATURE2_ARCH_2_07
+#define PPC_FEATURE2_ARCH_2_07         0x80000000
+#endif
+
+       if (getauxval(AT_HWCAP2) & PPC_FEATURE2_ARCH_3_00) {
+               info->ppc.arch_3_00 = true;
+       } else if (getauxval(AT_HWCAP2) & PPC_FEATURE2_ARCH_2_07) {
+               info->ppc.arch_2_07 = true;
+       }
+#else
+       info->ppc.arch_2_07 = false;
+       info->ppc.arch_3_00 = false;
+#endif
+}
+
 void FLAC__cpu_info (FLAC__CPUInfo *info)
 {
        memset(info, 0, sizeof(*info));
@@ -238,6 +264,8 @@ void FLAC__cpu_info (FLAC__CPUInfo *info)
        info->type = FLAC__CPUINFO_TYPE_IA32;
 #elif defined FLAC__CPU_X86_64
        info->type = FLAC__CPUINFO_TYPE_X86_64;
+#elif defined FLAC__CPU_PPC
+       info->type = FLAC__CPUINFO_TYPE_PPC;
 #else
        info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
 #endif
@@ -247,6 +275,9 @@ void FLAC__cpu_info (FLAC__CPUInfo *info)
        case FLAC__CPUINFO_TYPE_X86_64:
                x86_cpu_info (info);
                break;
+       case FLAC__CPUINFO_TYPE_PPC:
+               ppc_cpu_info (info);
+               break;
        default:
                info->use_asm = false;
                break;
index 676d306..fc31350 100644 (file)
 typedef enum {
        FLAC__CPUINFO_TYPE_IA32,
        FLAC__CPUINFO_TYPE_X86_64,
+       FLAC__CPUINFO_TYPE_PPC,
        FLAC__CPUINFO_TYPE_UNKNOWN
 } FLAC__CPUInfo_Type;
 
@@ -173,11 +174,16 @@ typedef struct {
        FLAC__bool fma;
 } FLAC__CPUInfo_x86;
 
+typedef struct {
+       FLAC__bool arch_3_00;
+       FLAC__bool arch_2_07;
+} FLAC__CPUInfo_ppc;
 
 typedef struct {
        FLAC__bool use_asm;
        FLAC__CPUInfo_Type type;
        FLAC__CPUInfo_x86 x86;
+       FLAC__CPUInfo_ppc ppc;
 } FLAC__CPUInfo;
 
 void FLAC__cpu_info(FLAC__CPUInfo *info);