xor.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2023 WANG Xuerui <git@xen0n.name>
  4. */
  5. #ifndef _ASM_LOONGARCH_XOR_H
  6. #define _ASM_LOONGARCH_XOR_H
  7. #include <asm/cpu-features.h>
  8. #include <asm/xor_simd.h>
  9. #ifdef CONFIG_CPU_HAS_LSX
  10. static struct xor_block_template xor_block_lsx = {
  11. .name = "lsx",
  12. .do_2 = xor_lsx_2,
  13. .do_3 = xor_lsx_3,
  14. .do_4 = xor_lsx_4,
  15. .do_5 = xor_lsx_5,
  16. };
  17. #define XOR_SPEED_LSX() \
  18. do { \
  19. if (cpu_has_lsx) \
  20. xor_speed(&xor_block_lsx); \
  21. } while (0)
  22. #else /* CONFIG_CPU_HAS_LSX */
  23. #define XOR_SPEED_LSX()
  24. #endif /* CONFIG_CPU_HAS_LSX */
  25. #ifdef CONFIG_CPU_HAS_LASX
  26. static struct xor_block_template xor_block_lasx = {
  27. .name = "lasx",
  28. .do_2 = xor_lasx_2,
  29. .do_3 = xor_lasx_3,
  30. .do_4 = xor_lasx_4,
  31. .do_5 = xor_lasx_5,
  32. };
  33. #define XOR_SPEED_LASX() \
  34. do { \
  35. if (cpu_has_lasx) \
  36. xor_speed(&xor_block_lasx); \
  37. } while (0)
  38. #else /* CONFIG_CPU_HAS_LASX */
  39. #define XOR_SPEED_LASX()
  40. #endif /* CONFIG_CPU_HAS_LASX */
  41. /*
  42. * For grins, also test the generic routines.
  43. *
  44. * More importantly: it cannot be ruled out at this point of time, that some
  45. * future (maybe reduced) models could run the vector algorithms slower than
  46. * the scalar ones, maybe for errata or micro-op reasons. It may be
  47. * appropriate to revisit this after one or two more uarch generations.
  48. */
  49. #include <asm-generic/xor.h>
  50. #undef XOR_TRY_TEMPLATES
  51. #define XOR_TRY_TEMPLATES \
  52. do { \
  53. xor_speed(&xor_block_8regs); \
  54. xor_speed(&xor_block_8regs_p); \
  55. xor_speed(&xor_block_32regs); \
  56. xor_speed(&xor_block_32regs_p); \
  57. XOR_SPEED_LSX(); \
  58. XOR_SPEED_LASX(); \
  59. } while (0)
  60. #endif /* _ASM_LOONGARCH_XOR_H */