asm.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Some useful macros for LoongArch assembler code
  4. *
  5. * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
  6. *
  7. * Derived from MIPS:
  8. * Copyright (C) 1995, 1996, 1997, 1999, 2001 by Ralf Baechle
  9. * Copyright (C) 1999 by Silicon Graphics, Inc.
  10. * Copyright (C) 2001 MIPS Technologies, Inc.
  11. * Copyright (C) 2002 Maciej W. Rozycki
  12. */
  13. #ifndef __ASM_ASM_H
  14. #define __ASM_ASM_H
  15. /* LoongArch pref instruction. */
  16. #ifdef CONFIG_CPU_HAS_PREFETCH
  17. #define PREF(hint, addr, offs) \
  18. preld hint, addr, offs; \
  19. #define PREFX(hint, addr, index) \
  20. preldx hint, addr, index; \
  21. #else /* !CONFIG_CPU_HAS_PREFETCH */
  22. #define PREF(hint, addr, offs)
  23. #define PREFX(hint, addr, index)
  24. #endif /* !CONFIG_CPU_HAS_PREFETCH */
  25. /*
  26. * Stack alignment
  27. */
  28. #define STACK_ALIGN ~(0xf)
  29. /*
  30. * Macros to handle different pointer/register sizes for 32/64-bit code
  31. */
  32. /*
  33. * Size of a register
  34. */
  35. #ifndef __loongarch64
  36. #define SZREG 4
  37. #else
  38. #define SZREG 8
  39. #endif
  40. /*
  41. * Use the following macros in assemblercode to load/store registers,
  42. * pointers etc.
  43. */
  44. #if (SZREG == 4)
  45. #define REG_L ld.w
  46. #define REG_S st.w
  47. #define REG_ADD add.w
  48. #define REG_SUB sub.w
  49. #else /* SZREG == 8 */
  50. #define REG_L ld.d
  51. #define REG_S st.d
  52. #define REG_ADD add.d
  53. #define REG_SUB sub.d
  54. #endif
  55. /*
  56. * How to add/sub/load/store/shift C int variables.
  57. */
  58. #if (__SIZEOF_INT__ == 4)
  59. #define INT_ADD add.w
  60. #define INT_ADDI addi.w
  61. #define INT_SUB sub.w
  62. #define INT_L ld.w
  63. #define INT_S st.w
  64. #define INT_SLL slli.w
  65. #define INT_SLLV sll.w
  66. #define INT_SRL srli.w
  67. #define INT_SRLV srl.w
  68. #define INT_SRA srai.w
  69. #define INT_SRAV sra.w
  70. #endif
  71. #if (__SIZEOF_INT__ == 8)
  72. #define INT_ADD add.d
  73. #define INT_ADDI addi.d
  74. #define INT_SUB sub.d
  75. #define INT_L ld.d
  76. #define INT_S st.d
  77. #define INT_SLL slli.d
  78. #define INT_SLLV sll.d
  79. #define INT_SRL srli.d
  80. #define INT_SRLV srl.d
  81. #define INT_SRA srai.d
  82. #define INT_SRAV sra.d
  83. #endif
  84. /*
  85. * How to add/sub/load/store/shift C long variables.
  86. */
  87. #if (__SIZEOF_LONG__ == 4)
  88. #define LONG_ADD add.w
  89. #define LONG_ADDI addi.w
  90. #define LONG_SUB sub.w
  91. #define LONG_L ld.w
  92. #define LONG_S st.w
  93. #define LONG_SLL slli.w
  94. #define LONG_SLLV sll.w
  95. #define LONG_SRL srli.w
  96. #define LONG_SRLV srl.w
  97. #define LONG_SRA srai.w
  98. #define LONG_SRAV sra.w
  99. #ifdef __ASSEMBLY__
  100. #define LONG .word
  101. #endif
  102. #define LONGSIZE 4
  103. #define LONGMASK 3
  104. #define LONGLOG 2
  105. #endif
  106. #if (__SIZEOF_LONG__ == 8)
  107. #define LONG_ADD add.d
  108. #define LONG_ADDI addi.d
  109. #define LONG_SUB sub.d
  110. #define LONG_L ld.d
  111. #define LONG_S st.d
  112. #define LONG_SLL slli.d
  113. #define LONG_SLLV sll.d
  114. #define LONG_SRL srli.d
  115. #define LONG_SRLV srl.d
  116. #define LONG_SRA srai.d
  117. #define LONG_SRAV sra.d
  118. #ifdef __ASSEMBLY__
  119. #define LONG .dword
  120. #endif
  121. #define LONGSIZE 8
  122. #define LONGMASK 7
  123. #define LONGLOG 3
  124. #endif
  125. /*
  126. * How to add/sub/load/store/shift pointers.
  127. */
  128. #if (__SIZEOF_POINTER__ == 4)
  129. #define PTR_ADD add.w
  130. #define PTR_ADDI addi.w
  131. #define PTR_SUB sub.w
  132. #define PTR_L ld.w
  133. #define PTR_S st.w
  134. #define PTR_LI li.w
  135. #define PTR_SLL slli.w
  136. #define PTR_SLLV sll.w
  137. #define PTR_SRL srli.w
  138. #define PTR_SRLV srl.w
  139. #define PTR_SRA srai.w
  140. #define PTR_SRAV sra.w
  141. #define PTR_SCALESHIFT 2
  142. #ifdef __ASSEMBLY__
  143. #define PTR .word
  144. #endif
  145. #define PTRSIZE 4
  146. #define PTRLOG 2
  147. #endif
  148. #if (__SIZEOF_POINTER__ == 8)
  149. #define PTR_ADD add.d
  150. #define PTR_ADDI addi.d
  151. #define PTR_SUB sub.d
  152. #define PTR_L ld.d
  153. #define PTR_S st.d
  154. #define PTR_LI li.d
  155. #define PTR_SLL slli.d
  156. #define PTR_SLLV sll.d
  157. #define PTR_SRL srli.d
  158. #define PTR_SRLV srl.d
  159. #define PTR_SRA srai.d
  160. #define PTR_SRAV sra.d
  161. #define PTR_SCALESHIFT 3
  162. #ifdef __ASSEMBLY__
  163. #define PTR .dword
  164. #endif
  165. #define PTRSIZE 8
  166. #define PTRLOG 3
  167. #endif
  168. #endif /* __ASM_ASM_H */