1 /******************************************************************************
2  * @file     arm_math_types.h
3  * @brief    Public header file for CMSIS DSP Library
4  * @version  V1.9.0
5  * @date     23 April 2021
6  * Target Processor: Cortex-M and Cortex-A cores
7  ******************************************************************************/
8 /*
9  * Copyright (c) 2010-2021 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 #ifndef _ARM_MATH_TYPES_H_
27 
28 #define _ARM_MATH_TYPES_H_
29 
30 #ifdef   __cplusplus
31 extern "C"
32 {
33 #endif
34 
35 /* Compiler specific diagnostic adjustment */
36 #if   defined ( __CC_ARM )
37 
38 #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
39 
40 #elif defined ( __GNUC__ )
41   #pragma GCC diagnostic push
42   #pragma GCC diagnostic ignored "-Wsign-conversion"
43   #pragma GCC diagnostic ignored "-Wconversion"
44   #pragma GCC diagnostic ignored "-Wunused-parameter"
45 
46 #elif defined ( __ICCARM__ )
47 
48 #elif defined ( __TI_ARM__ )
49 
50 #elif defined ( __CSMC__ )
51 
52 #elif defined ( __TASKING__ )
53 
54 #elif defined ( _MSC_VER )
55 
56 #else
57   #error Unknown compiler
58 #endif
59 
60 
61 /* Included for instrinsics definitions */
62 #if defined (_MSC_VER )
63 #include <stdint.h>
64 #define __STATIC_FORCEINLINE static __forceinline
65 #define __STATIC_INLINE static __inline
66 #define __ALIGNED(x) __declspec(align(x))
67 
68 #elif defined (__GNUC_PYTHON__)
69 #include <stdint.h>
70 #define  __ALIGNED(x) __attribute__((aligned(x)))
71 #define __STATIC_FORCEINLINE static inline __attribute__((always_inline))
72 #define __STATIC_INLINE static inline
73 
74 #else
75 #include "cmsis_compiler.h"
76 #endif
77 
78 
79 
80 #include <string.h>
81 #include <math.h>
82 #include <float.h>
83 #include <limits.h>
84 
85 /* evaluate ARM DSP feature */
86 #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1))
87   #define ARM_MATH_DSP                   1
88 #endif
89 
90 #if defined(ARM_MATH_NEON)
91 #include <arm_neon.h>
92 #if __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
93   #if !defined(ARM_MATH_NEON_FLOAT16)
94   #define ARM_MATH_NEON_FLOAT16
95   #endif
96 #endif
97 #endif
98 
99 #if !defined(ARM_MATH_AUTOVECTORIZE)
100 
101 #if __ARM_FEATURE_MVE
102   #if !defined(ARM_MATH_MVEI)
103     #define ARM_MATH_MVEI
104   #endif
105 #endif
106 
107 #if (__ARM_FEATURE_MVE & 2)
108   #if !defined(ARM_MATH_MVEF)
109     #define ARM_MATH_MVEF
110   #endif
111   #if !defined(ARM_MATH_MVE_FLOAT16)
112        #define ARM_MATH_MVE_FLOAT16
113   #endif
114 #endif
115 
116 #endif /*!defined(ARM_MATH_AUTOVECTORIZE)*/
117 
118 
119 #if defined (ARM_MATH_HELIUM)
120   #if !defined(ARM_MATH_MVEF)
121     #define ARM_MATH_MVEF
122   #endif
123 
124   #if !defined(ARM_MATH_MVEI)
125     #define ARM_MATH_MVEI
126   #endif
127 
128   #if !defined(ARM_MATH_MVE_FLOAT16)
129        #define ARM_MATH_MVE_FLOAT16
130   #endif
131 #endif
132 
133 
134 
135 #if   defined ( __CC_ARM )
136   /* Enter low optimization region - place directly above function definition */
137   #if defined( __ARM_ARCH_7EM__ )
138     #define LOW_OPTIMIZATION_ENTER \
139        _Pragma ("push")         \
140        _Pragma ("O1")
141   #else
142     #define LOW_OPTIMIZATION_ENTER
143   #endif
144 
145   /* Exit low optimization region - place directly after end of function definition */
146   #if defined ( __ARM_ARCH_7EM__ )
147     #define LOW_OPTIMIZATION_EXIT \
148        _Pragma ("pop")
149   #else
150     #define LOW_OPTIMIZATION_EXIT
151   #endif
152 
153   /* Enter low optimization region - place directly above function definition */
154   #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
155 
156   /* Exit low optimization region - place directly after end of function definition */
157   #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
158 
159 #elif defined (__ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
160   #define LOW_OPTIMIZATION_ENTER
161   #define LOW_OPTIMIZATION_EXIT
162   #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
163   #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
164 
165 #elif defined ( __GNUC__ )
166   #define LOW_OPTIMIZATION_ENTER \
167        __attribute__(( optimize("-O1") ))
168   #define LOW_OPTIMIZATION_EXIT
169   #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
170   #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
171 
172 #elif defined ( __ICCARM__ )
173   /* Enter low optimization region - place directly above function definition */
174   #if defined ( __ARM_ARCH_7EM__ )
175     #define LOW_OPTIMIZATION_ENTER \
176        _Pragma ("optimize=low")
177   #else
178     #define LOW_OPTIMIZATION_ENTER
179   #endif
180 
181   /* Exit low optimization region - place directly after end of function definition */
182   #define LOW_OPTIMIZATION_EXIT
183 
184   /* Enter low optimization region - place directly above function definition */
185   #if defined ( __ARM_ARCH_7EM__ )
186     #define IAR_ONLY_LOW_OPTIMIZATION_ENTER \
187        _Pragma ("optimize=low")
188   #else
189     #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
190   #endif
191 
192   /* Exit low optimization region - place directly after end of function definition */
193   #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
194 
195 #elif defined ( __TI_ARM__ )
196   #define LOW_OPTIMIZATION_ENTER
197   #define LOW_OPTIMIZATION_EXIT
198   #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
199   #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
200 
201 #elif defined ( __CSMC__ )
202   #define LOW_OPTIMIZATION_ENTER
203   #define LOW_OPTIMIZATION_EXIT
204   #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
205   #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
206 
207 #elif defined ( __TASKING__ )
208   #define LOW_OPTIMIZATION_ENTER
209   #define LOW_OPTIMIZATION_EXIT
210   #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
211   #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
212 
213 #elif defined ( _MSC_VER ) || defined(__GNUC_PYTHON__)
214       #define LOW_OPTIMIZATION_ENTER
215       #define LOW_OPTIMIZATION_EXIT
216       #define IAR_ONLY_LOW_OPTIMIZATION_ENTER
217       #define IAR_ONLY_LOW_OPTIMIZATION_EXIT
218 #endif
219 
220 
221 
222 /* Compiler specific diagnostic adjustment */
223 #if   defined ( __CC_ARM )
224 
225 #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 )
226 
227 #elif defined ( __GNUC__ )
228 #pragma GCC diagnostic pop
229 
230 #elif defined ( __ICCARM__ )
231 
232 #elif defined ( __TI_ARM__ )
233 
234 #elif defined ( __CSMC__ )
235 
236 #elif defined ( __TASKING__ )
237 
238 #elif defined ( _MSC_VER )
239 
240 #else
241   #error Unknown compiler
242 #endif
243 
244 #ifdef   __cplusplus
245 }
246 #endif
247 
248 #if __ARM_FEATURE_MVE
249 #include <arm_mve.h>
250 #endif
251 
252 #ifdef   __cplusplus
253 extern "C"
254 {
255 #endif
256 
257  /**
258    * @brief 8-bit fractional data type in 1.7 format.
259    */
260   typedef int8_t q7_t;
261 
262   /**
263    * @brief 16-bit fractional data type in 1.15 format.
264    */
265   typedef int16_t q15_t;
266 
267   /**
268    * @brief 32-bit fractional data type in 1.31 format.
269    */
270   typedef int32_t q31_t;
271 
272   /**
273    * @brief 64-bit fractional data type in 1.63 format.
274    */
275   typedef int64_t q63_t;
276 
277   /**
278    * @brief 32-bit floating-point type definition.
279    */
280   typedef float float32_t;
281 
282   /**
283    * @brief 64-bit floating-point type definition.
284    */
285   typedef double float64_t;
286 
287   /**
288    * @brief vector types
289    */
290 #if defined(ARM_MATH_NEON) || (defined (ARM_MATH_MVEI)  && !defined(ARM_MATH_AUTOVECTORIZE))
291   /**
292    * @brief 64-bit fractional 128-bit vector data type in 1.63 format
293    */
294   typedef int64x2_t q63x2_t;
295 
296   /**
297    * @brief 32-bit fractional 128-bit vector data type in 1.31 format.
298    */
299   typedef int32x4_t q31x4_t;
300 
301   /**
302    * @brief 16-bit fractional 128-bit vector data type with 16-bit alignment in 1.15 format.
303    */
304   typedef __ALIGNED(2) int16x8_t q15x8_t;
305 
306  /**
307    * @brief 8-bit fractional 128-bit vector data type with 8-bit alignment in 1.7 format.
308    */
309   typedef __ALIGNED(1) int8x16_t q7x16_t;
310 
311     /**
312    * @brief 32-bit fractional 128-bit vector pair data type in 1.31 format.
313    */
314   typedef int32x4x2_t q31x4x2_t;
315 
316   /**
317    * @brief 32-bit fractional 128-bit vector quadruplet data type in 1.31 format.
318    */
319   typedef int32x4x4_t q31x4x4_t;
320 
321   /**
322    * @brief 16-bit fractional 128-bit vector pair data type in 1.15 format.
323    */
324   typedef int16x8x2_t q15x8x2_t;
325 
326   /**
327    * @brief 16-bit fractional 128-bit vector quadruplet data type in 1.15 format.
328    */
329   typedef int16x8x4_t q15x8x4_t;
330 
331   /**
332    * @brief 8-bit fractional 128-bit vector pair data type in 1.7 format.
333    */
334   typedef int8x16x2_t q7x16x2_t;
335 
336   /**
337    * @brief 8-bit fractional 128-bit vector quadruplet data type in 1.7 format.
338    */
339    typedef int8x16x4_t q7x16x4_t;
340 
341   /**
342    * @brief 32-bit fractional data type in 9.23 format.
343    */
344   typedef int32_t q23_t;
345 
346   /**
347    * @brief 32-bit fractional 128-bit vector data type in 9.23 format.
348    */
349   typedef int32x4_t q23x4_t;
350 
351   /**
352    * @brief 64-bit status 128-bit vector data type.
353    */
354   typedef int64x2_t status64x2_t;
355 
356   /**
357    * @brief 32-bit status 128-bit vector data type.
358    */
359   typedef int32x4_t status32x4_t;
360 
361   /**
362    * @brief 16-bit status 128-bit vector data type.
363    */
364   typedef int16x8_t status16x8_t;
365 
366   /**
367    * @brief 8-bit status 128-bit vector data type.
368    */
369   typedef int8x16_t status8x16_t;
370 
371 
372 #endif
373 
374 #if defined(ARM_MATH_NEON) || (defined(ARM_MATH_MVEF)  && !defined(ARM_MATH_AUTOVECTORIZE)) /* floating point vector*/
375   /**
376    * @brief 32-bit floating-point 128-bit vector type
377    */
378   typedef float32x4_t f32x4_t;
379 
380   /**
381    * @brief 32-bit floating-point 128-bit vector pair data type
382    */
383   typedef float32x4x2_t f32x4x2_t;
384 
385   /**
386    * @brief 32-bit floating-point 128-bit vector quadruplet data type
387    */
388   typedef float32x4x4_t f32x4x4_t;
389 
390   /**
391    * @brief 32-bit ubiquitous 128-bit vector data type
392    */
393   typedef union _any32x4_t
394   {
395       float32x4_t     f;
396       int32x4_t       i;
397   } any32x4_t;
398 
399 #endif
400 
401 #if defined(ARM_MATH_NEON)
402   /**
403    * @brief 32-bit fractional 64-bit vector data type in 1.31 format.
404    */
405   typedef int32x2_t  q31x2_t;
406 
407   /**
408    * @brief 16-bit fractional 64-bit vector data type in 1.15 format.
409    */
410   typedef  __ALIGNED(2) int16x4_t q15x4_t;
411 
412   /**
413    * @brief 8-bit fractional 64-bit vector data type in 1.7 format.
414    */
415   typedef  __ALIGNED(1) int8x8_t q7x8_t;
416 
417   /**
418    * @brief 32-bit float 64-bit vector data type.
419    */
420   typedef float32x2_t  f32x2_t;
421 
422   /**
423    * @brief 32-bit floating-point 128-bit vector triplet data type
424    */
425   typedef float32x4x3_t f32x4x3_t;
426 
427 
428   /**
429    * @brief 32-bit fractional 128-bit vector triplet data type in 1.31 format
430    */
431   typedef int32x4x3_t q31x4x3_t;
432 
433   /**
434    * @brief 16-bit fractional 128-bit vector triplet data type in 1.15 format
435    */
436   typedef int16x8x3_t q15x8x3_t;
437 
438   /**
439    * @brief 8-bit fractional 128-bit vector triplet data type in 1.7 format
440    */
441   typedef int8x16x3_t q7x16x3_t;
442 
443   /**
444    * @brief 32-bit floating-point 64-bit vector pair data type
445    */
446   typedef float32x2x2_t f32x2x2_t;
447 
448   /**
449    * @brief 32-bit floating-point 64-bit vector triplet data type
450    */
451   typedef float32x2x3_t f32x2x3_t;
452 
453   /**
454    * @brief 32-bit floating-point 64-bit vector quadruplet data type
455    */
456   typedef float32x2x4_t f32x2x4_t;
457 
458 
459   /**
460    * @brief 32-bit fractional 64-bit vector pair data type in 1.31 format
461    */
462   typedef int32x2x2_t q31x2x2_t;
463 
464   /**
465    * @brief 32-bit fractional 64-bit vector triplet data type in 1.31 format
466    */
467   typedef int32x2x3_t q31x2x3_t;
468 
469   /**
470    * @brief 32-bit fractional 64-bit vector quadruplet data type in 1.31 format
471    */
472   typedef int32x4x3_t q31x2x4_t;
473 
474   /**
475    * @brief 16-bit fractional 64-bit vector pair data type in 1.15 format
476    */
477   typedef int16x4x2_t q15x4x2_t;
478 
479   /**
480    * @brief 16-bit fractional 64-bit vector triplet data type in 1.15 format
481    */
482   typedef int16x4x2_t q15x4x3_t;
483 
484   /**
485    * @brief 16-bit fractional 64-bit vector quadruplet data type in 1.15 format
486    */
487   typedef int16x4x3_t q15x4x4_t;
488 
489   /**
490    * @brief 8-bit fractional 64-bit vector pair data type in 1.7 format
491    */
492   typedef int8x8x2_t q7x8x2_t;
493 
494   /**
495    * @brief 8-bit fractional 64-bit vector triplet data type in 1.7 format
496    */
497   typedef int8x8x3_t q7x8x3_t;
498 
499   /**
500    * @brief 8-bit fractional 64-bit vector quadruplet data type in 1.7 format
501    */
502   typedef int8x8x4_t q7x8x4_t;
503 
504   /**
505    * @brief 32-bit ubiquitous 64-bit vector data type
506    */
507   typedef union _any32x2_t
508   {
509       float32x2_t     f;
510       int32x2_t       i;
511   } any32x2_t;
512 
513 
514   /**
515    * @brief 32-bit status 64-bit vector data type.
516    */
517   typedef int32x4_t status32x2_t;
518 
519   /**
520    * @brief 16-bit status 64-bit vector data type.
521    */
522   typedef int16x8_t status16x4_t;
523 
524   /**
525    * @brief 8-bit status 64-bit vector data type.
526    */
527   typedef int8x16_t status8x8_t;
528 
529 #endif
530 
531 
532 
533 
534 
535 #define F64_MAX   ((float64_t)DBL_MAX)
536 #define F32_MAX   ((float32_t)FLT_MAX)
537 
538 
539 
540 #define F64_MIN   (-DBL_MAX)
541 #define F32_MIN   (-FLT_MAX)
542 
543 
544 
545 #define F64_ABSMAX   ((float64_t)DBL_MAX)
546 #define F32_ABSMAX   ((float32_t)FLT_MAX)
547 
548 
549 
550 #define F64_ABSMIN   ((float64_t)0.0)
551 #define F32_ABSMIN   ((float32_t)0.0)
552 
553 
554 #define Q31_MAX   ((q31_t)(0x7FFFFFFFL))
555 #define Q15_MAX   ((q15_t)(0x7FFF))
556 #define Q7_MAX    ((q7_t)(0x7F))
557 #define Q31_MIN   ((q31_t)(0x80000000L))
558 #define Q15_MIN   ((q15_t)(0x8000))
559 #define Q7_MIN    ((q7_t)(0x80))
560 
561 #define Q31_ABSMAX   ((q31_t)(0x7FFFFFFFL))
562 #define Q15_ABSMAX   ((q15_t)(0x7FFF))
563 #define Q7_ABSMAX    ((q7_t)(0x7F))
564 #define Q31_ABSMIN   ((q31_t)0)
565 #define Q15_ABSMIN   ((q15_t)0)
566 #define Q7_ABSMIN    ((q7_t)0)
567 
568   /* Dimension C vector space */
569   #define CMPLX_DIM 2
570 
571   /**
572    * @brief Error status returned by some functions in the library.
573    */
574 
575   typedef enum
576   {
577     ARM_MATH_SUCCESS                 =  0,        /**< No error */
578     ARM_MATH_ARGUMENT_ERROR          = -1,        /**< One or more arguments are incorrect */
579     ARM_MATH_LENGTH_ERROR            = -2,        /**< Length of data buffer is incorrect */
580     ARM_MATH_SIZE_MISMATCH           = -3,        /**< Size of matrices is not compatible with the operation */
581     ARM_MATH_NANINF                  = -4,        /**< Not-a-number (NaN) or infinity is generated */
582     ARM_MATH_SINGULAR                = -5,        /**< Input matrix is singular and cannot be inverted */
583     ARM_MATH_TEST_FAILURE            = -6,        /**< Test Failed */
584     ARM_MATH_DECOMPOSITION_FAILURE   = -7         /**< Decomposition Failed */
585   } arm_status;
586 
587 
588 #ifdef   __cplusplus
589 }
590 #endif
591 
592 #endif /*ifndef _ARM_MATH_TYPES_H_ */
593