michael@0: michael@0: /* arm_init.c - NEON optimised filter functions michael@0: * michael@0: * Copyright (c) 2014 Glenn Randers-Pehrson michael@0: * Written by Mans Rullgard, 2011. michael@0: * Last changed in libpng 1.6.10 [March 6, 2014] michael@0: * michael@0: * This code is released under the libpng license. michael@0: * For conditions of distribution and use, see the disclaimer michael@0: * and license in png.h michael@0: */ michael@0: /* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are michael@0: * called. michael@0: */ michael@0: #define _POSIX_SOURCE 1 michael@0: michael@0: #include "../pngpriv.h" michael@0: michael@0: #ifdef PNG_READ_SUPPORTED michael@0: #if PNG_ARM_NEON_OPT > 0 michael@0: #ifdef PNG_ARM_NEON_CHECK_SUPPORTED /* Do run-time checks */ michael@0: /* WARNING: it is strongly recommended that you do not build libpng with michael@0: * run-time checks for CPU features if at all possible. In the case of the ARM michael@0: * NEON instructions there is no processor-specific way of detecting the michael@0: * presense of the required support, therefore run-time detectioon is extremely michael@0: * OS specific. michael@0: * michael@0: * You may set the macro PNG_ARM_NEON_FILE to the file name of file containing michael@0: * a fragment of C source code which defines the png_have_neon function. There michael@0: * are a number of implementations in contrib/arm-neon, but the only one that michael@0: * has partial support is contrib/arm-neon/linux.c - a generic Linux michael@0: * implementation which reads /proc/cpufino. michael@0: */ michael@0: #ifndef PNG_ARM_NEON_FILE michael@0: # ifdef __linux__ michael@0: # define PNG_ARM_NEON_FILE "linux.c" michael@0: # endif michael@0: #endif michael@0: michael@0: #ifdef PNG_ARM_NEON_FILE michael@0: michael@0: #include /* for sig_atomic_t */ michael@0: static int png_have_neon(png_structp png_ptr); michael@0: #include PNG_ARM_NEON_FILE michael@0: michael@0: #else /* PNG_ARM_NEON_FILE */ michael@0: # error "PNG_ARM_NEON_FILE undefined: no support for run-time ARM NEON checks" michael@0: #endif /* PNG_ARM_NEON_FILE */ michael@0: #endif /* PNG_ARM_NEON_CHECK_SUPPORTED */ michael@0: michael@0: #ifndef PNG_ALIGNED_MEMORY_SUPPORTED michael@0: # error "ALIGNED_MEMORY is required; set: -DPNG_ALIGNED_MEMORY_SUPPORTED" michael@0: #endif michael@0: michael@0: void michael@0: png_init_filter_functions_neon(png_structp pp, unsigned int bpp) michael@0: { michael@0: /* The switch statement is compiled in for ARM_NEON_API, the call to michael@0: * png_have_neon is compiled in for ARM_NEON_CHECK. If both are defined michael@0: * the check is only performed if the API has not set the NEON option on michael@0: * or off explicitly. In this case the check controls what happens. michael@0: * michael@0: * If the CHECK is not compiled in and the option is UNSET the behavior prior michael@0: * to 1.6.7 was to use the NEON code - this was a bug caused by having the michael@0: * wrong order of the 'ON' and 'default' cases. UNSET now defaults to OFF, michael@0: * as documented in png.h michael@0: */ michael@0: #ifdef PNG_ARM_NEON_API_SUPPORTED michael@0: switch ((pp->options >> PNG_ARM_NEON) & 3) michael@0: { michael@0: case PNG_OPTION_UNSET: michael@0: /* Allow the run-time check to execute if it has been enabled - michael@0: * thus both API and CHECK can be turned on. If it isn't supported michael@0: * this case will fall through to the 'default' below, which just michael@0: * returns. michael@0: */ michael@0: #endif /* PNG_ARM_NEON_API_SUPPORTED */ michael@0: #ifdef PNG_ARM_NEON_CHECK_SUPPORTED michael@0: { michael@0: static volatile sig_atomic_t no_neon = -1; /* not checked */ michael@0: michael@0: if (no_neon < 0) michael@0: no_neon = !png_have_neon(pp); michael@0: michael@0: if (no_neon) michael@0: return; michael@0: } michael@0: #ifdef PNG_ARM_NEON_API_SUPPORTED michael@0: break; michael@0: #endif michael@0: #endif /* PNG_ARM_NEON_CHECK_SUPPORTED */ michael@0: michael@0: #ifdef PNG_ARM_NEON_API_SUPPORTED michael@0: default: /* OFF or INVALID */ michael@0: return; michael@0: michael@0: case PNG_OPTION_ON: michael@0: /* Option turned on */ michael@0: break; michael@0: } michael@0: #endif michael@0: michael@0: /* IMPORTANT: any new external functions used here must be declared using michael@0: * PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the michael@0: * 'prefix' option to configure works: michael@0: * michael@0: * ./configure --with-libpng-prefix=foobar_ michael@0: * michael@0: * Verify you have got this right by running the above command, doing a build michael@0: * and examining pngprefix.h; it must contain a #define for every external michael@0: * function you add. (Notice that this happens automatically for the michael@0: * initialization function.) michael@0: */ michael@0: pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon; michael@0: michael@0: if (bpp == 3) michael@0: { michael@0: pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon; michael@0: pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon; michael@0: pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = michael@0: png_read_filter_row_paeth3_neon; michael@0: } michael@0: michael@0: else if (bpp == 4) michael@0: { michael@0: pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon; michael@0: pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon; michael@0: pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = michael@0: png_read_filter_row_paeth4_neon; michael@0: } michael@0: } michael@0: #endif /* PNG_ARM_NEON_OPT > 0 */ michael@0: #endif /* PNG_READ_SUPPORTED */