arm_bitreversal2.S 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. ;/* ----------------------------------------------------------------------
  2. ;* Copyright (C) 2010-2014 ARM Limited. All rights reserved.
  3. ;*
  4. ;* $Date: 12. March 2014
  5. ;* $Revision: V1.4.4
  6. ;*
  7. ;* Project: CMSIS DSP Library
  8. ;* Title: arm_bitreversal2.S
  9. ;*
  10. ;* Description: This is the arm_bitreversal_32 function done in
  11. ;* assembly for maximum speed. This function is called
  12. ;* after doing an fft to reorder the output. The function
  13. ;* is loop unrolled by 2. arm_bitreversal_16 as well.
  14. ;*
  15. ;* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
  16. ;*
  17. ;* Redistribution and use in source and binary forms, with or without
  18. ;* modification, are permitted provided that the following conditions
  19. ;* are met:
  20. ;* - Redistributions of source code must retain the above copyright
  21. ;* notice, this list of conditions and the following disclaimer.
  22. ;* - Redistributions in binary form must reproduce the above copyright
  23. ;* notice, this list of conditions and the following disclaimer in
  24. ;* the documentation and/or other materials provided with the
  25. ;* distribution.
  26. ;* - Neither the name of ARM LIMITED nor the names of its contributors
  27. ;* may be used to endorse or promote products derived from this
  28. ;* software without specific prior written permission.
  29. ;*
  30. ;* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. ;* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. ;* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  33. ;* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  34. ;* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  35. ;* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  36. ;* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. ;* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. ;* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  39. ;* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  40. ;* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. ;* POSSIBILITY OF SUCH DAMAGE.
  42. ;* -------------------------------------------------------------------- */
  43. #if defined(__CC_ARM) // Keil
  44. #define CODESECT AREA ||.text||, CODE, READONLY, ALIGN=2
  45. #define LABEL
  46. #elif defined(__IASMARM__) // IAR
  47. #define CODESECT SECTION `.text`:CODE
  48. #define PROC
  49. #define LABEL
  50. #define ENDP
  51. #define EXPORT PUBLIC
  52. #elif defined(__CSMC__) /* Cosmic */
  53. #define CODESECT switch .text
  54. #define THUMB
  55. #define EXPORT xdef
  56. #define PROC :
  57. #define LABEL :
  58. #define ENDP
  59. #define arm_bitreversal_32 _arm_bitreversal_32
  60. #elif defined (__GNUC__) // GCC
  61. #define THUMB .thumb
  62. #define CODESECT .section .text
  63. #define EXPORT .global
  64. #define PROC :
  65. #define LABEL :
  66. #define ENDP
  67. #define END
  68. .syntax unified
  69. #endif
  70. CODESECT
  71. THUMB
  72. ;/*
  73. ;* @brief In-place bit reversal function.
  74. ;* @param[in, out] *pSrc points to the in-place buffer of unknown 32-bit data type.
  75. ;* @param[in] bitRevLen bit reversal table length
  76. ;* @param[in] *pBitRevTab points to bit reversal table.
  77. ;* @return none.
  78. ;*/
  79. EXPORT arm_bitreversal_32
  80. EXPORT arm_bitreversal_16
  81. #if defined(ARM_MATH_CM0) || defined(ARM_MATH_CM0PLUS)
  82. arm_bitreversal_32 PROC
  83. ADDS r3,r1,#1
  84. PUSH {r4-r6}
  85. ADDS r1,r2,#0
  86. LSRS r3,r3,#1
  87. arm_bitreversal_32_0 LABEL
  88. LDRH r2,[r1,#2]
  89. LDRH r6,[r1,#0]
  90. ADD r2,r0,r2
  91. ADD r6,r0,r6
  92. LDR r5,[r2,#0]
  93. LDR r4,[r6,#0]
  94. STR r5,[r6,#0]
  95. STR r4,[r2,#0]
  96. LDR r5,[r2,#4]
  97. LDR r4,[r6,#4]
  98. STR r5,[r6,#4]
  99. STR r4,[r2,#4]
  100. ADDS r1,r1,#4
  101. SUBS r3,r3,#1
  102. BNE arm_bitreversal_32_0
  103. POP {r4-r6}
  104. BX lr
  105. ENDP
  106. arm_bitreversal_16 PROC
  107. ADDS r3,r1,#1
  108. PUSH {r4-r6}
  109. ADDS r1,r2,#0
  110. LSRS r3,r3,#1
  111. arm_bitreversal_16_0 LABEL
  112. LDRH r2,[r1,#2]
  113. LDRH r6,[r1,#0]
  114. LSRS r2,r2,#1
  115. LSRS r6,r6,#1
  116. ADD r2,r0,r2
  117. ADD r6,r0,r6
  118. LDR r5,[r2,#0]
  119. LDR r4,[r6,#0]
  120. STR r5,[r6,#0]
  121. STR r4,[r2,#0]
  122. ADDS r1,r1,#4
  123. SUBS r3,r3,#1
  124. BNE arm_bitreversal_16_0
  125. POP {r4-r6}
  126. BX lr
  127. ENDP
  128. #else
  129. arm_bitreversal_32 PROC
  130. ADDS r3,r1,#1
  131. CMP r3,#1
  132. IT LS
  133. BXLS lr
  134. PUSH {r4-r9}
  135. ADDS r1,r2,#2
  136. LSRS r3,r3,#2
  137. arm_bitreversal_32_0 LABEL ;/* loop unrolled by 2 */
  138. LDRH r8,[r1,#4]
  139. LDRH r9,[r1,#2]
  140. LDRH r2,[r1,#0]
  141. LDRH r12,[r1,#-2]
  142. ADD r8,r0,r8
  143. ADD r9,r0,r9
  144. ADD r2,r0,r2
  145. ADD r12,r0,r12
  146. LDR r7,[r9,#0]
  147. LDR r6,[r8,#0]
  148. LDR r5,[r2,#0]
  149. LDR r4,[r12,#0]
  150. STR r6,[r9,#0]
  151. STR r7,[r8,#0]
  152. STR r5,[r12,#0]
  153. STR r4,[r2,#0]
  154. LDR r7,[r9,#4]
  155. LDR r6,[r8,#4]
  156. LDR r5,[r2,#4]
  157. LDR r4,[r12,#4]
  158. STR r6,[r9,#4]
  159. STR r7,[r8,#4]
  160. STR r5,[r12,#4]
  161. STR r4,[r2,#4]
  162. ADDS r1,r1,#8
  163. SUBS r3,r3,#1
  164. BNE arm_bitreversal_32_0
  165. POP {r4-r9}
  166. BX lr
  167. ENDP
  168. arm_bitreversal_16 PROC
  169. ADDS r3,r1,#1
  170. CMP r3,#1
  171. IT LS
  172. BXLS lr
  173. PUSH {r4-r9}
  174. ADDS r1,r2,#2
  175. LSRS r3,r3,#2
  176. arm_bitreversal_16_0 LABEL ;/* loop unrolled by 2 */
  177. LDRH r8,[r1,#4]
  178. LDRH r9,[r1,#2]
  179. LDRH r2,[r1,#0]
  180. LDRH r12,[r1,#-2]
  181. ADD r8,r0,r8,LSR #1
  182. ADD r9,r0,r9,LSR #1
  183. ADD r2,r0,r2,LSR #1
  184. ADD r12,r0,r12,LSR #1
  185. LDR r7,[r9,#0]
  186. LDR r6,[r8,#0]
  187. LDR r5,[r2,#0]
  188. LDR r4,[r12,#0]
  189. STR r6,[r9,#0]
  190. STR r7,[r8,#0]
  191. STR r5,[r12,#0]
  192. STR r4,[r2,#0]
  193. ADDS r1,r1,#8
  194. SUBS r3,r3,#1
  195. BNE arm_bitreversal_16_0
  196. POP {r4-r9}
  197. BX lr
  198. ENDP
  199. #endif
  200. END