powerpc_init.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* powerpc_init.c - POWERPC optimised filter functions
  2. *
  3. * Copyright (c) 2018 Cosmin Truta
  4. * Copyright (c) 2017 Glenn Randers-Pehrson
  5. * Written by Vadim Barkov, 2017.
  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 <stdio.h>
  16. #include "../pngpriv.h"
  17. #ifdef PNG_READ_SUPPORTED
  18. #if PNG_POWERPC_VSX_OPT > 0
  19. #ifdef PNG_POWERPC_VSX_CHECK_SUPPORTED /* Do run-time checks */
  20. /* WARNING: it is strongly recommended that you do not build libpng with
  21. * run-time checks for CPU features if at all possible. In the case of the PowerPC
  22. * VSX instructions there is no processor-specific way of detecting the
  23. * presence of the required support, therefore run-time detection is extremely
  24. * OS specific.
  25. *
  26. * You may set the macro PNG_POWERPC_VSX_FILE to the file name of file containing
  27. * a fragment of C source code which defines the png_have_vsx function. There
  28. * are a number of implementations in contrib/powerpc-vsx, but the only one that
  29. * has partial support is contrib/powerpc-vsx/linux.c - a generic Linux
  30. * implementation which reads /proc/cpufino.
  31. */
  32. #ifndef PNG_POWERPC_VSX_FILE
  33. # ifdef __linux__
  34. # define PNG_POWERPC_VSX_FILE "contrib/powerpc-vsx/linux_aux.c"
  35. # endif
  36. #endif
  37. #ifdef PNG_POWERPC_VSX_FILE
  38. #include <signal.h> /* for sig_atomic_t */
  39. static int png_have_vsx(png_structp png_ptr);
  40. #error #include PNG_POWERPC_VSX_FILE
  41. #else /* PNG_POWERPC_VSX_FILE */
  42. # error "PNG_POWERPC_VSX_FILE undefined: no support for run-time POWERPC VSX checks"
  43. #endif /* PNG_POWERPC_VSX_FILE */
  44. #endif /* PNG_POWERPC_VSX_CHECK_SUPPORTED */
  45. void
  46. png_init_filter_functions_vsx(png_structp pp, unsigned int bpp)
  47. {
  48. /* The switch statement is compiled in for POWERPC_VSX_API, the call to
  49. * png_have_vsx is compiled in for POWERPC_VSX_CHECK. If both are defined
  50. * the check is only performed if the API has not set the PowerPC option on
  51. * or off explicitly. In this case the check controls what happens.
  52. */
  53. #ifdef PNG_POWERPC_VSX_API_SUPPORTED
  54. switch ((pp->options >> PNG_POWERPC_VSX) & 3)
  55. {
  56. case PNG_OPTION_UNSET:
  57. /* Allow the run-time check to execute if it has been enabled -
  58. * thus both API and CHECK can be turned on. If it isn't supported
  59. * this case will fall through to the 'default' below, which just
  60. * returns.
  61. */
  62. #endif /* PNG_POWERPC_VSX_API_SUPPORTED */
  63. #ifdef PNG_POWERPC_VSX_CHECK_SUPPORTED
  64. {
  65. static volatile sig_atomic_t no_vsx = -1; /* not checked */
  66. if (no_vsx < 0)
  67. no_vsx = !png_have_vsx(pp);
  68. if (no_vsx)
  69. return;
  70. }
  71. #ifdef PNG_POWERPC_VSX_API_SUPPORTED
  72. break;
  73. #endif
  74. #endif /* PNG_POWERPC_VSX_CHECK_SUPPORTED */
  75. #ifdef PNG_POWERPC_VSX_API_SUPPORTED
  76. default: /* OFF or INVALID */
  77. return;
  78. case PNG_OPTION_ON:
  79. /* Option turned on */
  80. break;
  81. }
  82. #endif
  83. /* IMPORTANT: any new internal functions used here must be declared using
  84. * PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the
  85. * 'prefix' option to configure works:
  86. *
  87. * ./configure --with-libpng-prefix=foobar_
  88. *
  89. * Verify you have got this right by running the above command, doing a build
  90. * and examining pngprefix.h; it must contain a #define for every external
  91. * function you add. (Notice that this happens automatically for the
  92. * initialization function.)
  93. */
  94. pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_vsx;
  95. if (bpp == 3)
  96. {
  97. pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_vsx;
  98. pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_vsx;
  99. pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth3_vsx;
  100. }
  101. else if (bpp == 4)
  102. {
  103. pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_vsx;
  104. pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_vsx;
  105. pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth4_vsx;
  106. }
  107. }
  108. #endif /* PNG_POWERPC_VSX_OPT > 0 */
  109. #endif /* READ */