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