arm_q15_to_f16.c 4.0 KB

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