support_functions_f16.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /******************************************************************************
  2. * @file support_functions_f16.h
  3. * @brief Public header file for CMSIS DSP Library
  4. * @version V1.10.1
  5. * @date 18 August 2022
  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 64 bit floating-point vector to 16 bit floating-point vector.
  66. * @param[in] pSrc points to the f64 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_f64_to_f16(const float64_t * pSrc, float16_t * pDst, uint32_t blockSize);
  71. /**
  72. * @brief Converts the elements of the 16 bit floating-point vector to 64 bit floating-point vector.
  73. * @param[in] pSrc points to the f16 input vector
  74. * @param[out] pDst points to the f64 output vector
  75. * @param[in] blockSize length of the input vector
  76. */
  77. void arm_f16_to_f64(const float16_t * pSrc, float64_t * pDst, uint32_t blockSize);
  78. /**
  79. * @brief Converts the elements of the floating-point vector to Q31 vector.
  80. * @param[in] pSrc points to the f32 input vector
  81. * @param[out] pDst points to the f16 output vector
  82. * @param[in] blockSize length of the input vector
  83. */
  84. void arm_float_to_f16(const float32_t * pSrc, float16_t * pDst, uint32_t blockSize);
  85. /**
  86. * @brief Converts the elements of the floating-point vector to Q31 vector.
  87. * @param[in] pSrc points to the f16 input vector
  88. * @param[out] pDst points to the f32 output vector
  89. * @param[in] blockSize length of the input vector
  90. */
  91. void arm_f16_to_float(const float16_t * pSrc, float32_t * pDst, uint32_t blockSize);
  92. /**
  93. * @brief Weighted sum
  94. * @param[in] *in Array of input values.
  95. * @param[in] *weigths Weights
  96. * @param[in] blockSize Number of samples in the input array.
  97. * @return Weighted sum
  98. */
  99. float16_t arm_weighted_sum_f16(const float16_t *in
  100. , const float16_t *weigths
  101. , uint32_t blockSize);
  102. /**
  103. * @brief Barycenter
  104. * @param[in] in List of vectors
  105. * @param[in] weights Weights of the vectors
  106. * @param[out] out Barycenter
  107. * @param[in] nbVectors Number of vectors
  108. * @param[in] vecDim Dimension of space (vector dimension)
  109. */
  110. void arm_barycenter_f16(const float16_t *in
  111. , const float16_t *weights
  112. , float16_t *out
  113. , uint32_t nbVectors
  114. , uint32_t vecDim);
  115. /**
  116. @ingroup groupSupport
  117. */
  118. /**
  119. * @defgroup typecast Typecasting
  120. */
  121. /**
  122. @addtogroup typecast
  123. @{
  124. */
  125. /**
  126. * @brief Interpret a f16 as an s16 value
  127. * @param[in] x input value.
  128. * @return return value.
  129. *
  130. * @par Description
  131. * It is a typecast. No conversion of the float to int is done.
  132. * The memcpy will be optimized out by the compiler.
  133. * memcpy is used to prevent type punning issues.
  134. * With gcc, -fno-builtins MUST not be used or the
  135. * memcpy will not be optimized out.
  136. */
  137. __STATIC_INLINE int16_t arm_typecast_s16_f16(float16_t x)
  138. {
  139. int16_t res;
  140. res=*(int16_t*)memcpy((char*)&res,(char*)&x,sizeof(float16_t));
  141. return(res);
  142. }
  143. /**
  144. * @brief Interpret an s16 as an f16 value
  145. * @param[in] x input value.
  146. * @return return value.
  147. *
  148. * @par Description
  149. * It is a typecast. No conversion of the int to float is done.
  150. * The memcpy will be optimized out by the compiler.
  151. * memcpy is used to prevent type punning issues.
  152. * With gcc, -fno-builtins MUST not be used or the
  153. * memcpy will not be optimized out.
  154. */
  155. __STATIC_INLINE float16_t arm_typecast_f16_s16(int16_t x)
  156. {
  157. float16_t res;
  158. res=*(float16_t*)memcpy((char*)&res,(char*)&x,sizeof(int16_t));
  159. return(res);
  160. }
  161. /**
  162. @} end of typecast group
  163. */
  164. #endif /*defined(ARM_FLOAT16_SUPPORTED)*/
  165. #ifdef __cplusplus
  166. }
  167. #endif
  168. #endif /* ifndef _SUPPORT_FUNCTIONS_F16_H_ */