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