arm_q31_to_float.c 5.3 KB

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