support_functions_f16.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /******************************************************************************
  2. * @file support_functions_f16.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.10.0
  5. * @date 08 July 2021
  6. * Target Processor: Cortex-M and Cortex-A cores
  7. ******************************************************************************/
  8. /*
  9. * Copyright (c) 2010-2020 Arm Limited or its affiliates. All rights reserved.
  10. *
  11. * SPDX-License-Identifier: Apache-2.0
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the License); you may
  14. * not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  21. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. #ifndef _SUPPORT_FUNCTIONS_F16_H_
  26. #define _SUPPORT_FUNCTIONS_F16_H_
  27. #include "arm_math_types_f16.h"
  28. #include "arm_math_memory.h"
  29. #include "dsp/none.h"
  30. #include "dsp/utils.h"
  31. #ifdef __cplusplus
  32. extern "C"
  33. {
  34. #endif
  35. #if defined(ARM_FLOAT16_SUPPORTED)
  36. /**
  37. * @brief Copies the elements of a floating-point vector.
  38. * @param[in] pSrc input pointer
  39. * @param[out] pDst output pointer
  40. * @param[in] blockSize number of samples to process
  41. */
  42. void arm_copy_f16(const float16_t * pSrc, float16_t * pDst, uint32_t blockSize);
  43. /**
  44. * @brief Fills a constant value into a floating-point vector.
  45. * @param[in] value input value to be filled
  46. * @param[out] pDst output pointer
  47. * @param[in] blockSize number of samples to process
  48. */
  49. void arm_fill_f16(float16_t value, float16_t * pDst, uint32_t blockSize);
  50. /**
  51. * @brief Converts the elements of the floating-point vector to Q31 vector.
  52. * @param[in] pSrc points to the f16 input vector
  53. * @param[out] pDst points to the q15 output vector
  54. * @param[in] blockSize length of the input vector
  55. */
  56. void arm_f16_to_q15(const float16_t * pSrc, q15_t * pDst, uint32_t blockSize);
  57. /**
  58. * @brief Converts the elements of the floating-point vector to Q31 vector.
  59. * @param[in] pSrc points to the q15 input vector
  60. * @param[out] pDst points to the f16 output vector
  61. * @param[in] blockSize length of the input vector
  62. */
  63. void arm_q15_to_f16(const q15_t * pSrc, float16_t * pDst, uint32_t blockSize);
  64. /**
  65. * @brief Converts the elements of the floating-point vector to Q31 vector.
  66. * @param[in] pSrc points to the f32 input vector
  67. * @param[out] pDst points to the f16 output vector
  68. * @param[in] blockSize length of the input vector
  69. */
  70. void arm_float_to_f16(const float32_t * pSrc, float16_t * pDst, uint32_t blockSize);
  71. /**
  72. * @brief Converts the elements of the floating-point vector to Q31 vector.
  73. * @param[in] pSrc points to the f16 input vector
  74. * @param[out] pDst points to the f32 output vector
  75. * @param[in] blockSize length of the input vector
  76. */
  77. void arm_f16_to_float(const float16_t * pSrc, float32_t * pDst, uint32_t blockSize);
  78. /**
  79. * @brief Weighted sum
  80. *
  81. *
  82. * @param[in] *in Array of input values.
  83. * @param[in] *weigths Weights
  84. * @param[in] blockSize Number of samples in the input array.
  85. * @return Weighted sum
  86. *
  87. */
  88. float16_t arm_weighted_sum_f16(const float16_t *in
  89. , const float16_t *weigths
  90. , uint32_t blockSize);
  91. /**
  92. * @brief Barycenter
  93. *
  94. *
  95. * @param[in] in List of vectors
  96. * @param[in] weights Weights of the vectors
  97. * @param[out] out Barycenter
  98. * @param[in] nbVectors Number of vectors
  99. * @param[in] vecDim Dimension of space (vector dimension)
  100. * @return None
  101. *
  102. */
  103. void arm_barycenter_f16(const float16_t *in
  104. , const float16_t *weights
  105. , float16_t *out
  106. , uint32_t nbVectors
  107. , uint32_t vecDim);
  108. /**
  109. @ingroup groupSupport
  110. */
  111. /**
  112. * @defgroup typecast Typecasting
  113. */
  114. /**
  115. @addtogroup typecast
  116. @{
  117. */
  118. /**
  119. * @brief Interpret a f16 as an s16 value
  120. * @param[in] x input value.
  121. * @return return value.
  122. *
  123. * @par Description
  124. * It is a typecast. No conversion of the float to int is done.
  125. * The memcpy will be optimized out by the compiler.
  126. * memcpy is used to prevent type punning issues.
  127. * With gcc, -fno-builtins MUST not be used or the
  128. * memcpy will not be optimized out.
  129. */
  130. __STATIC_INLINE int16_t arm_typecast_s16_f16(float16_t x)
  131. {
  132. int16_t res;
  133. res=*(int16_t*)memcpy((char*)&res,(char*)&x,sizeof(float16_t));
  134. return(res);
  135. }
  136. /**
  137. * @brief Interpret an s16 as an f16 value
  138. * @param[in] x input value.
  139. * @return return value.
  140. *
  141. * @par Description
  142. * It is a typecast. No conversion of the int to float is done.
  143. * The memcpy will be optimized out by the compiler.
  144. * memcpy is used to prevent type punning issues.
  145. * With gcc, -fno-builtins MUST not be used or the
  146. * memcpy will not be optimized out.
  147. */
  148. __STATIC_INLINE float16_t arm_typecast_f16_s16(int16_t x)
  149. {
  150. float16_t res;
  151. res=*(float16_t*)memcpy((char*)&res,(char*)&x,sizeof(int16_t));
  152. return(res);
  153. }
  154. /**
  155. @} end of typecast group
  156. */
  157. #endif /*defined(ARM_FLOAT16_SUPPORTED)*/
  158. #ifdef __cplusplus
  159. }
  160. #endif
  161. #endif /* ifndef _SUPPORT_FUNCTIONS_F16_H_ */