arm_q15_to_float.c 5.2 KB

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