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