summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Blanchard <anton@ozlabs.org>2018-07-07 10:49:59 +1000
committerErik de Castro Lopo <erikd@mega-nerd.com>2018-08-20 18:16:34 +1000
commit8e1796b91a1893609b8e2f5813d08f7df3f011cf (patch)
tree2d8ff470341ab5c5c89152527d0851c6e86d091a
parentc0215fc149478963405e5359457f2f1759046f67 (diff)
downloadflac-8e1796b91a1893609b8e2f5813d08f7df3f011cf.tar.gz
Add runtime detection of POWER8 and POWER9
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>
-rw-r--r--src/libFLAC/cpu.c31
-rw-r--r--src/libFLAC/include/private/cpu.h6
2 files changed, 37 insertions, 0 deletions
diff --git a/src/libFLAC/cpu.c b/src/libFLAC/cpu.c
index bf0708c8..64da9cbc 100644
--- a/src/libFLAC/cpu.c
+++ b/src/libFLAC/cpu.c
@@ -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;
diff --git a/src/libFLAC/include/private/cpu.h b/src/libFLAC/include/private/cpu.h
index 676d306b..fc31350e 100644
--- a/src/libFLAC/include/private/cpu.h
+++ b/src/libFLAC/include/private/cpu.h
@@ -153,6 +153,7 @@
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);