Path: blob/master/thirdparty/libpng/powerpc/powerpc_init.c
9897 views
/* powerpc_init.c - POWERPC optimised filter functions1*2* Copyright (c) 2018 Cosmin Truta3* Copyright (c) 2017 Glenn Randers-Pehrson4* Written by Vadim Barkov, 2017.5*6* This code is released under the libpng license.7* For conditions of distribution and use, see the disclaimer8* and license in png.h9*/1011/* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are12* called.13*/14#define _POSIX_SOURCE 11516#include <stdio.h>17#include "../pngpriv.h"1819#ifdef PNG_READ_SUPPORTED2021#if PNG_POWERPC_VSX_OPT > 022#ifdef PNG_POWERPC_VSX_CHECK_SUPPORTED /* Do run-time checks */23/* WARNING: it is strongly recommended that you do not build libpng with24* run-time checks for CPU features if at all possible. In the case of the PowerPC25* VSX instructions there is no processor-specific way of detecting the26* presence of the required support, therefore run-time detection is extremely27* OS specific.28*29* You may set the macro PNG_POWERPC_VSX_FILE to the file name of file containing30* a fragment of C source code which defines the png_have_vsx function. There31* are a number of implementations in contrib/powerpc-vsx, but the only one that32* has partial support is contrib/powerpc-vsx/linux.c - a generic Linux33* implementation which reads /proc/cpufino.34*/35#ifndef PNG_POWERPC_VSX_FILE36# ifdef __linux__37# define PNG_POWERPC_VSX_FILE "contrib/powerpc-vsx/linux_aux.c"38# endif39#endif4041#ifdef PNG_POWERPC_VSX_FILE4243#include <signal.h> /* for sig_atomic_t */44static int png_have_vsx(png_structp png_ptr);45#include PNG_POWERPC_VSX_FILE4647#else /* PNG_POWERPC_VSX_FILE */48# error PNG_POWERPC_VSX_FILE undefined: no support for run-time POWERPC VSX checks49#endif /* PNG_POWERPC_VSX_FILE */50#endif /* PNG_POWERPC_VSX_CHECK_SUPPORTED */5152void53png_init_filter_functions_vsx(png_structp pp, unsigned int bpp)54{55/* The switch statement is compiled in for POWERPC_VSX_API, the call to56* png_have_vsx is compiled in for POWERPC_VSX_CHECK. If both are defined57* the check is only performed if the API has not set the PowerPC option on58* or off explicitly. In this case the check controls what happens.59*/6061#ifdef PNG_POWERPC_VSX_API_SUPPORTED62switch ((pp->options >> PNG_POWERPC_VSX) & 3)63{64case PNG_OPTION_UNSET:65/* Allow the run-time check to execute if it has been enabled -66* thus both API and CHECK can be turned on. If it isn't supported67* this case will fall through to the 'default' below, which just68* returns.69*/70#endif /* PNG_POWERPC_VSX_API_SUPPORTED */71#ifdef PNG_POWERPC_VSX_CHECK_SUPPORTED72{73static volatile sig_atomic_t no_vsx = -1; /* not checked */7475if (no_vsx < 0)76no_vsx = !png_have_vsx(pp);7778if (no_vsx)79return;80}81#ifdef PNG_POWERPC_VSX_API_SUPPORTED82break;83#endif84#endif /* PNG_POWERPC_VSX_CHECK_SUPPORTED */8586#ifdef PNG_POWERPC_VSX_API_SUPPORTED87default: /* OFF or INVALID */88return;8990case PNG_OPTION_ON:91/* Option turned on */92break;93}94#endif9596/* IMPORTANT: any new internal functions used here must be declared using97* PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the98* 'prefix' option to configure works:99*100* ./configure --with-libpng-prefix=foobar_101*102* Verify you have got this right by running the above command, doing a build103* and examining pngprefix.h; it must contain a #define for every external104* function you add. (Notice that this happens automatically for the105* initialization function.)106*/107pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_vsx;108109if (bpp == 3)110{111pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_vsx;112pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_vsx;113pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth3_vsx;114}115116else if (bpp == 4)117{118pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_vsx;119pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_vsx;120pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth4_vsx;121}122}123#endif /* PNG_POWERPC_VSX_OPT > 0 */124#endif /* READ */125126127