media/libpng/arm/arm_init.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libpng/arm/arm_init.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,133 @@
     1.4 +
     1.5 +/* arm_init.c - NEON optimised filter functions
     1.6 + *
     1.7 + * Copyright (c) 2014 Glenn Randers-Pehrson
     1.8 + * Written by Mans Rullgard, 2011.
     1.9 + * Last changed in libpng 1.6.10 [March 6, 2014]
    1.10 + *
    1.11 + * This code is released under the libpng license.
    1.12 + * For conditions of distribution and use, see the disclaimer
    1.13 + * and license in png.h
    1.14 + */
    1.15 +/* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are
    1.16 + * called.
    1.17 + */
    1.18 +#define _POSIX_SOURCE 1
    1.19 +
    1.20 +#include "../pngpriv.h"
    1.21 +
    1.22 +#ifdef PNG_READ_SUPPORTED
    1.23 +#if PNG_ARM_NEON_OPT > 0
    1.24 +#ifdef PNG_ARM_NEON_CHECK_SUPPORTED /* Do run-time checks */
    1.25 +/* WARNING: it is strongly recommended that you do not build libpng with
    1.26 + * run-time checks for CPU features if at all possible.  In the case of the ARM
    1.27 + * NEON instructions there is no processor-specific way of detecting the
    1.28 + * presense of the required support, therefore run-time detectioon is extremely
    1.29 + * OS specific.
    1.30 + *
    1.31 + * You may set the macro PNG_ARM_NEON_FILE to the file name of file containing
    1.32 + * a fragment of C source code which defines the png_have_neon function.  There
    1.33 + * are a number of implementations in contrib/arm-neon, but the only one that
    1.34 + * has partial support is contrib/arm-neon/linux.c - a generic Linux
    1.35 + * implementation which reads /proc/cpufino.
    1.36 + */
    1.37 +#ifndef PNG_ARM_NEON_FILE
    1.38 +#  ifdef __linux__
    1.39 +#     define PNG_ARM_NEON_FILE "linux.c"
    1.40 +#  endif
    1.41 +#endif
    1.42 +
    1.43 +#ifdef PNG_ARM_NEON_FILE
    1.44 +
    1.45 +#include <signal.h> /* for sig_atomic_t */
    1.46 +static int png_have_neon(png_structp png_ptr);
    1.47 +#include PNG_ARM_NEON_FILE
    1.48 +
    1.49 +#else  /* PNG_ARM_NEON_FILE */
    1.50 +#  error "PNG_ARM_NEON_FILE undefined: no support for run-time ARM NEON checks"
    1.51 +#endif /* PNG_ARM_NEON_FILE */
    1.52 +#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */
    1.53 +
    1.54 +#ifndef PNG_ALIGNED_MEMORY_SUPPORTED
    1.55 +#  error "ALIGNED_MEMORY is required; set: -DPNG_ALIGNED_MEMORY_SUPPORTED"
    1.56 +#endif
    1.57 +
    1.58 +void
    1.59 +png_init_filter_functions_neon(png_structp pp, unsigned int bpp)
    1.60 +{
    1.61 +   /* The switch statement is compiled in for ARM_NEON_API, the call to
    1.62 +    * png_have_neon is compiled in for ARM_NEON_CHECK.  If both are defined
    1.63 +    * the check is only performed if the API has not set the NEON option on
    1.64 +    * or off explicitly.  In this case the check controls what happens.
    1.65 +    *
    1.66 +    * If the CHECK is not compiled in and the option is UNSET the behavior prior
    1.67 +    * to 1.6.7 was to use the NEON code - this was a bug caused by having the
    1.68 +    * wrong order of the 'ON' and 'default' cases.  UNSET now defaults to OFF,
    1.69 +    * as documented in png.h
    1.70 +    */
    1.71 +#ifdef PNG_ARM_NEON_API_SUPPORTED
    1.72 +   switch ((pp->options >> PNG_ARM_NEON) & 3)
    1.73 +   {
    1.74 +      case PNG_OPTION_UNSET:
    1.75 +         /* Allow the run-time check to execute if it has been enabled -
    1.76 +          * thus both API and CHECK can be turned on.  If it isn't supported
    1.77 +          * this case will fall through to the 'default' below, which just
    1.78 +          * returns.
    1.79 +          */
    1.80 +#endif /* PNG_ARM_NEON_API_SUPPORTED */
    1.81 +#ifdef PNG_ARM_NEON_CHECK_SUPPORTED
    1.82 +         {
    1.83 +            static volatile sig_atomic_t no_neon = -1; /* not checked */
    1.84 +
    1.85 +            if (no_neon < 0)
    1.86 +               no_neon = !png_have_neon(pp);
    1.87 +
    1.88 +            if (no_neon)
    1.89 +               return;
    1.90 +         }
    1.91 +#ifdef PNG_ARM_NEON_API_SUPPORTED
    1.92 +         break;
    1.93 +#endif
    1.94 +#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */
    1.95 +
    1.96 +#ifdef PNG_ARM_NEON_API_SUPPORTED
    1.97 +      default: /* OFF or INVALID */
    1.98 +         return;
    1.99 +
   1.100 +      case PNG_OPTION_ON:
   1.101 +         /* Option turned on */
   1.102 +         break;
   1.103 +   }
   1.104 +#endif
   1.105 +
   1.106 +   /* IMPORTANT: any new external functions used here must be declared using
   1.107 +    * PNG_INTERNAL_FUNCTION in ../pngpriv.h.  This is required so that the
   1.108 +    * 'prefix' option to configure works:
   1.109 +    *
   1.110 +    *    ./configure --with-libpng-prefix=foobar_
   1.111 +    *
   1.112 +    * Verify you have got this right by running the above command, doing a build
   1.113 +    * and examining pngprefix.h; it must contain a #define for every external
   1.114 +    * function you add.  (Notice that this happens automatically for the
   1.115 +    * initialization function.)
   1.116 +    */
   1.117 +   pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon;
   1.118 +
   1.119 +   if (bpp == 3)
   1.120 +   {
   1.121 +      pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon;
   1.122 +      pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon;
   1.123 +      pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
   1.124 +         png_read_filter_row_paeth3_neon;
   1.125 +   }
   1.126 +
   1.127 +   else if (bpp == 4)
   1.128 +   {
   1.129 +      pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon;
   1.130 +      pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon;
   1.131 +      pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
   1.132 +          png_read_filter_row_paeth4_neon;
   1.133 +   }
   1.134 +}
   1.135 +#endif /* PNG_ARM_NEON_OPT > 0 */
   1.136 +#endif /* PNG_READ_SUPPORTED */

mercurial