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