arm_f16_to_float.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. */
  46. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) && defined(__CMSIS_GCC_H)
  47. #pragma GCC warning "Scalar version of arm_f16_to_float built. Helium version has build issues with gcc."
  48. #endif
  49. #if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE) && !defined(__CMSIS_GCC_H)
  50. void arm_f16_to_float(
  51. const float16_t * pSrc,
  52. float32_t * pDst,
  53. uint32_t blockSize)
  54. {
  55. int32_t blkCnt; /* loop counters */
  56. float16x8_t vecDst;
  57. float32x4x2_t tmp;
  58. blkCnt = blockSize >> 3;
  59. while (blkCnt > 0)
  60. {
  61. vecDst = vldrhq_f16(pSrc);
  62. pSrc += 8;
  63. tmp.val[0] = vcvtbq_f32_f16(vecDst);
  64. tmp.val[1] = vcvttq_f32_f16(vecDst);
  65. vst2q(pDst,tmp);
  66. pDst += 8;
  67. /*
  68. * Decrement the blockSize loop counter
  69. */
  70. blkCnt--;
  71. }
  72. /*
  73. * tail
  74. * (will be merged thru tail predication)
  75. */
  76. blkCnt = blockSize & 7;
  77. while (blkCnt > 0)
  78. {
  79. *pDst++ = (float32_t) *pSrc++;
  80. /*
  81. * Decrement the loop counter
  82. */
  83. blkCnt--;
  84. }
  85. }
  86. #else
  87. void arm_f16_to_float(
  88. const float16_t * pSrc,
  89. float32_t * pDst,
  90. uint32_t blockSize)
  91. {
  92. const float16_t *pIn = pSrc; /* Src pointer */
  93. uint32_t blkCnt; /* loop counter */
  94. /*
  95. * Loop over blockSize number of values
  96. */
  97. blkCnt = blockSize;
  98. while (blkCnt > 0U)
  99. {
  100. *pDst++ = (float32_t) * pIn++;
  101. /*
  102. * Decrement the loop counter
  103. */
  104. blkCnt--;
  105. }
  106. }
  107. #endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */
  108. /**
  109. @} end of f16_to_x group
  110. */
  111. #endif /* #if defined(ARM_FLOAT16_SUPPORTED) */