arm_q15_to_f16.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_f16.h"
  29. #if defined(ARM_FLOAT16_SUPPORTED)
  30. /**
  31. @ingroup groupSupport
  32. */
  33. /**
  34. * @defgroup q15_to_x Convert 16-bit fixed point value
  35. */
  36. /**
  37. @addtogroup q15_to_x
  38. @{
  39. */
  40. /**
  41. @brief Converts the elements of the Q15 vector to f16 vector.
  42. @param[in] pSrc points to the Q15 input vector
  43. @param[out] pDst points to the f16 output vector
  44. @param[in] blockSize number of samples in each vector
  45. @return none
  46. @par Details
  47. The equation used for the conversion process is:
  48. <pre>
  49. pDst[n] = (float16_t) pSrc[n] / 32768; 0 <= n < blockSize.
  50. </pre>
  51. */
  52. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)
  53. void arm_q15_to_f16(
  54. const q15_t * pSrc,
  55. float16_t * pDst,
  56. uint32_t blockSize)
  57. {
  58. int32_t blkCnt; /* loop counters */
  59. q15x8_t vecDst;
  60. q15_t const *pSrcVec;
  61. pSrcVec = (q15_t const *) pSrc;
  62. blkCnt = blockSize >> 3;
  63. while (blkCnt > 0)
  64. {
  65. /* C = (float16_t) A / 32768 */
  66. /* convert from q15 to float and then store the results in the destination buffer */
  67. vecDst = vld1q(pSrcVec); pSrcVec += 8;
  68. vstrhq(pDst, vcvtq_n_f16_s16(vecDst, 15)); pDst += 8;
  69. /*
  70. * Decrement the blockSize loop counter
  71. */
  72. blkCnt--;
  73. }
  74. /*
  75. * tail
  76. * (will be merged thru tail predication)
  77. */
  78. blkCnt = blockSize & 7;
  79. if (blkCnt > 0)
  80. {
  81. mve_pred16_t p0 = vctp16q(blkCnt);
  82. vecDst = vld1q(pSrcVec); pSrcVec += 8;
  83. vstrhq_p(pDst, vcvtq_n_f16_s16(vecDst, 15), p0);
  84. }
  85. }
  86. #else
  87. void arm_q15_to_f16(
  88. const q15_t * pSrc,
  89. float16_t * pDst,
  90. uint32_t blockSize)
  91. {
  92. uint32_t blkCnt; /* Loop counter */
  93. const q15_t *pIn = pSrc; /* Source pointer */
  94. #if defined (ARM_MATH_LOOPUNROLL)
  95. /* Loop unrolling: Compute 4 outputs at a time */
  96. blkCnt = blockSize >> 2U;
  97. while (blkCnt > 0U)
  98. {
  99. /* C = (float16_t) A / 32768 */
  100. /* Convert from q15 to float and store result in destination buffer */
  101. *pDst++ = ((_Float16) * pIn++ / 32768.0f16);
  102. *pDst++ = ((_Float16) * pIn++ / 32768.0f16);
  103. *pDst++ = ((_Float16) * pIn++ / 32768.0f16);
  104. *pDst++ = ((_Float16) * pIn++ / 32768.0f16);
  105. /* Decrement loop counter */
  106. blkCnt--;
  107. }
  108. /* Loop unrolling: Compute remaining outputs */
  109. blkCnt = blockSize % 0x4U;
  110. #else
  111. /* Initialize blkCnt with number of samples */
  112. blkCnt = blockSize;
  113. #endif /* #if defined (ARM_MATH_LOOPUNROLL) */
  114. while (blkCnt > 0U)
  115. {
  116. /* C = (float16_t) A / 32768 */
  117. /* Convert from q15 to float and store result in destination buffer */
  118. *pDst++ = ((_Float16) *pIn++ / 32768.0f16);
  119. /* Decrement loop counter */
  120. blkCnt--;
  121. }
  122. }
  123. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  124. /**
  125. @} end of q15_to_x group
  126. */
  127. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */