arm_bitreversal_f16.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. */
  36. #if defined(ARM_FLOAT16_SUPPORTED)
  37. void arm_bitreversal_f16(
  38. float16_t * pSrc,
  39. uint16_t fftSize,
  40. uint16_t bitRevFactor,
  41. const uint16_t * pBitRevTab)
  42. {
  43. uint16_t fftLenBy2, fftLenBy2p1;
  44. uint16_t i, j;
  45. float16_t in;
  46. /* Initializations */
  47. j = 0U;
  48. fftLenBy2 = fftSize >> 1U;
  49. fftLenBy2p1 = (fftSize >> 1U) + 1U;
  50. /* Bit Reversal Implementation */
  51. for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U)
  52. {
  53. if (i < j)
  54. {
  55. /* pSrc[i] <-> pSrc[j]; */
  56. in = pSrc[2U * i];
  57. pSrc[2U * i] = pSrc[2U * j];
  58. pSrc[2U * j] = in;
  59. /* pSrc[i+1U] <-> pSrc[j+1U] */
  60. in = pSrc[(2U * i) + 1U];
  61. pSrc[(2U * i) + 1U] = pSrc[(2U * j) + 1U];
  62. pSrc[(2U * j) + 1U] = in;
  63. /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */
  64. in = pSrc[2U * (i + fftLenBy2p1)];
  65. pSrc[2U * (i + fftLenBy2p1)] = pSrc[2U * (j + fftLenBy2p1)];
  66. pSrc[2U * (j + fftLenBy2p1)] = in;
  67. /* pSrc[i+fftLenBy2p1+1U] <-> pSrc[j+fftLenBy2p1+1U] */
  68. in = pSrc[(2U * (i + fftLenBy2p1)) + 1U];
  69. pSrc[(2U * (i + fftLenBy2p1)) + 1U] =
  70. pSrc[(2U * (j + fftLenBy2p1)) + 1U];
  71. pSrc[(2U * (j + fftLenBy2p1)) + 1U] = in;
  72. }
  73. /* pSrc[i+1U] <-> pSrc[j+1U] */
  74. in = pSrc[2U * (i + 1U)];
  75. pSrc[2U * (i + 1U)] = pSrc[2U * (j + fftLenBy2)];
  76. pSrc[2U * (j + fftLenBy2)] = in;
  77. /* pSrc[i+2U] <-> pSrc[j+2U] */
  78. in = pSrc[(2U * (i + 1U)) + 1U];
  79. pSrc[(2U * (i + 1U)) + 1U] = pSrc[(2U * (j + fftLenBy2)) + 1U];
  80. pSrc[(2U * (j + fftLenBy2)) + 1U] = in;
  81. /* Reading the index for the bit reversal */
  82. j = *pBitRevTab;
  83. /* Updating the bit reversal index depending on the fft length */
  84. pBitRevTab += bitRevFactor;
  85. }
  86. }
  87. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */