arm_vec_fft.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /******************************************************************************
  2. * @file arm_vec_fft.h
  3. * @brief Private header file for CMSIS DSP Library
  4. * @version V1.7.0
  5. * @date 07. January 2020
  6. ******************************************************************************/
  7. /*
  8. * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved.
  9. *
  10. * SPDX-License-Identifier: Apache-2.0
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the License); you may
  13. * not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  20. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. #ifndef _ARM_VEC_FFT_H_
  25. #define _ARM_VEC_FFT_H_
  26. #include "arm_math.h"
  27. #include "arm_helium_utils.h"
  28. #ifdef __cplusplus
  29. extern "C"
  30. {
  31. #endif
  32. #if (defined(ARM_MATH_MVEF) || defined(ARM_MATH_MVEI) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE)
  33. #define MVE_CMPLX_ADD_A_ixB(A, B) vcaddq_rot90(A,B)
  34. #define MVE_CMPLX_SUB_A_ixB(A,B) vcaddq_rot270(A,B)
  35. #define MVE_CMPLX_MULT_FLT_AxB(A,B) vcmlaq_rot90(vcmulq(A, B), A, B)
  36. #define MVE_CMPLX_MULT_FLT_Conj_AxB(A,B) vcmlaq_rot270(vcmulq(A, B), A, B)
  37. #define MVE_CMPLX_MULT_FX_AxB(A,B,TyA) vqdmladhxq(vqdmlsdhq((TyA)vuninitializedq_s32(), A, B), A, B)
  38. #define MVE_CMPLX_MULT_FX_AxConjB(A,B,TyA) vqdmladhq(vqdmlsdhxq((TyA)vuninitializedq_s32(), A, B), A, B)
  39. #define MVE_CMPLX_ADD_FX_A_ixB(A, B) vhcaddq_rot90(A,B)
  40. #define MVE_CMPLX_SUB_FX_A_ixB(A,B) vhcaddq_rot270(A,B)
  41. /**
  42. @brief In-place 32 bit reversal function for helium
  43. @param[in,out] pSrc points to in-place buffer of unknown 32-bit data type
  44. @param[in] bitRevLen bit reversal table length
  45. @param[in] pBitRevTab points to bit reversal table
  46. @return none
  47. */
  48. __STATIC_INLINE void arm_bitreversal_32_inpl_mve(
  49. uint32_t *pSrc,
  50. const uint16_t bitRevLen,
  51. const uint16_t *pBitRevTab)
  52. {
  53. uint64_t *src = (uint64_t *) pSrc;
  54. int32_t blkCnt; /* loop counters */
  55. uint32x4_t bitRevTabOff;
  56. uint32x4_t one = vdupq_n_u32(1);
  57. uint64x2_t inLow, inHigh;
  58. uint64x2_t bitRevOff1Low, bitRevOff0Low;
  59. uint64x2_t bitRevOff1High, bitRevOff0High;
  60. /* load scheduling to increase gather load idx update / gather load distance */
  61. bitRevTabOff = vldrhq_u32(pBitRevTab);
  62. pBitRevTab += 4;
  63. bitRevOff0Low = vmullbq_int_u32(bitRevTabOff, one);
  64. bitRevOff0High = vmulltq_int_u32(bitRevTabOff, one);
  65. blkCnt = bitRevLen / 8;
  66. while (blkCnt > 0) {
  67. bitRevTabOff = vldrhq_u32(pBitRevTab);
  68. pBitRevTab += 4;
  69. /* 64-bit index expansion */
  70. bitRevOff1Low = vmullbq_int_u32(bitRevTabOff, one);
  71. bitRevOff1High = vmulltq_int_u32(bitRevTabOff, one);
  72. inLow = vldrdq_gather_offset_u64(src, bitRevOff0Low);
  73. inHigh = vldrdq_gather_offset_u64(src, bitRevOff0High);
  74. vstrdq_scatter_offset_u64(src, bitRevOff0Low, inHigh);
  75. vstrdq_scatter_offset_u64(src, bitRevOff0High, inLow);
  76. /* unrolled */
  77. bitRevTabOff = vldrhq_u32(pBitRevTab);
  78. pBitRevTab += 4;
  79. bitRevOff0Low = vmullbq_int_u32(bitRevTabOff, one);
  80. bitRevOff0High = vmulltq_int_u32(bitRevTabOff, one);
  81. inLow = vldrdq_gather_offset_u64(src, bitRevOff1Low);
  82. inHigh = vldrdq_gather_offset_u64(src, bitRevOff1High);
  83. vstrdq_scatter_offset_u64(src, bitRevOff1Low, inHigh);
  84. vstrdq_scatter_offset_u64(src, bitRevOff1High, inLow);
  85. /*
  86. * Decrement the blockSize loop counter
  87. */
  88. blkCnt--;
  89. }
  90. if (bitRevLen & 7) {
  91. /* FFT size = 16 */
  92. inLow = vldrdq_gather_offset_u64(src, bitRevOff0Low);
  93. inHigh = vldrdq_gather_offset_u64(src, bitRevOff0High);
  94. vstrdq_scatter_offset_u64(src, bitRevOff0Low, inHigh);
  95. vstrdq_scatter_offset_u64(src, bitRevOff0High, inLow);
  96. }
  97. }
  98. /**
  99. @brief In-place 16 bit reversal function for helium
  100. @param[in,out] pSrc points to in-place buffer of unknown 16-bit data type
  101. @param[in] bitRevLen bit reversal table length
  102. @param[in] pBitRevTab points to bit reversal table
  103. @return none
  104. */
  105. __STATIC_INLINE void arm_bitreversal_16_inpl_mve(
  106. uint16_t *pSrc,
  107. const uint16_t bitRevLen,
  108. const uint16_t *pBitRevTab)
  109. {
  110. uint32_t *src = (uint32_t *) pSrc;
  111. int32_t blkCnt; /* loop counters */
  112. uint32x4_t bitRevTabOff;
  113. uint16x8_t one = vdupq_n_u16(1);
  114. uint32x4_t bitRevOff1Low, bitRevOff0Low;
  115. uint32x4_t bitRevOff1High, bitRevOff0High;
  116. uint32x4_t inLow, inHigh;
  117. /* load scheduling to increase gather load idx update / gather load distance */
  118. bitRevTabOff = vldrhq_u16(pBitRevTab);
  119. pBitRevTab += 8;
  120. bitRevOff0Low = vmullbq_int_u16((uint16x8_t)bitRevTabOff, one);
  121. bitRevOff0High = vmulltq_int_u16((uint16x8_t)bitRevTabOff, one);
  122. bitRevOff0Low = vshrq_n_u16((uint16x8_t)bitRevOff0Low, 3);
  123. bitRevOff0High = vshrq_n_u16((uint16x8_t)bitRevOff0High, 3);
  124. blkCnt = (bitRevLen / 16);
  125. while (blkCnt > 0) {
  126. bitRevTabOff = vldrhq_u16(pBitRevTab);
  127. pBitRevTab += 8;
  128. bitRevOff1Low = vmullbq_int_u16((uint16x8_t)bitRevTabOff, one);
  129. bitRevOff1High = vmulltq_int_u16((uint16x8_t)bitRevTabOff, one);
  130. bitRevOff1Low = vshrq_n_u16((uint16x8_t)bitRevOff1Low, 3);
  131. bitRevOff1High = vshrq_n_u16((uint16x8_t)bitRevOff1High, 3);
  132. inLow = vldrwq_gather_shifted_offset_u32(src, bitRevOff0Low);
  133. inHigh = vldrwq_gather_shifted_offset_u32(src, bitRevOff0High);
  134. vstrwq_scatter_shifted_offset_u32(src, bitRevOff0Low, inHigh);
  135. vstrwq_scatter_shifted_offset_u32(src, bitRevOff0High, inLow);
  136. /* loop unrolling */
  137. bitRevTabOff = vldrhq_u16(pBitRevTab);
  138. pBitRevTab += 8;
  139. bitRevOff0Low = vmullbq_int_u16((uint16x8_t)bitRevTabOff, one);
  140. bitRevOff0High = vmulltq_int_u16((uint16x8_t)bitRevTabOff, one);
  141. bitRevOff0Low = vshrq_n_u16((uint16x8_t)bitRevOff0Low, 3);
  142. bitRevOff0High = vshrq_n_u16((uint16x8_t)bitRevOff0High, 3);
  143. inLow = vldrwq_gather_shifted_offset_u32(src, bitRevOff1Low);
  144. inHigh = vldrwq_gather_shifted_offset_u32(src, bitRevOff1High);
  145. vstrwq_scatter_shifted_offset_u32(src, bitRevOff1Low, inHigh);
  146. vstrwq_scatter_shifted_offset_u32(src, bitRevOff1High, inLow);
  147. blkCnt--;
  148. }
  149. /* tail handling */
  150. blkCnt = bitRevLen & 0xf;
  151. if (blkCnt == 8) {
  152. inLow = vldrwq_gather_shifted_offset_u32(src, bitRevOff0Low);
  153. inHigh = vldrwq_gather_shifted_offset_u32(src, bitRevOff0High);
  154. vstrwq_scatter_shifted_offset_u32(src, bitRevOff0Low, inHigh);
  155. vstrwq_scatter_shifted_offset_u32(src, bitRevOff0High, inLow);
  156. } else if (blkCnt == 12) {
  157. /* FFT 16 special case */
  158. mve_pred16_t p = vctp16q(4);
  159. bitRevTabOff = vldrhq_z_u16(pBitRevTab, p);
  160. inLow = vldrwq_gather_shifted_offset_u32(src, bitRevOff0Low);
  161. inHigh = vldrwq_gather_shifted_offset_u32(src, bitRevOff0High);
  162. vstrwq_scatter_shifted_offset_u32(src, bitRevOff0Low, inHigh);
  163. vstrwq_scatter_shifted_offset_u32(src, bitRevOff0High, inLow);
  164. bitRevOff0Low = vmullbq_int_u16((uint16x8_t)bitRevTabOff, one);
  165. bitRevOff0High = vmulltq_int_u16((uint16x8_t)bitRevTabOff, one);
  166. bitRevOff0Low = vshrq_n_u16((uint16x8_t)bitRevOff0Low, 3);
  167. bitRevOff0High = vshrq_n_u16((uint16x8_t)bitRevOff0High, 3);
  168. inLow = vldrwq_gather_shifted_offset_z_u32(src, bitRevOff0Low, p);
  169. inHigh = vldrwq_gather_shifted_offset_z_u32(src, bitRevOff0High, p);
  170. vstrwq_scatter_shifted_offset_p_u32(src, bitRevOff0Low, inHigh, p);
  171. vstrwq_scatter_shifted_offset_p_u32(src, bitRevOff0High, inLow, p);
  172. }
  173. }
  174. /**
  175. @brief Out-of-place 32 bit reversal function for helium
  176. @param[out] pDst points to destination buffer of unknown 32-bit data type
  177. @param[in] pSrc points to input buffer of unknown 32-bit data type
  178. @param[in] fftLen FFT length
  179. @return none
  180. */
  181. __STATIC_INLINE void arm_bitreversal_32_outpl_mve(void *pDst, void *pSrc, uint32_t fftLen)
  182. {
  183. uint32x4_t idxOffs0, idxOffs1, bitRevOffs0, bitRevOffs1;
  184. uint32_t bitRevPos, blkCnt;
  185. uint32_t *pDst32 = (uint32_t *) pDst;
  186. /* fwd indexes */
  187. idxOffs0 = vdupq_n_u32(0);
  188. idxOffs1 = vdupq_n_u32(0);
  189. idxOffs0[0] = 0; idxOffs0[2] = 4;
  190. idxOffs1[0] = 8; idxOffs1[2] = 12;
  191. bitRevPos = (31 - __CLZ(fftLen)) + 5;
  192. blkCnt = fftLen >> 2;
  193. /* issued earlier to increase gather load idx update / gather load distance */
  194. /* bit-reverse fwd indexes */
  195. bitRevOffs0 = vbrsrq(idxOffs0, bitRevPos);
  196. bitRevOffs1 = vbrsrq(idxOffs1, bitRevPos);
  197. while (blkCnt > 0) {
  198. uint64x2_t vecIn;
  199. vecIn = vldrdq_gather_offset_u64(pSrc, (uint64x2_t) bitRevOffs0);
  200. idxOffs0 = idxOffs0 + 16;
  201. vst1q(pDst32, (uint32x4_t) vecIn);
  202. pDst32 += 4;
  203. bitRevOffs0 = vbrsrq(idxOffs0, bitRevPos);
  204. vecIn = vldrdq_gather_offset_u64(pSrc, (uint64x2_t) bitRevOffs1);
  205. idxOffs1 = idxOffs1 + 16;
  206. vst1q(pDst32, (uint32x4_t) vecIn);
  207. pDst32 += 4;
  208. bitRevOffs1 = vbrsrq(idxOffs1, bitRevPos);
  209. blkCnt--;
  210. }
  211. }
  212. /**
  213. @brief Out-of-place 16 bit reversal function for helium
  214. @param[out] pDst points to destination buffer of unknown 16-bit data type
  215. @param[in] pSrc points to input buffer of unknown 16-bit data type
  216. @param[in] fftLen FFT length
  217. @return none
  218. */
  219. __STATIC_INLINE void arm_bitreversal_16_outpl_mve(void *pDst, void *pSrc, uint32_t fftLen)
  220. {
  221. uint32x4_t idxOffs0, idxOffs1, bitRevOffs0, bitRevOffs1;
  222. uint32_t bitRevPos, blkCnt;
  223. uint16_t *pDst16 = (uint16_t *) pDst;
  224. uint32_t incrIdx = 0;
  225. /* fwd indexes */
  226. idxOffs0 = vidupq_wb_u32(&incrIdx, 4); // {0, 4, 8, 12}
  227. idxOffs1 = vidupq_wb_u32(&incrIdx, 4); // {16, 20, 24, 28}
  228. bitRevPos = (31 - __CLZ(fftLen)) + 4;
  229. blkCnt = fftLen >> 3;
  230. /* issued earlier to increase gather load idx update / gather load distance */
  231. /* bit-reverse fwd indexes */
  232. bitRevOffs0 = vbrsrq(idxOffs0, bitRevPos);
  233. bitRevOffs1 = vbrsrq(idxOffs1, bitRevPos);
  234. while (blkCnt > 0) {
  235. uint32x4_t vecIn;
  236. vecIn = vldrwq_gather_offset_s32(pSrc, bitRevOffs0);
  237. idxOffs0 = idxOffs0 + 32;
  238. vst1q(pDst16, (uint16x8_t) vecIn);
  239. pDst16 += 8;
  240. bitRevOffs0 = vbrsrq(idxOffs0, bitRevPos);
  241. vecIn = vldrwq_gather_offset_s32(pSrc, bitRevOffs1);
  242. idxOffs1 = idxOffs1 + 32;
  243. vst1q(pDst16, (uint16x8_t) vecIn);
  244. pDst16 += 8;
  245. bitRevOffs1 = vbrsrq(idxOffs1, bitRevPos);
  246. blkCnt--;
  247. }
  248. }
  249. #endif /* (defined(ARM_MATH_MVEF) || defined(ARM_MATH_HELIUM)) && !defined(ARM_MATH_AUTOVECTORIZE)*/
  250. #ifdef __cplusplus
  251. }
  252. #endif
  253. #endif /* _ARM_VEC_FFT_H_ */