arm_q7_to_float.c 5.6 KB

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