srai.S 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. ; Copyright (C) 2012-2022 Free Software Foundation, Inc.
  2. ; Contributed by Red Hat.
  3. ;
  4. ; This file is free software; you can redistribute it and/or modify it
  5. ; under the terms of the GNU General Public License as published by the
  6. ; Free Software Foundation; either version 3, or (at your option) any
  7. ; later version.
  8. ;
  9. ; This file is distributed in the hope that it will be useful, but
  10. ; WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ; General Public License for more details.
  13. ;
  14. ; Under Section 7 of GPL version 3, you are granted additional
  15. ; permissions described in the GCC Runtime Library Exception, version
  16. ; 3.1, as published by the Free Software Foundation.
  17. ;
  18. ; You should have received a copy of the GNU General Public License and
  19. ; a copy of the GCC Runtime Library Exception along with this program;
  20. ; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  21. ; <http://www.gnu.org/licenses/>.
  22. .text
  23. .section .text.__mspabi_srai_n
  24. .macro _srai n
  25. .global __mspabi_srai_\n
  26. __mspabi_srai_\n:
  27. RRA.W R12
  28. .endm
  29. /* Arithmetic Right Shift - R12 -> R12. */
  30. _srai 15
  31. _srai 14
  32. _srai 13
  33. _srai 12
  34. _srai 11
  35. _srai 10
  36. _srai 9
  37. _srai 8
  38. _srai 7
  39. _srai 6
  40. _srai 5
  41. _srai 4
  42. _srai 3
  43. _srai 2
  44. _srai 1
  45. #ifdef __MSP430X_LARGE__
  46. RETA
  47. #else
  48. RET
  49. #endif
  50. .section .text.__mspabi_srai
  51. 1: ADD.W #-1,R13
  52. RRA.W R12,R12
  53. .global __mspabi_srai
  54. __mspabi_srai:
  55. CMP #0,R13
  56. JNZ 1b
  57. #ifdef __MSP430X_LARGE__
  58. RETA
  59. #else
  60. RET
  61. #endif
  62. #ifdef __MSP430X__
  63. .section .text.__gnu_mspabi_srap
  64. 1: ADDA #-1,R13
  65. RRAX.A R12,R12
  66. .global __gnu_mspabi_srap
  67. __gnu_mspabi_srap:
  68. CMP #0,R13
  69. JNZ 1b
  70. #ifdef __MSP430X_LARGE__
  71. RETA
  72. #else
  73. RET
  74. #endif /* __MSP430X_LARGE__ */
  75. #endif /* __MSP430X__ */
  76. /* Arithmetic Right Shift - R12:R13 -> R12:R13. */
  77. .section .text.__mspabi_sral_n
  78. .macro _sral n
  79. .global __mspabi_sral_\n
  80. __mspabi_sral_\n:
  81. RRA.W R13
  82. RRC.W R12
  83. .endm
  84. _sral 15
  85. _sral 14
  86. _sral 13
  87. _sral 12
  88. _sral 11
  89. _sral 10
  90. _sral 9
  91. _sral 8
  92. _sral 7
  93. _sral 6
  94. _sral 5
  95. _sral 4
  96. _sral 3
  97. _sral 2
  98. _sral 1
  99. #ifdef __MSP430X_LARGE__
  100. RETA
  101. #else
  102. RET
  103. #endif
  104. .section .text.__mspabi_sral
  105. 1: ADD.W #-1,R14
  106. RRA.W R13
  107. RRC.W R12
  108. .global __mspabi_sral
  109. __mspabi_sral:
  110. CMP #0,R14
  111. JNZ 1b
  112. #ifdef __MSP430X_LARGE__
  113. RETA
  114. #else
  115. RET
  116. #endif
  117. /* Arithmetic Right Shift - R8:R11 -> R12:R15
  118. A 64-bit argument would normally be passed in R12:R15, but __mspabi_srall has
  119. special conventions, so the 64-bit value to shift is passed in R8:R11.
  120. According to the MSPABI, the shift amount is a 64-bit value in R12:R15, but
  121. we only use the low word in R12. */
  122. .section .text.__mspabi_srall
  123. .global __mspabi_srall
  124. __mspabi_srall:
  125. MOV R11, R15 ; Free up R11 first
  126. MOV R12, R11 ; Save the shift amount in R11
  127. MOV R10, R14
  128. MOV R9, R13
  129. MOV R8, R12
  130. CMP #0, R11
  131. JNZ 1f
  132. #ifdef __MSP430X_LARGE__
  133. RETA
  134. #else
  135. RET
  136. #endif
  137. 1:
  138. RRA R15
  139. RRC R14
  140. RRC R13
  141. RRC R12
  142. ADD #-1,R11
  143. JNZ 1b
  144. #ifdef __MSP430X_LARGE__
  145. RETA
  146. #else
  147. RET
  148. #endif