1 /* ----------------------------------------------------------------------
2  * Project:      CMSIS DSP Library
3  * Title:        arm_bitreversal2.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) 2019 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.h"
30 #include "arm_common_tables.h"
31 
32 void arm_bitreversal_64(
33         uint64_t *pSrc,
34   const uint16_t bitRevLen,
35   const uint16_t *pBitRevTab);
36 
37 
38 /**
39   @brief         In-place 64 bit reversal function.
40   @param[in,out] pSrc        points to in-place buffer of unknown 64-bit data type
41   @param[in]     bitRevLen   bit reversal table length
42   @param[in]     pBitRevTab  points to bit reversal table
43 */
44 
arm_bitreversal_64(uint64_t * pSrc,const uint16_t bitRevLen,const uint16_t * pBitRevTab)45 ARM_DSP_ATTRIBUTE void arm_bitreversal_64(
46         uint64_t *pSrc,
47   const uint16_t bitRevLen,
48   const uint16_t *pBitRevTab)
49 {
50   uint64_t a, b, tmp;
51   uint32_t i;
52 
53   for (i = 0; i < bitRevLen; )
54   {
55      a = pBitRevTab[i    ] >> 2;
56      b = pBitRevTab[i + 1] >> 2;
57 
58      //real
59      tmp = pSrc[a];
60      pSrc[a] = pSrc[b];
61      pSrc[b] = tmp;
62 
63      //complex
64      tmp = pSrc[a+1];
65      pSrc[a+1] = pSrc[b+1];
66      pSrc[b+1] = tmp;
67 
68     i += 2;
69   }
70 }
71 
72 void arm_bitreversal_32(
73         uint32_t *pSrc,
74   const uint16_t bitRevLen,
75   const uint16_t *pBitRevTab);
76 
77 /**
78   @brief         In-place 32 bit reversal function.
79   @param[in,out] pSrc        points to in-place buffer of unknown 32-bit data type
80   @param[in]     bitRevLen   bit reversal table length
81   @param[in]     pBitRevTab  points to bit reversal table
82 */
83 
arm_bitreversal_32(uint32_t * pSrc,const uint16_t bitRevLen,const uint16_t * pBitRevTab)84 ARM_DSP_ATTRIBUTE void arm_bitreversal_32(
85         uint32_t *pSrc,
86   const uint16_t bitRevLen,
87   const uint16_t *pBitRevTab)
88 {
89   uint32_t a, b, i, tmp;
90 
91   for (i = 0; i < bitRevLen; )
92   {
93      a = pBitRevTab[i    ] >> 2;
94      b = pBitRevTab[i + 1] >> 2;
95 
96      //real
97      tmp = pSrc[a];
98      pSrc[a] = pSrc[b];
99      pSrc[b] = tmp;
100 
101      //complex
102      tmp = pSrc[a+1];
103      pSrc[a+1] = pSrc[b+1];
104      pSrc[b+1] = tmp;
105 
106     i += 2;
107   }
108 }
109 
110 void arm_bitreversal_16(
111         uint16_t *pSrc,
112   const uint16_t bitRevLen,
113   const uint16_t *pBitRevTab);
114 
115 
116 /**
117   @brief         In-place 16 bit reversal function.
118   @param[in,out] pSrc        points to in-place buffer of unknown 16-bit data type
119   @param[in]     bitRevLen   bit reversal table length
120   @param[in]     pBitRevTab  points to bit reversal table
121 */
122 
arm_bitreversal_16(uint16_t * pSrc,const uint16_t bitRevLen,const uint16_t * pBitRevTab)123 ARM_DSP_ATTRIBUTE void arm_bitreversal_16(
124         uint16_t *pSrc,
125   const uint16_t bitRevLen,
126   const uint16_t *pBitRevTab)
127 {
128   uint16_t a, b, tmp;
129   uint32_t i;
130 
131   for (i = 0; i < bitRevLen; )
132   {
133      a = pBitRevTab[i    ] >> 2;
134      b = pBitRevTab[i + 1] >> 2;
135 
136      //real
137      tmp = pSrc[a];
138      pSrc[a] = pSrc[b];
139      pSrc[b] = tmp;
140 
141      //complex
142      tmp = pSrc[a+1];
143      pSrc[a+1] = pSrc[b+1];
144      pSrc[b+1] = tmp;
145 
146     i += 2;
147   }
148 }
149