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
29 #include "dsp/transform_functions_f16.h"
30
31
32
33 /*
34 * @brief In-place bit reversal function.
35 * @param[in, out] *pSrc points to the in-place buffer of floating-point data type.
36 * @param[in] fftSize length of the FFT.
37 * @param[in] bitRevFactor bit reversal modifier that supports different size FFTs with the same bit reversal table.
38 * @param[in] *pBitRevTab points to the bit reversal table.
39 */
40
41 #if defined(ARM_FLOAT16_SUPPORTED)
42
43 void arm_bitreversal_f16(
44 float16_t * pSrc,
45 uint16_t fftSize,
46 uint16_t bitRevFactor,
47 const uint16_t * pBitRevTab);
48
arm_bitreversal_f16(float16_t * pSrc,uint16_t fftSize,uint16_t bitRevFactor,const uint16_t * pBitRevTab)49 ARM_DSP_ATTRIBUTE void arm_bitreversal_f16(
50 float16_t * pSrc,
51 uint16_t fftSize,
52 uint16_t bitRevFactor,
53 const uint16_t * pBitRevTab)
54 {
55 uint16_t fftLenBy2, fftLenBy2p1;
56 uint16_t i, j;
57 float16_t in;
58
59 /* Initializations */
60 j = 0U;
61 fftLenBy2 = fftSize >> 1U;
62 fftLenBy2p1 = (fftSize >> 1U) + 1U;
63
64 /* Bit Reversal Implementation */
65 for (i = 0U; i <= (fftLenBy2 - 2U); i += 2U)
66 {
67 if (i < j)
68 {
69 /* pSrc[i] <-> pSrc[j]; */
70 in = pSrc[2U * i];
71 pSrc[2U * i] = pSrc[2U * j];
72 pSrc[2U * j] = in;
73
74 /* pSrc[i+1U] <-> pSrc[j+1U] */
75 in = pSrc[(2U * i) + 1U];
76 pSrc[(2U * i) + 1U] = pSrc[(2U * j) + 1U];
77 pSrc[(2U * j) + 1U] = in;
78
79 /* pSrc[i+fftLenBy2p1] <-> pSrc[j+fftLenBy2p1] */
80 in = pSrc[2U * (i + fftLenBy2p1)];
81 pSrc[2U * (i + fftLenBy2p1)] = pSrc[2U * (j + fftLenBy2p1)];
82 pSrc[2U * (j + fftLenBy2p1)] = in;
83
84 /* pSrc[i+fftLenBy2p1+1U] <-> pSrc[j+fftLenBy2p1+1U] */
85 in = pSrc[(2U * (i + fftLenBy2p1)) + 1U];
86 pSrc[(2U * (i + fftLenBy2p1)) + 1U] =
87 pSrc[(2U * (j + fftLenBy2p1)) + 1U];
88 pSrc[(2U * (j + fftLenBy2p1)) + 1U] = in;
89
90 }
91
92 /* pSrc[i+1U] <-> pSrc[j+1U] */
93 in = pSrc[2U * (i + 1U)];
94 pSrc[2U * (i + 1U)] = pSrc[2U * (j + fftLenBy2)];
95 pSrc[2U * (j + fftLenBy2)] = in;
96
97 /* pSrc[i+2U] <-> pSrc[j+2U] */
98 in = pSrc[(2U * (i + 1U)) + 1U];
99 pSrc[(2U * (i + 1U)) + 1U] = pSrc[(2U * (j + fftLenBy2)) + 1U];
100 pSrc[(2U * (j + fftLenBy2)) + 1U] = in;
101
102 /* Reading the index for the bit reversal */
103 j = *pBitRevTab;
104
105 /* Updating the bit reversal index depending on the fft length */
106 pBitRevTab += bitRevFactor;
107 }
108 }
109 #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
110