arm_q15_to_float.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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: 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 q15_to_x Convert 16-bit Integer 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_NEON_EXPERIMENTAL)
  52. void arm_q15_to_float(
  53. const q15_t * pSrc,
  54. float32_t * pDst,
  55. uint32_t blockSize)
  56. {
  57. const q15_t *pIn = pSrc; /* Src pointer */
  58. uint32_t blkCnt; /* loop counter */
  59. int16x8_t inV;
  60. int32x4_t inV0, inV1;
  61. float32x4_t outV;
  62. blkCnt = blockSize >> 3U;
  63. /* Compute 8 outputs at a time.
  64. ** a second loop below computes the remaining 1 to 7 samples. */
  65. while (blkCnt > 0U)
  66. {
  67. /* C = (float32_t) A / 32768 */
  68. /* convert from q15 to float and then store the results in the destination buffer */
  69. inV = vld1q_s16(pIn);
  70. pIn += 8;
  71. inV0 = vmovl_s16(vget_low_s16(inV));
  72. inV1 = vmovl_s16(vget_high_s16(inV));
  73. outV = vcvtq_n_f32_s32(inV0,15);
  74. vst1q_f32(pDst, outV);
  75. pDst += 4;
  76. outV = vcvtq_n_f32_s32(inV1,15);
  77. vst1q_f32(pDst, outV);
  78. pDst += 4;
  79. /* Decrement the loop counter */
  80. blkCnt--;
  81. }
  82. /* If the blockSize is not a multiple of 8, compute any remaining output samples here.
  83. ** No loop unrolling is used. */
  84. blkCnt = blockSize & 7;
  85. while (blkCnt > 0U)
  86. {
  87. /* C = (float32_t) A / 32768 */
  88. /* convert from q15 to float and then store the results in the destination buffer */
  89. *pDst++ = ((float32_t) * pIn++ / 32768.0f);
  90. /* Decrement the loop counter */
  91. blkCnt--;
  92. }
  93. }
  94. #else
  95. void arm_q15_to_float(
  96. const q15_t * pSrc,
  97. float32_t * pDst,
  98. uint32_t blockSize)
  99. {
  100. uint32_t blkCnt; /* Loop counter */
  101. const q15_t *pIn = pSrc; /* Source pointer */
  102. #if defined (ARM_MATH_LOOPUNROLL)
  103. /* Loop unrolling: Compute 4 outputs at a time */
  104. blkCnt = blockSize >> 2U;
  105. while (blkCnt > 0U)
  106. {
  107. /* C = (float32_t) A / 32768 */
  108. /* Convert from q15 to float and store result in destination buffer */
  109. *pDst++ = ((float32_t) * pIn++ / 32768.0f);
  110. *pDst++ = ((float32_t) * pIn++ / 32768.0f);
  111. *pDst++ = ((float32_t) * pIn++ / 32768.0f);
  112. *pDst++ = ((float32_t) * pIn++ / 32768.0f);
  113. /* Decrement loop counter */
  114. blkCnt--;
  115. }
  116. /* Loop unrolling: Compute remaining outputs */
  117. blkCnt = blockSize % 0x4U;
  118. #else
  119. /* Initialize blkCnt with number of samples */
  120. blkCnt = blockSize;
  121. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  122. while (blkCnt > 0U)
  123. {
  124. /* C = (float32_t) A / 32768 */
  125. /* Convert from q15 to float and store result in destination buffer */
  126. *pDst++ = ((float32_t) *pIn++ / 32768.0f);
  127. /* Decrement loop counter */
  128. blkCnt--;
  129. }
  130. }
  131. #endif /* #if defined(ARM_MATH_NEON) */
  132. /**
  133. @} end of q15_to_x group
  134. */