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
26
27 #ifndef SUPPORT_FUNCTIONS_F16_H_
28 #define SUPPORT_FUNCTIONS_F16_H_
29
30 #include "arm_math_types_f16.h"
31 #include "arm_math_memory.h"
32
33 #include "dsp/none.h"
34 #include "dsp/utils.h"
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40
41 #if defined(ARM_FLOAT16_SUPPORTED)
42
43 /**
44 * @brief Copies the elements of a floating-point vector.
45 * @param[in] pSrc input pointer
46 * @param[out] pDst output pointer
47 * @param[in] blockSize number of samples to process
48 */
49 void arm_copy_f16(const float16_t * pSrc, float16_t * pDst, uint32_t blockSize);
50
51
52 /**
53 * @brief Fills a constant value into a floating-point vector.
54 * @param[in] value input value to be filled
55 * @param[out] pDst output pointer
56 * @param[in] blockSize number of samples to process
57 */
58 void arm_fill_f16(float16_t value, float16_t * pDst, uint32_t blockSize);
59
60
61 /**
62 * @brief Converts the elements of the floating-point vector to Q31 vector.
63 * @param[in] pSrc points to the f16 input vector
64 * @param[out] pDst points to the q15 output vector
65 * @param[in] blockSize length of the input vector
66 */
67 void arm_f16_to_q15(const float16_t * pSrc, q15_t * pDst, uint32_t blockSize);
68
69
70 /**
71 * @brief Converts the elements of the floating-point vector to Q31 vector.
72 * @param[in] pSrc points to the q15 input vector
73 * @param[out] pDst points to the f16 output vector
74 * @param[in] blockSize length of the input vector
75 */
76 void arm_q15_to_f16(const q15_t * pSrc, float16_t * pDst, uint32_t blockSize);
77
78
79 /**
80 * @brief Converts the elements of the 64 bit floating-point vector to 16 bit floating-point vector.
81 * @param[in] pSrc points to the f64 input vector
82 * @param[out] pDst points to the f16 output vector
83 * @param[in] blockSize length of the input vector
84 */
85 void arm_f64_to_f16(const float64_t * pSrc, float16_t * pDst, uint32_t blockSize);
86
87
88 /**
89 * @brief Converts the elements of the 16 bit floating-point vector to 64 bit floating-point vector.
90 * @param[in] pSrc points to the f16 input vector
91 * @param[out] pDst points to the f64 output vector
92 * @param[in] blockSize length of the input vector
93 */
94 void arm_f16_to_f64(const float16_t * pSrc, float64_t * pDst, uint32_t blockSize);
95
96
97 /**
98 * @brief Converts the elements of the floating-point vector to Q31 vector.
99 * @param[in] pSrc points to the f32 input vector
100 * @param[out] pDst points to the f16 output vector
101 * @param[in] blockSize length of the input vector
102 */
103 void arm_float_to_f16(const float32_t * pSrc, float16_t * pDst, uint32_t blockSize);
104
105
106 /**
107 * @brief Converts the elements of the floating-point vector to Q31 vector.
108 * @param[in] pSrc points to the f16 input vector
109 * @param[out] pDst points to the f32 output vector
110 * @param[in] blockSize length of the input vector
111 */
112 void arm_f16_to_float(const float16_t * pSrc, float32_t * pDst, uint32_t blockSize);
113
114
115 /**
116 * @brief Weighted average
117 * @param[in] *in Array of input values.
118 * @param[in] *weigths Weights
119 * @param[in] blockSize Number of samples in the input array.
120 * @return Weighted average
121 */
122 float16_t arm_weighted_average_f16(const float16_t *in
123 , const float16_t *weigths
124 , uint32_t blockSize);
125
126
127 /**
128 * @brief Barycenter
129 * @param[in] in List of vectors
130 * @param[in] weights Weights of the vectors
131 * @param[out] out Barycenter
132 * @param[in] nbVectors Number of vectors
133 * @param[in] vecDim Dimension of space (vector dimension)
134 */
135 void arm_barycenter_f16(const float16_t *in
136 , const float16_t *weights
137 , float16_t *out
138 , uint32_t nbVectors
139 , uint32_t vecDim);
140
141
142 /**
143 @ingroup groupSupport
144 */
145
146 /**
147 * @defgroup typecast Typecasting
148 */
149
150 /**
151 @addtogroup typecast
152 @{
153 */
154
155 /**
156 * @brief Interpret a f16 as an s16 value
157 * @param[in] x input value.
158 * @return return value.
159 *
160 * @par Description
161 * It is a typecast. No conversion of the float to int is done.
162 * The memcpy will be optimized out by the compiler.
163 * memcpy is used to prevent type punning issues.
164 * With gcc, -fno-builtins MUST not be used or the
165 * memcpy will not be optimized out.
166 */
arm_typecast_s16_f16(float16_t x)167 __STATIC_INLINE int16_t arm_typecast_s16_f16(float16_t x)
168 {
169 int16_t res;
170 res=*(int16_t*)memcpy((char*)&res,(char*)&x,sizeof(float16_t));
171 return(res);
172 }
173
174 /**
175 * @brief Interpret an s16 as an f16 value
176 * @param[in] x input value.
177 * @return return value.
178 *
179 * @par Description
180 * It is a typecast. No conversion of the int to float is done.
181 * The memcpy will be optimized out by the compiler.
182 * memcpy is used to prevent type punning issues.
183 * With gcc, -fno-builtins MUST not be used or the
184 * memcpy will not be optimized out.
185 */
arm_typecast_f16_s16(int16_t x)186 __STATIC_INLINE float16_t arm_typecast_f16_s16(int16_t x)
187 {
188 float16_t res;
189 res=*(float16_t*)memcpy((char*)&res,(char*)&x,sizeof(int16_t));
190 return(res);
191 }
192
193
194 /**
195 @} end of typecast group
196 */
197
198
199 #endif /*defined(ARM_FLOAT16_SUPPORTED)*/
200 #ifdef __cplusplus
201 }
202 #endif
203
204 #endif /* ifndef _SUPPORT_FUNCTIONS_F16_H_ */
205