arm_init.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* arm_init.c - NEON optimised filter functions
  2. *
  3. * Copyright (c) 2014 Glenn Randers-Pehrson
  4. * Written by Mans Rullgard, 2011.
  5. * Last changed in libpng 1.6.16 [December 22, 2014]
  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. #ifdef PNG_ARM_NEON_API_SUPPORTED
  61. switch ((pp->options >> PNG_ARM_NEON) & 3)
  62. {
  63. case PNG_OPTION_UNSET:
  64. /* Allow the run-time check to execute if it has been enabled -
  65. * thus both API and CHECK can be turned on. If it isn't supported
  66. * this case will fall through to the 'default' below, which just
  67. * returns.
  68. */
  69. #endif /* PNG_ARM_NEON_API_SUPPORTED */
  70. #ifdef PNG_ARM_NEON_CHECK_SUPPORTED
  71. {
  72. static volatile sig_atomic_t no_neon = -1; /* not checked */
  73. if (no_neon < 0)
  74. no_neon = !png_have_neon(pp);
  75. if (no_neon)
  76. return;
  77. }
  78. #ifdef PNG_ARM_NEON_API_SUPPORTED
  79. break;
  80. #endif
  81. #endif /* PNG_ARM_NEON_CHECK_SUPPORTED */
  82. #ifdef PNG_ARM_NEON_API_SUPPORTED
  83. default: /* OFF or INVALID */
  84. return;
  85. case PNG_OPTION_ON:
  86. /* Option turned on */
  87. break;
  88. }
  89. #endif
  90. /* IMPORTANT: any new external functions used here must be declared using
  91. * PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the
  92. * 'prefix' option to configure works:
  93. *
  94. * ./configure --with-libpng-prefix=foobar_
  95. *
  96. * Verify you have got this right by running the above command, doing a build
  97. * and examining pngprefix.h; it must contain a #define for every external
  98. * function you add. (Notice that this happens automatically for the
  99. * initialization function.)
  100. */
  101. pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon;
  102. if (bpp == 3)
  103. {
  104. pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon;
  105. pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon;
  106. pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
  107. png_read_filter_row_paeth3_neon;
  108. }
  109. else if (bpp == 4)
  110. {
  111. pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon;
  112. pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon;
  113. pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =
  114. png_read_filter_row_paeth4_neon;
  115. }
  116. }
  117. #endif /* PNG_ARM_NEON_OPT > 0 */
  118. #endif /* READ */