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