arm_q31_to_float.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_q31_to_float.c
  4. * Description: Converts the elements of the Q31 vector to floating-point vector
  5. *
  6. * $Date: 18. March 2019
  7. * $Revision: V1.6.0
  8. *
  9. * Target Processor: Cortex-M cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-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. /**
  30. @ingroup groupSupport
  31. */
  32. /**
  33. * @defgroup q31_to_x Convert 32-bit Integer value
  34. */
  35. /**
  36. @addtogroup q31_to_x
  37. @{
  38. */
  39. /**
  40. @brief Converts the elements of the Q31 vector to floating-point vector.
  41. @param[in] pSrc points to the Q31 input vector
  42. @param[out] pDst points to the floating-point output vector
  43. @param[in] blockSize number of samples in each vector
  44. @return none
  45. @par Details
  46. The equation used for the conversion process is:
  47. <pre>
  48. pDst[n] = (float32_t) pSrc[n] / 2147483648; 0 <= n < blockSize.
  49. </pre>
  50. */
  51. #if defined(ARM_MATH_NEON_EXPERIMENTAL)
  52. void arm_q31_to_float(
  53. const q31_t * pSrc,
  54. float32_t * pDst,
  55. uint32_t blockSize)
  56. {
  57. const q31_t *pIn = pSrc; /* Src pointer */
  58. uint32_t blkCnt; /* loop counter */
  59. int32x4_t inV;
  60. float32x4_t outV;
  61. blkCnt = blockSize >> 2U;
  62. /* Compute 4 outputs at a time.
  63. ** a second loop below computes the remaining 1 to 3 samples. */
  64. while (blkCnt > 0U)
  65. {
  66. /* C = (float32_t) A / 2147483648 */
  67. /* Convert from q31 to float and then store the results in the destination buffer */
  68. inV = vld1q_s32(pIn);
  69. pIn += 4;
  70. outV = vcvtq_n_f32_s32(inV,31);
  71. vst1q_f32(pDst, outV);
  72. pDst += 4;
  73. /* Decrement the loop counter */
  74. blkCnt--;
  75. }
  76. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  77. ** No loop unrolling is used. */
  78. blkCnt = blockSize & 3;
  79. while (blkCnt > 0U)
  80. {
  81. /* C = (float32_t) A / 2147483648 */
  82. /* Convert from q31 to float and then store the results in the destination buffer */
  83. *pDst++ = ((float32_t) * pIn++ / 2147483648.0f);
  84. /* Decrement the loop counter */
  85. blkCnt--;
  86. }
  87. }
  88. #else
  89. void arm_q31_to_float(
  90. const q31_t * pSrc,
  91. float32_t * pDst,
  92. uint32_t blockSize)
  93. {
  94. const q31_t *pIn = pSrc; /* Src pointer */
  95. uint32_t blkCnt; /* loop counter */
  96. #if defined (ARM_MATH_LOOPUNROLL)
  97. /* Loop unrolling */
  98. blkCnt = blockSize >> 2U;
  99. while (blkCnt > 0U)
  100. {
  101. /* C = (float32_t) A / 2147483648 */
  102. /* Convert from q31 to float and store result in destination buffer */
  103. *pDst++ = ((float32_t) *pIn++ / 2147483648.0f);
  104. *pDst++ = ((float32_t) *pIn++ / 2147483648.0f);
  105. *pDst++ = ((float32_t) *pIn++ / 2147483648.0f);
  106. *pDst++ = ((float32_t) *pIn++ / 2147483648.0f);
  107. /* Decrement loop counter */
  108. blkCnt--;
  109. }
  110. /* Loop unrolling: Compute remaining outputs */
  111. blkCnt = blockSize % 0x4U;
  112. #else
  113. /* Initialize blkCnt with number of samples */
  114. blkCnt = blockSize;
  115. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  116. while (blkCnt > 0U)
  117. {
  118. /* C = (float32_t) A / 2147483648 */
  119. /* Convert from q31 to float and store result in destination buffer */
  120. *pDst++ = ((float32_t) *pIn++ / 2147483648.0f);
  121. /* Decrement loop counter */
  122. blkCnt--;
  123. }
  124. }
  125. #endif /* #if defined(ARM_MATH_NEON) */
  126. /**
  127. @} end of q31_to_x group
  128. */