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