From bea573d370e78e9b81f7098b7abb0b65460f7edc Mon Sep 17 00:00:00 2001 From: Vadim Barkov Date: Tue, 31 Jan 2017 11:59:11 +0000 Subject: [PATCH] Added auxv-based VSX detection method for PowerPC and enabled it by default --- contrib/powerpc-vsx/linux_aux.c | 34 +++++++++++++++++++++++++++++++++ powerpc/powerpc_init.c | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 contrib/powerpc-vsx/linux_aux.c 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 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