media/libpng/arm/arm_init.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1
michael@0 2 /* arm_init.c - NEON optimised filter functions
michael@0 3 *
michael@0 4 * Copyright (c) 2014 Glenn Randers-Pehrson
michael@0 5 * Written by Mans Rullgard, 2011.
michael@0 6 * Last changed in libpng 1.6.10 [March 6, 2014]
michael@0 7 *
michael@0 8 * This code is released under the libpng license.
michael@0 9 * For conditions of distribution and use, see the disclaimer
michael@0 10 * and license in png.h
michael@0 11 */
michael@0 12 /* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are
michael@0 13 * called.
michael@0 14 */
michael@0 15 #define _POSIX_SOURCE 1
michael@0 16
michael@0 17 #include "../pngpriv.h"
michael@0 18
michael@0 19 #ifdef PNG_READ_SUPPORTED
michael@0 20 #if PNG_ARM_NEON_OPT > 0
michael@0 21 #ifdef PNG_ARM_NEON_CHECK_SUPPORTED /* Do run-time checks */
michael@0 22 /* WARNING: it is strongly recommended that you do not build libpng with
michael@0 23 * run-time checks for CPU features if at all possible. In the case of the ARM
michael@0 24 * NEON instructions there is no processor-specific way of detecting the
michael@0 25 * presense of the required support, therefore run-time detectioon is extremely
michael@0 26 * OS specific.
michael@0 27 *
michael@0 28 * You may set the macro PNG_ARM_NEON_FILE to the file name of file containing
michael@0 29 * a fragment of C source code which defines the png_have_neon function. There
michael@0 30 * are a number of implementations in contrib/arm-neon, but the only one that
michael@0 31 * has partial support is contrib/arm-neon/linux.c - a generic Linux
michael@0 32 * implementation which reads /proc/cpufino.
michael@0 33 */
michael@0 34 #ifndef PNG_ARM_NEON_FILE
michael@0 35 # ifdef __linux__
michael@0 36 # define PNG_ARM_NEON_FILE "linux.c"
michael@0 37 # endif
michael@0 38 #endif
michael@0 39
michael@0 40 #ifdef PNG_ARM_NEON_FILE
michael@0 41
michael@0 42 #include <signal.h> /* for sig_atomic_t */
michael@0 43 static int png_have_neon(png_structp png_ptr);
michael@0 44 #include PNG_ARM_NEON_FILE
michael@0 45
michael@0 46 #else /* PNG_ARM_NEON_FILE */
michael@0 47 # error "PNG_ARM_NEON_FILE undefined: no support for run-time ARM NEON checks"
michael@0 48 #endif /* PNG_ARM_NEON_FILE */
michael@0 49 #endif /* PNG_ARM_NEON_CHECK_SUPPORTED */
michael@0 50
michael@0 51 #ifndef PNG_ALIGNED_MEMORY_SUPPORTED
michael@0 52 # error "ALIGNED_MEMORY is required; set: -DPNG_ALIGNED_MEMORY_SUPPORTED"
michael@0 53 #endif
michael@0 54
michael@0 55 void
michael@0 56 png_init_filter_functions_neon(png_structp pp, unsigned int bpp)
michael@0 57 {
michael@0 58 /* The switch statement is compiled in for ARM_NEON_API, the call to
michael@0 59 * png_have_neon is compiled in for ARM_NEON_CHECK. If both are defined
michael@0 60 * the check is only performed if the API has not set the NEON option on
michael@0 61 * or off explicitly. In this case the check controls what happens.
michael@0 62 *
michael@0 63 * If the CHECK is not compiled in and the option is UNSET the behavior prior
michael@0 64 * to 1.6.7 was to use the NEON code - this was a bug caused by having the
michael@0 65 * wrong order of the 'ON' and 'default' cases. UNSET now defaults to OFF,
michael@0 66 * as documented in png.h
michael@0 67 */
michael@0 68 #ifdef PNG_ARM_NEON_API_SUPPORTED
michael@0 69 switch ((pp->options >> PNG_ARM_NEON) & 3)
michael@0 70 {
michael@0 71 case PNG_OPTION_UNSET:
michael@0 72 /* Allow the run-time check to execute if it has been enabled -
michael@0 73 * thus both API and CHECK can be turned on. If it isn't supported
michael@0 74 * this case will fall through to the 'default' below, which just
michael@0 75 * returns.
michael@0 76 */
michael@0 77 #endif /* PNG_ARM_NEON_API_SUPPORTED */
michael@0 78 #ifdef PNG_ARM_NEON_CHECK_SUPPORTED
michael@0 79 {
michael@0 80 static volatile sig_atomic_t no_neon = -1; /* not checked */
michael@0 81
michael@0 82 if (no_neon < 0)
michael@0 83 no_neon = !png_have_neon(pp);
michael@0 84
michael@0 85 if (no_neon)
michael@0 86 return;
michael@0 87 }
michael@0 88 #ifdef PNG_ARM_NEON_API_SUPPORTED
michael@0 89 break;
michael@0 90 #endif
michael@0 91 #endif /* PNG_ARM_NEON_CHECK_SUPPORTED */
michael@0 92
michael@0 93 #ifdef PNG_ARM_NEON_API_SUPPORTED
michael@0 94 default: /* OFF or INVALID */
michael@0 95 return;
michael@0 96
michael@0 97 case PNG_OPTION_ON:
michael@0 98 /* Option turned on */
michael@0 99 break;
michael@0 100 }
michael@0 101 #endif
michael@0 102
michael@0 103 /* IMPORTANT: any new external functions used here must be declared using
michael@0 104 * PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the
michael@0 105 * 'prefix' option to configure works:
michael@0 106 *
michael@0 107 * ./configure --with-libpng-prefix=foobar_
michael@0 108 *
michael@0 109 * Verify you have got this right by running the above command, doing a build
michael@0 110 * and examining pngprefix.h; it must contain a #define for every external
michael@0 111 * function you add. (Notice that this happens automatically for the
michael@0 112 * initialization function.)
michael@0 113 */
michael@0 114 pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon;
michael@0 115
michael@0 116 if (bpp == 3)
michael@0 117 {
michael@0 118 pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon;
michael@0 119 pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon;
michael@0 120 pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
michael@0 121 png_read_filter_row_paeth3_neon;
michael@0 122 }
michael@0 123
michael@0 124 else if (bpp == 4)
michael@0 125 {
michael@0 126 pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon;
michael@0 127 pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon;
michael@0 128 pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
michael@0 129 png_read_filter_row_paeth4_neon;
michael@0 130 }
michael@0 131 }
michael@0 132 #endif /* PNG_ARM_NEON_OPT > 0 */
michael@0 133 #endif /* PNG_READ_SUPPORTED */

mercurial