arm_bitreversal_f16.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_bitreversal_f16.c
  4. * Description: Bitreversal functions
  5. *
  6. * $Date: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
  13. *
  14. * SPDX-License-Identifier: Apache-2.0
  15. *
  16. * Licensed under the Apache License, Version 2.0 (the License); you may
  17. * not use this file except in compliance with the License.
  18. * You may obtain a copy of the License at
  19. *
  20. * www.apache.org/licenses/LICENSE-2.0
  21. *
  22. * Unless required by applicable law or agreed to in writing, software
  23. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  24. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. * See the License for the specific language governing permissions and
  26. * limitations under the License.
  27. */
  28. #include "dsp/transform_functions_f16.h"
  29. /*
  30. * @brief In-place bit reversal function.
  31. * @param[in, out] *pSrc points to the in-place buffer of floating-point data type.
  32. * @param[in] fftSize length of the FFT.
  33. * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table.
  34. * @param[in] *pBitRevTab points to the bit reversal table.
  35. * @return none.
  36. */
  37. #if defined(ARM_FLOAT16_SUPPORTED)
  38. void arm_bitreversal_f16(
  39. float16_t * pSrc,
  40. uint16_t fftSize,
  41. uint16_t bitRevFactor,
  42. const uint16_t * pBitRevTab)
  43. {
  44. uint16_t fftLenBy2, fftLenBy2p1;
  45. uint16_t i, j;
  46. float16_t in;
  47. /* Initializations */
  48. j = 0U;
  49. fftLenBy2 = fftSize >> 1U;
  50. fftLenBy2p1 = (fftSize >> 1U) + 1U;
  51. /* Bit Reversal Implementation */
  52. for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U)
  53. {
  54. if (i < j)
  55. {
  56. /* pSrc[i] <-> pSrc[j]; */
  57. in = pSrc[2U * i];
  58. pSrc[2U * i] = pSrc[2U * j];
  59. pSrc[2U * j] = in;
  60. /* pSrc[i+1U] <-> pSrc[j+1U] */
  61. in = pSrc[(2U * i) + 1U];
  62. pSrc[(2U * i) + 1U] = pSrc[(2U * j) + 1U];
  63. pSrc[(2U * j) + 1U] = in;
  64. /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */
  65. in = pSrc[2U * (i + fftLenBy2p1)];
  66. pSrc[2U * (i + fftLenBy2p1)] = pSrc[2U * (j + fftLenBy2p1)];
  67. pSrc[2U * (j + fftLenBy2p1)] = in;
  68. /* pSrc[i+fftLenBy2p1+1U] <-> pSrc[j+fftLenBy2p1+1U] */
  69. in = pSrc[(2U * (i + fftLenBy2p1)) + 1U];
  70. pSrc[(2U * (i + fftLenBy2p1)) + 1U] =
  71. pSrc[(2U * (j + fftLenBy2p1)) + 1U];
  72. pSrc[(2U * (j + fftLenBy2p1)) + 1U] = in;
  73. }
  74. /* pSrc[i+1U] <-> pSrc[j+1U] */
  75. in = pSrc[2U * (i + 1U)];
  76. pSrc[2U * (i + 1U)] = pSrc[2U * (j + fftLenBy2)];
  77. pSrc[2U * (j + fftLenBy2)] = in;
  78. /* pSrc[i+2U] <-> pSrc[j+2U] */
  79. in = pSrc[(2U * (i + 1U)) + 1U];
  80. pSrc[(2U * (i + 1U)) + 1U] = pSrc[(2U * (j + fftLenBy2)) + 1U];
  81. pSrc[(2U * (j + fftLenBy2)) + 1U] = in;
  82. /* Reading the index for the bit reversal */
  83. j = *pBitRevTab;
  84. /* Updating the bit reversal index depending on the fft length */
  85. pBitRevTab += bitRevFactor;
  86. }
  87. }
  88. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */