summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Barkov <neverscaired@gmail.com>2017-01-31 11:59:11 +0000
committerVadim Barkov <neverscaired@gmail.com>2017-01-31 11:59:11 +0000
commitbea573d370e78e9b81f7098b7abb0b65460f7edc (patch)
tree8342370c28f8716976095b207d5201537158f20f
parentd0d310f1cb7bd5ddb62850a84da14e8b1e65d9c8 (diff)
Added auxv-based VSX detection method for PowerPC and enabled it by default
-rw-r--r--contrib/powerpc-vsx/linux_aux.c34
-rw-r--r--powerpc/powerpc_init.c2
2 files changed, 35 insertions, 1 deletions
diff --git a/contrib/powerpc-vsx/linux_aux.c b/contrib/powerpc-vsx/linux_aux.c
new file mode 100644
index 000000000..ceb2ab0c3
--- /dev/null
+++ b/contrib/powerpc-vsx/linux_aux.c
@@ -0,0 +1,34 @@
+/* contrib/powerpc-vsx/linux.c
+ *
+ * Copyright (c) 2016 Glenn Randers-Pehrson
+ * Written by Vadim Barkov, 2017.
+ *
+ * This code is released under the libpng license.
+ * For conditions of distribution and use, see the disclaimer
+ * and license in png.h
+ *
+ * SEE contrib/powerpc-vsx/README before reporting bugs
+ *
+ * STATUS: COMPILED
+ * BUG REPORTS: png-mng-implement@sourceforge.net
+ *
+ * png_have_vsx implemented for Linux by reading the widely available
+ * pseudo-file /proc/cpuinfo. Result is cached so if function will be called
+ * multiple times only one reading is perfomed.
+ *
+ * This code is strict ANSI-C and is probably moderately portable; it does
+ * however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.
+ */
+
+#include "sys/auxv.h"
+#include "png.h"
+
+static int
+png_have_vsx(png_structp png_ptr)
+{
+ const unsigned long auxv = getauxval( AT_HWCAP );
+ if(auxv & (PPC_FEATURE_HAS_ALTIVEC|PPC_FEATURE_HAS_VSX ))
+ return 1;
+ else
+ return 0;
+}
diff --git a/powerpc/powerpc_init.c b/powerpc/powerpc_init.c
index d3aeb28db..d406893ce 100644
--- a/powerpc/powerpc_init.c
+++ b/powerpc/powerpc_init.c
@@ -32,7 +32,7 @@
*/
#ifndef PNG_POWERPC_VSX_FILE
# ifdef __linux__
-# define PNG_POWERPC_VSX_FILE "contrib/powerpc-vsx/linux.c"
+# define PNG_POWERPC_VSX_FILE "contrib/powerpc-vsx/linux_aux.c"
# endif
#endif