arm_bitreversal2.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_bitreversal2.c
  4. * Description: Bitreversal functions
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.0.0
  8. *
  9. * Target Processor: Cortex-M 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 "arm_math.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. @return none
  36. */
  37. void arm_bitreversal_64(
  38. uint64_t *pSrc,
  39. const uint16_t bitRevLen,
  40. const uint16_t *pBitRevTab)
  41. {
  42. uint64_t a, b, i, tmp;
  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. @return none
  64. */
  65. void arm_bitreversal_32(
  66. uint32_t *pSrc,
  67. const uint16_t bitRevLen,
  68. const uint16_t *pBitRevTab)
  69. {
  70. uint32_t a, b, i, tmp;
  71. for (i = 0; i < bitRevLen; )
  72. {
  73. a = pBitRevTab[i ] >> 2;
  74. b = pBitRevTab[i + 1] >> 2;
  75. //real
  76. tmp = pSrc[a];
  77. pSrc[a] = pSrc[b];
  78. pSrc[b] = tmp;
  79. //complex
  80. tmp = pSrc[a+1];
  81. pSrc[a+1] = pSrc[b+1];
  82. pSrc[b+1] = tmp;
  83. i += 2;
  84. }
  85. }
  86. /**
  87. @brief In-place 16 bit reversal function.
  88. @param[in,out] pSrc points to in-place buffer of unknown 16-bit data type
  89. @param[in] bitRevLen bit reversal table length
  90. @param[in] pBitRevTab points to bit reversal table
  91. @return none
  92. */
  93. void arm_bitreversal_16(
  94. uint16_t *pSrc,
  95. const uint16_t bitRevLen,
  96. const uint16_t *pBitRevTab)
  97. {
  98. uint16_t a, b, i, tmp;
  99. for (i = 0; i < bitRevLen; )
  100. {
  101. a = pBitRevTab[i ] >> 2;
  102. b = pBitRevTab[i + 1] >> 2;
  103. //real
  104. tmp = pSrc[a];
  105. pSrc[a] = pSrc[b];
  106. pSrc[b] = tmp;
  107. //complex
  108. tmp = pSrc[a+1];
  109. pSrc[a+1] = pSrc[b+1];
  110. pSrc[b+1] = tmp;
  111. i += 2;
  112. }
  113. }