CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/ext/libpng17/arm/arm_init.c
Views: 1401
1/* arm_init.c - NEON optimised filter functions2*3* Copyright (c) 2014 Glenn Randers-Pehrson4* Written by Mans Rullgard, 2011.5* Last changed in libpng 1.6.16 [December 22, 2014]6*7* This code is released under the libpng license.8* For conditions of distribution and use, see the disclaimer9* and license in png.h10*/11/* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are12* called.13*/14#define _POSIX_SOURCE 11516#include "../pngpriv.h"17#define PNG_SRC_FILE PNG_SRC_FILE_arm_arm_init1819#ifdef PNG_READ_SUPPORTED2021#if PNG_ARM_NEON_OPT > 022#ifdef PNG_ARM_NEON_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 ARM25* NEON 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_ARM_NEON_FILE to the file name of file containing30* a fragment of C source code which defines the png_have_neon function. There31* are a number of implementations in contrib/arm-neon, but the only one that32* has partial support is contrib/arm-neon/linux.c - a generic Linux33* implementation which reads /proc/cpufino.34*/35#ifndef PNG_ARM_NEON_FILE36# ifdef __linux__37# define PNG_ARM_NEON_FILE "contrib/arm-neon/linux.c"38# endif39#endif4041#ifdef PNG_ARM_NEON_FILE4243#include <signal.h> /* for sig_atomic_t */44static int png_have_neon(png_structp png_ptr);45#include PNG_ARM_NEON_FILE4647#else /* PNG_ARM_NEON_FILE */48# error "PNG_ARM_NEON_FILE undefined: no support for run-time ARM NEON checks"49#endif /* PNG_ARM_NEON_FILE */50#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */5152#ifndef PNG_ALIGNED_MEMORY_SUPPORTED53# error "ALIGNED_MEMORY is required; set: -DPNG_ALIGNED_MEMORY_SUPPORTED"54#endif5556void57png_init_filter_functions_neon(png_structp pp, unsigned int bpp)58{59/* The switch statement is compiled in for ARM_NEON_API, the call to60* png_have_neon is compiled in for ARM_NEON_CHECK. If both are defined61* the check is only performed if the API has not set the NEON option on62* or off explicitly. In this case the check controls what happens.63*64* If the CHECK is not compiled in and the option is UNSET the behavior prior65* to 1.6.7 was to use the NEON code - this was a bug caused by having the66* wrong order of the 'ON' and 'default' cases. UNSET now defaults to OFF,67* as documented in png.h68*/69#ifdef PNG_ARM_NEON_API_SUPPORTED70switch ((pp->options >> PNG_ARM_NEON) & 3)71{72case PNG_OPTION_UNSET:73/* Allow the run-time check to execute if it has been enabled -74* thus both API and CHECK can be turned on. If it isn't supported75* this case will fall through to the 'default' below, which just76* returns.77*/78#endif /* PNG_ARM_NEON_API_SUPPORTED */79#ifdef PNG_ARM_NEON_CHECK_SUPPORTED80{81static volatile sig_atomic_t no_neon = -1; /* not checked */8283if (no_neon < 0)84no_neon = !png_have_neon(pp);8586if (no_neon)87return;88}89#ifdef PNG_ARM_NEON_API_SUPPORTED90break;91#endif92#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */9394#ifdef PNG_ARM_NEON_API_SUPPORTED95default: /* OFF or INVALID */96return;9798case PNG_OPTION_ON:99/* Option turned on */100break;101}102#endif103104/* IMPORTANT: any new external functions used here must be declared using105* PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the106* 'prefix' option to configure works:107*108* ./configure --with-libpng-prefix=foobar_109*110* Verify you have got this right by running the above command, doing a build111* and examining pngprefix.h; it must contain a #define for every external112* function you add. (Notice that this happens automatically for the113* initialization function.)114*/115pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon;116117if (bpp == 3)118{119pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon;120pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon;121pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =122png_read_filter_row_paeth3_neon;123}124125else if (bpp == 4)126{127pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon;128pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon;129pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =130png_read_filter_row_paeth4_neon;131}132}133#endif /* PNG_ARM_NEON_OPT > 0 */134#endif /* READ */135136137