loongarch_lsx_init.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* loongarch_lsx_init.c - LSX optimized filter functions
  2. *
  3. * Copyright (c) 2021 Loongson Technology Corporation Limited
  4. * All rights reserved.
  5. * Contributed by Jin Bo <jinbo@loongson.cn>
  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. #include "../pngpriv.h"
  12. #ifdef PNG_READ_SUPPORTED
  13. #if PNG_LOONGARCH_LSX_IMPLEMENTATION == 1
  14. #include <sys/auxv.h>
  15. #define LA_HWCAP_LSX (1<<4)
  16. static int png_has_lsx(void)
  17. {
  18. int flags = 0;
  19. int flag = (int)getauxval(AT_HWCAP);
  20. if (flag & LA_HWCAP_LSX)
  21. return 1;
  22. return 0;
  23. }
  24. void
  25. png_init_filter_functions_lsx(png_structp pp, unsigned int bpp)
  26. {
  27. /* IMPORTANT: any new external functions used here must be declared using
  28. * PNG_INTERNAL_FUNCTION in ../pngpriv.h. This is required so that the
  29. * 'prefix' option to configure works:
  30. *
  31. * ./configure --with-libpng-prefix=foobar_
  32. *
  33. * Verify you have got this right by running the above command, doing a build
  34. * and examining pngprefix.h; it must contain a #define for every external
  35. * function you add. (Notice that this happens automatically for the
  36. * initialization function.)
  37. */
  38. if (png_has_lsx())
  39. {
  40. pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_lsx;
  41. if (bpp == 3)
  42. {
  43. pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_lsx;
  44. pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_lsx;
  45. pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth3_lsx;
  46. }
  47. else if (bpp == 4)
  48. {
  49. pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_lsx;
  50. pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_lsx;
  51. pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth4_lsx;
  52. }
  53. }
  54. }
  55. #endif /* PNG_LOONGARCH_LSX_IMPLEMENTATION == 1 */
  56. #endif /* PNG_READ_SUPPORTED */