arm_q31_to_float.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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: 23 April 2021
  7. * $Revision: V1.9.0
  8. *
  9. * Target Processor: Cortex-M and Cortex-A cores
  10. * -------------------------------------------------------------------- */
  11. /*
  12. * Copyright (C) 2010-2021 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/support_functions.h"
  29. /**
  30. @ingroup groupSupport
  31. */
  32. /**
  33. * @defgroup q31_to_x Convert 32-bit fixed point 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. @par Details
  45. The equation used for the conversion process is:
  46. <pre>
  47. pDst[n] = (float32_t) pSrc[n] / 2147483648; 0 <= n < blockSize.
  48. </pre>
  49. */
  50. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  51. void arm_q31_to_float(
  52. const q31_t * pSrc,
  53. float32_t * pDst,
  54. uint32_t blockSize)
  55. {
  56. uint32_t blkCnt; /* loop counters */
  57. q31x4_t vecDst;
  58. q31_t const *pSrcVec;
  59. pSrcVec = (q31_t const *) pSrc;
  60. blkCnt = blockSize >> 2;
  61. while (blkCnt > 0U)
  62. {
  63. /* C = (float32_t) A / 2147483648 */
  64. /* convert from q31 to float and then store the results in the destination buffer */
  65. vecDst = vld1q(pSrcVec);
  66. pSrcVec += 4;
  67. vstrwq(pDst, vcvtq_n_f32_s32(vecDst, 31));
  68. pDst += 4;
  69. /*
  70. * Decrement the blockSize loop counter
  71. */
  72. blkCnt--;
  73. }
  74. /*
  75. * tail
  76. * (will be merged thru tail predication)
  77. */
  78. blkCnt = blockSize & 3;
  79. while (blkCnt > 0U)
  80. {
  81. /* C = (float32_t) A / 2147483648 */
  82. /* Convert from q31 to float and store result in destination buffer */
  83. *pDst++ = ((float32_t) *pSrcVec++ / 2147483648.0f);
  84. /* Decrement loop counter */
  85. blkCnt--;
  86. }
  87. }
  88. #else
  89. #if defined(ARM_MATH_NEON_EXPERIMENTAL)
  90. void arm_q31_to_float(
  91. const q31_t * pSrc,
  92. float32_t * pDst,
  93. uint32_t blockSize)
  94. {
  95. const q31_t *pIn = pSrc; /* Src pointer */
  96. uint32_t blkCnt; /* loop counter */
  97. int32x4_t inV;
  98. float32x4_t outV;
  99. blkCnt = blockSize >> 2U;
  100. /* Compute 4 outputs at a time.
  101. ** a second loop below computes the remaining 1 to 3 samples. */
  102. while (blkCnt > 0U)
  103. {
  104. /* C = (float32_t) A / 2147483648 */
  105. /* Convert from q31 to float and then store the results in the destination buffer */
  106. inV = vld1q_s32(pIn);
  107. pIn += 4;
  108. outV = vcvtq_n_f32_s32(inV,31);
  109. vst1q_f32(pDst, outV);
  110. pDst += 4;
  111. /* Decrement the loop counter */
  112. blkCnt--;
  113. }
  114. /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
  115. ** No loop unrolling is used. */
  116. blkCnt = blockSize & 3;
  117. while (blkCnt > 0U)
  118. {
  119. /* C = (float32_t) A / 2147483648 */
  120. /* Convert from q31 to float and then store the results in the destination buffer */
  121. *pDst++ = ((float32_t) * pIn++ / 2147483648.0f);
  122. /* Decrement the loop counter */
  123. blkCnt--;
  124. }
  125. }
  126. #else
  127. void arm_q31_to_float(
  128. const q31_t * pSrc,
  129. float32_t * pDst,
  130. uint32_t blockSize)
  131. {
  132. const q31_t *pIn = pSrc; /* Src pointer */
  133. uint32_t blkCnt; /* loop counter */
  134. #if defined (ARM_MATH_LOOPUNROLL)
  135. /* Loop unrolling */
  136. blkCnt = blockSize >> 2U;
  137. while (blkCnt > 0U)
  138. {
  139. /* C = (float32_t) A / 2147483648 */
  140. /* Convert from q31 to float and store result in destination buffer */
  141. *pDst++ = ((float32_t) *pIn++ / 2147483648.0f);
  142. *pDst++ = ((float32_t) *pIn++ / 2147483648.0f);
  143. *pDst++ = ((float32_t) *pIn++ / 2147483648.0f);
  144. *pDst++ = ((float32_t) *pIn++ / 2147483648.0f);
  145. /* Decrement loop counter */
  146. blkCnt--;
  147. }
  148. /* Loop unrolling: Compute remaining outputs */
  149. blkCnt = blockSize % 0x4U;
  150. #else
  151. /* Initialize blkCnt with number of samples */
  152. blkCnt = blockSize;
  153. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  154. while (blkCnt > 0U)
  155. {
  156. /* C = (float32_t) A / 2147483648 */
  157. /* Convert from q31 to float and store result in destination buffer */
  158. *pDst++ = ((float32_t) *pIn++ / 2147483648.0f);
  159. /* Decrement loop counter */
  160. blkCnt--;
  161. }
  162. }
  163. #endif /* #if defined(ARM_MATH_NEON) */
  164. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  165. /**
  166. @} end of q31_to_x group
  167. */