arm_init.c 4.6 KB

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