arm_q7_to_float.c 4.6 KB

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