arm_f16_to_float.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* ----------------------------------------------------------------------
  2. * Project: CMSIS DSP Library
  3. * Title: arm_float_to_q15.c
  4. * Description: Converts the elements of the floating-point vector to Q15 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 f16_to_x Convert 16-bit floating point value
  35. */
  36. /**
  37. @addtogroup f16_to_x
  38. @{
  39. */
  40. /**
  41. @brief Converts the elements of the f16 vector to f32 vector.
  42. @param[in] pSrc points to the f16 input vector
  43. @param[out] pDst points to the f32 output vector
  44. @param[in] blockSize number of samples in each vector
  45. @return none
  46. */
  47. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) && defined(__CMSIS_GCC_H)
  48. #pragma GCC warning "Scalar version of arm_f16_to_float built. Helium version has build issues with gcc."
  49. #endif
  50. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) && !defined(__CMSIS_GCC_H)
  51. void arm_f16_to_float(
  52. const float16_t * pSrc,
  53. float32_t * pDst,
  54. uint32_t blockSize)
  55. {
  56. int32_t blkCnt; /* loop counters */
  57. float16x8_t vecDst;
  58. float32x4x2_t tmp;
  59. blkCnt = blockSize >> 3;
  60. while (blkCnt > 0)
  61. {
  62. vecDst = vldrhq_f16(pSrc);
  63. pSrc += 8;
  64. tmp.val[0] = vcvtbq_f32_f16(vecDst);
  65. tmp.val[1] = vcvttq_f32_f16(vecDst);
  66. vst2q(pDst,tmp);
  67. 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. while (blkCnt > 0)
  79. {
  80. *pDst++ = (float32_t) *pSrc++;
  81. /*
  82. * Decrement the loop counter
  83. */
  84. blkCnt--;
  85. }
  86. }
  87. #else
  88. void arm_f16_to_float(
  89. const float16_t * pSrc,
  90. float32_t * pDst,
  91. uint32_t blockSize)
  92. {
  93. const float16_t *pIn = pSrc; /* Src pointer */
  94. uint32_t blkCnt; /* loop counter */
  95. /*
  96. * Loop over blockSize number of values
  97. */
  98. blkCnt = blockSize;
  99. while (blkCnt > 0U)
  100. {
  101. *pDst++ = (float32_t) * pIn++;
  102. /*
  103. * Decrement the loop counter
  104. */
  105. blkCnt--;
  106. }
  107. }
  108. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  109. /**
  110. @} end of f16_to_x group
  111. */
  112. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */