arm_bitreversal2.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #include "dsp/transform_functions.h"
  29. #include "arm_common_tables.h"
  30. /**
  31. @brief In-place 64 bit reversal function.
  32. @param[in,out] pSrc points to in-place buffer of unknown 64-bit data type
  33. @param[in] bitRevLen bit reversal table length
  34. @param[in] pBitRevTab points to bit reversal table
  35. */
  36. void arm_bitreversal_64(
  37. uint64_t *pSrc,
  38. const uint16_t bitRevLen,
  39. const uint16_t *pBitRevTab)
  40. {
  41. uint64_t a, b, tmp;
  42. uint32_t i;
  43. for (i = 0; i < bitRevLen; )
  44. {
  45. a = pBitRevTab[i ] >> 2;
  46. b = pBitRevTab[i + 1] >> 2;
  47. //real
  48. tmp = pSrc[a];
  49. pSrc[a] = pSrc[b];
  50. pSrc[b] = tmp;
  51. //complex
  52. tmp = pSrc[a+1];
  53. pSrc[a+1] = pSrc[b+1];
  54. pSrc[b+1] = tmp;
  55. i += 2;
  56. }
  57. }
  58. /**
  59. @brief In-place 32 bit reversal function.
  60. @param[in,out] pSrc points to in-place buffer of unknown 32-bit data type
  61. @param[in] bitRevLen bit reversal table length
  62. @param[in] pBitRevTab points to bit reversal table
  63. */
  64. void arm_bitreversal_32(
  65. uint32_t *pSrc,
  66. const uint16_t bitRevLen,
  67. const uint16_t *pBitRevTab)
  68. {
  69. uint32_t a, b, i, tmp;
  70. for (i = 0; i < bitRevLen; )
  71. {
  72. a = pBitRevTab[i ] >> 2;
  73. b = pBitRevTab[i + 1] >> 2;
  74. //real
  75. tmp = pSrc[a];
  76. pSrc[a] = pSrc[b];
  77. pSrc[b] = tmp;
  78. //complex
  79. tmp = pSrc[a+1];
  80. pSrc[a+1] = pSrc[b+1];
  81. pSrc[b+1] = tmp;
  82. i += 2;
  83. }
  84. }
  85. /**
  86. @brief In-place 16 bit reversal function.
  87. @param[in,out] pSrc points to in-place buffer of unknown 16-bit data type
  88. @param[in] bitRevLen bit reversal table length
  89. @param[in] pBitRevTab points to bit reversal table
  90. */
  91. void arm_bitreversal_16(
  92. uint16_t *pSrc,
  93. const uint16_t bitRevLen,
  94. const uint16_t *pBitRevTab)
  95. {
  96. uint16_t a, b, tmp;
  97. uint32_t i;
  98. for (i = 0; i < bitRevLen; )
  99. {
  100. a = pBitRevTab[i ] >> 2;
  101. b = pBitRevTab[i + 1] >> 2;
  102. //real
  103. tmp = pSrc[a];
  104. pSrc[a] = pSrc[b];
  105. pSrc[b] = tmp;
  106. //complex
  107. tmp = pSrc[a+1];
  108. pSrc[a+1] = pSrc[b+1];
  109. pSrc[b+1] = tmp;
  110. i += 2;
  111. }
  112. }