arm_q15_to_float.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_q15_to_float.c
  4. * Description: Converts the elements of the Q15 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 q15_to_x Convert 16-bit fixed point value
  34. */
  35. /**
  36. @addtogroup q15_to_x
  37. @{
  38. */
  39. /**
  40. @brief Converts the elements of the Q15 vector to floating-point vector.
  41. @param[in] pSrc points to the Q15 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] / 32768; 0 <= n < blockSize.
  49. </pre>
  50. */
  51. #if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)
  52. void arm_q15_to_float(
  53. const q15_t * pSrc,
  54. float32_t * pDst,
  55. uint32_t blockSize)
  56. {
  57. uint32_t blkCnt;
  58. q15x8_t vecDst;
  59. q15_t const *pSrcVec;
  60. pSrcVec = (q15_t const *) pSrc;
  61. blkCnt = blockSize >> 2;
  62. while (blkCnt > 0U)
  63. {
  64. /* C = (float32_t) A / 32768 */
  65. /* convert from q15 to float and then store the results in the destination buffer */
  66. vecDst = vldrhq_s32(pSrcVec);
  67. pSrcVec += 4;
  68. vstrwq(pDst, vcvtq_n_f32_s32((int32x4_t)vecDst, 15));
  69. pDst += 4;
  70. /*
  71. * Decrement the blockSize loop counter
  72. */
  73. blkCnt--;
  74. }
  75. blkCnt = blockSize & 3;
  76. while (blkCnt > 0U)
  77. {
  78. /* C = (float32_t) A / 32768 */
  79. /* Convert from q15 to float and store result in destination buffer */
  80. *pDst++ = ((float32_t) *pSrcVec++ / 32768.0f);
  81. /* Decrement loop counter */
  82. blkCnt--;
  83. }
  84. }
  85. #else
  86. #if defined(ARM_MATH_NEON_EXPERIMENTAL)
  87. void arm_q15_to_float(
  88. const q15_t * pSrc,
  89. float32_t * pDst,
  90. uint32_t blockSize)
  91. {
  92. const q15_t *pIn = pSrc; /* Src pointer */
  93. uint32_t blkCnt; /* loop counter */
  94. int16x8_t inV;
  95. int32x4_t inV0, inV1;
  96. float32x4_t outV;
  97. blkCnt = blockSize >> 3U;
  98. /* Compute 8 outputs at a time.
  99. ** a second loop below computes the remaining 1 to 7 samples. */
  100. while (blkCnt > 0U)
  101. {
  102. /* C = (float32_t) A / 32768 */
  103. /* convert from q15 to float and then store the results in the destination buffer */
  104. inV = vld1q_s16(pIn);
  105. pIn += 8;
  106. inV0 = vmovl_s16(vget_low_s16(inV));
  107. inV1 = vmovl_s16(vget_high_s16(inV));
  108. outV = vcvtq_n_f32_s32(inV0,15);
  109. vst1q_f32(pDst, outV);
  110. pDst += 4;
  111. outV = vcvtq_n_f32_s32(inV1,15);
  112. vst1q_f32(pDst, outV);
  113. pDst += 4;
  114. /* Decrement the loop counter */
  115. blkCnt--;
  116. }
  117. /* If the blockSize is not a multiple of 8, compute any remaining output samples here.
  118. ** No loop unrolling is used. */
  119. blkCnt = blockSize & 7;
  120. while (blkCnt > 0U)
  121. {
  122. /* C = (float32_t) A / 32768 */
  123. /* convert from q15 to float and then store the results in the destination buffer */
  124. *pDst++ = ((float32_t) * pIn++ / 32768.0f);
  125. /* Decrement the loop counter */
  126. blkCnt--;
  127. }
  128. }
  129. #else
  130. void arm_q15_to_float(
  131. const q15_t * pSrc,
  132. float32_t * pDst,
  133. uint32_t blockSize)
  134. {
  135. uint32_t blkCnt; /* Loop counter */
  136. const q15_t *pIn = pSrc; /* Source pointer */
  137. #if defined (ARM_MATH_LOOPUNROLL)
  138. /* Loop unrolling: Compute 4 outputs at a time */
  139. blkCnt = blockSize >> 2U;
  140. while (blkCnt > 0U)
  141. {
  142. /* C = (float32_t) A / 32768 */
  143. /* Convert from q15 to float and store result in destination buffer */
  144. *pDst++ = ((float32_t) * pIn++ / 32768.0f);
  145. *pDst++ = ((float32_t) * pIn++ / 32768.0f);
  146. *pDst++ = ((float32_t) * pIn++ / 32768.0f);
  147. *pDst++ = ((float32_t) * pIn++ / 32768.0f);
  148. /* Decrement loop counter */
  149. blkCnt--;
  150. }
  151. /* Loop unrolling: Compute remaining outputs */
  152. blkCnt = blockSize % 0x4U;
  153. #else
  154. /* Initialize blkCnt with number of samples */
  155. blkCnt = blockSize;
  156. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  157. while (blkCnt > 0U)
  158. {
  159. /* C = (float32_t) A / 32768 */
  160. /* Convert from q15 to float and store result in destination buffer */
  161. *pDst++ = ((float32_t) *pIn++ / 32768.0f);
  162. /* Decrement loop counter */
  163. blkCnt--;
  164. }
  165. }
  166. #endif /* #if defined(ARM_MATH_NEON) */
  167. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  168. /**
  169. @} end of q15_to_x group
  170. */