asmmacro.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2005 - 2013 Tensilica Inc.
  4. * Copyright (C) 2014 - 2016 Cadence Design Systems Inc.
  5. */
  6. #ifndef _XTENSA_ASMMACRO_H
  7. #define _XTENSA_ASMMACRO_H
  8. #include <asm/arch/core.h>
  9. /*
  10. * Function entry and return macros for supported ABIs.
  11. */
  12. #if defined(__XTENSA_WINDOWED_ABI__)
  13. #define abi_entry entry sp, 16
  14. #define abi_ret retw
  15. #elif defined(__XTENSA_CALL0_ABI__)
  16. #define abi_entry
  17. #define abi_ret ret
  18. #else
  19. #error Unsupported Xtensa ABI
  20. #endif
  21. /*
  22. * Some little helpers for loops. Use zero-overhead-loops
  23. * where applicable and if supported by the processor.
  24. *
  25. * __loopi ar, at, size, inc
  26. * ar register initialized with the start address
  27. * at scratch register used by macro
  28. * size size immediate value
  29. * inc increment
  30. *
  31. * __loops ar, as, at, inc_log2[, mask_log2][, cond][, ncond]
  32. * ar register initialized with the start address
  33. * as register initialized with the size
  34. * at scratch register use by macro
  35. * inc_log2 increment [in log2]
  36. * mask_log2 mask [in log2]
  37. * cond true condition (used in loop'cond')
  38. * ncond false condition (used in b'ncond')
  39. *
  40. * __loop as
  41. * restart loop. 'as' register must not have been modified!
  42. *
  43. * __endla ar, as, incr
  44. * ar start address (modified)
  45. * as scratch register used by __loops/__loopi macros or
  46. * end address used by __loopt macro
  47. * inc increment
  48. */
  49. #if XCHAL_HAVE_LOOPS
  50. .macro __loopi ar, at, size, incr
  51. movi \at, ((\size + \incr - 1) / (\incr))
  52. loop \at, 99f
  53. .endm
  54. .macro __loops ar, as, at, incr_log2, mask_log2, cond, ncond
  55. .ifgt \incr_log2 - 1
  56. addi \at, \as, (1 << \incr_log2) - 1
  57. .ifnc \mask_log2,
  58. extui \at, \at, \incr_log2, \mask_log2
  59. .else
  60. srli \at, \at, \incr_log2
  61. .endif
  62. .endif
  63. loop\cond \at, 99f
  64. .endm
  65. .macro __loopt ar, as, at, incr_log2
  66. sub \at, \as, \ar
  67. .ifgt \incr_log2 - 1
  68. addi \at, \at, (1 << \incr_log2) - 1
  69. srli \at, \at, \incr_log2
  70. .endif
  71. loop \at, 99f
  72. .endm
  73. .macro __loop as
  74. loop \as, 99f
  75. .endm
  76. .macro __endl ar, as
  77. 99:
  78. .endm
  79. #else
  80. .macro __loopi ar, at, size, incr
  81. movi \at, ((\size + \incr - 1) / (\incr))
  82. addi \at, \ar, \size
  83. 98:
  84. .endm
  85. .macro __loops ar, as, at, incr_log2, mask_log2, cond, ncond
  86. .ifnc \mask_log2,
  87. extui \at, \as, \incr_log2, \mask_log2
  88. .else
  89. .ifnc \ncond,
  90. srli \at, \as, \incr_log2
  91. .endif
  92. .endif
  93. .ifnc \ncond,
  94. b\ncond \at, 99f
  95. .endif
  96. .ifnc \mask_log2,
  97. slli \at, \at, \incr_log2
  98. add \at, \ar, \at
  99. .else
  100. add \at, \ar, \as
  101. .endif
  102. 98:
  103. .endm
  104. .macro __loopt ar, as, at, incr_log2
  105. 98:
  106. .endm
  107. .macro __loop as
  108. 98:
  109. .endm
  110. .macro __endl ar, as
  111. bltu \ar, \as, 98b
  112. 99:
  113. .endm
  114. #endif
  115. .macro __endla ar, as, incr
  116. addi \ar, \ar, \incr
  117. __endl \ar \as
  118. .endm
  119. #endif /* _XTENSA_ASMMACRO_H */