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 (__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 * @brief 8-bit fractional data type in 1.7 format. 287 */ 288 typedef int8_t q7_t; 289 290 /** 291 * @brief 16-bit fractional data type in 1.15 format. 292 */ 293 typedef int16_t q15_t; 294 295 /** 296 * @brief 32-bit fractional data type in 1.31 format. 297 */ 298 typedef int32_t q31_t; 299 300 /** 301 * @brief 64-bit fractional data type in 1.63 format. 302 */ 303 typedef int64_t q63_t; 304 305 /** 306 * @brief 32-bit floating-point type definition. 307 */ 308 #if !defined(__ICCARM__) || !(__ARM_FEATURE_MVE & 2) 309 typedef float float32_t; 310 #endif 311 312 /** 313 * @brief 64-bit floating-point type definition. 314 */ 315 typedef double float64_t; 316 317 /** 318 * @brief vector types 319 */ 320 #if defined(ARM_MATH_NEON) || (defined (ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)) 321 /** 322 * @brief 64-bit fractional 128-bit vector data type in 1.63 format 323 */ 324 typedef int64x2_t q63x2_t; 325 326 /** 327 * @brief 32-bit fractional 128-bit vector data type in 1.31 format. 328 */ 329 typedef int32x4_t q31x4_t; 330 331 /** 332 * @brief 16-bit fractional 128-bit vector data type with 16-bit alignment in 1.15 format. 333 */ 334 typedef __ALIGNED(2) int16x8_t q15x8_t; 335 336 /** 337 * @brief 8-bit fractional 128-bit vector data type with 8-bit alignment in 1.7 format. 338 */ 339 typedef __ALIGNED(1) int8x16_t q7x16_t; 340 341 /** 342 * @brief 32-bit fractional 128-bit vector pair data type in 1.31 format. 343 */ 344 typedef int32x4x2_t q31x4x2_t; 345 346 /** 347 * @brief 32-bit fractional 128-bit vector quadruplet data type in 1.31 format. 348 */ 349 typedef int32x4x4_t q31x4x4_t; 350 351 /** 352 * @brief 16-bit fractional 128-bit vector pair data type in 1.15 format. 353 */ 354 typedef int16x8x2_t q15x8x2_t; 355 356 /** 357 * @brief 16-bit fractional 128-bit vector quadruplet data type in 1.15 format. 358 */ 359 typedef int16x8x4_t q15x8x4_t; 360 361 /** 362 * @brief 8-bit fractional 128-bit vector pair data type in 1.7 format. 363 */ 364 typedef int8x16x2_t q7x16x2_t; 365 366 /** 367 * @brief 8-bit fractional 128-bit vector quadruplet data type in 1.7 format. 368 */ 369 typedef int8x16x4_t q7x16x4_t; 370 371 /** 372 * @brief 32-bit fractional data type in 9.23 format. 373 */ 374 typedef int32_t q23_t; 375 376 /** 377 * @brief 32-bit fractional 128-bit vector data type in 9.23 format. 378 */ 379 typedef int32x4_t q23x4_t; 380 381 /** 382 * @brief 64-bit status 128-bit vector data type. 383 */ 384 typedef int64x2_t status64x2_t; 385 386 /** 387 * @brief 32-bit status 128-bit vector data type. 388 */ 389 typedef int32x4_t status32x4_t; 390 391 /** 392 * @brief 16-bit status 128-bit vector data type. 393 */ 394 typedef int16x8_t status16x8_t; 395 396 /** 397 * @brief 8-bit status 128-bit vector data type. 398 */ 399 typedef int8x16_t status8x16_t; 400 401 402 #endif 403 404 #if defined(ARM_MATH_NEON) || (defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)) /* floating point vector*/ 405 /** 406 * @brief 32-bit floating-point 128-bit vector type 407 */ 408 typedef float32x4_t f32x4_t; 409 410 /** 411 * @brief 32-bit floating-point 128-bit vector pair data type 412 */ 413 typedef float32x4x2_t f32x4x2_t; 414 415 /** 416 * @brief 32-bit floating-point 128-bit vector quadruplet data type 417 */ 418 typedef float32x4x4_t f32x4x4_t; 419 420 /** 421 * @brief 32-bit ubiquitous 128-bit vector data type 422 */ 423 typedef union _any32x4_t 424 { 425 float32x4_t f; 426 int32x4_t i; 427 } any32x4_t; 428 429 #endif 430 431 #if defined(ARM_MATH_NEON) 432 /** 433 * @brief 32-bit fractional 64-bit vector data type in 1.31 format. 434 */ 435 typedef int32x2_t q31x2_t; 436 437 /** 438 * @brief 16-bit fractional 64-bit vector data type in 1.15 format. 439 */ 440 typedef __ALIGNED(2) int16x4_t q15x4_t; 441 442 /** 443 * @brief 8-bit fractional 64-bit vector data type in 1.7 format. 444 */ 445 typedef __ALIGNED(1) int8x8_t q7x8_t; 446 447 /** 448 * @brief 32-bit float 64-bit vector data type. 449 */ 450 typedef float32x2_t f32x2_t; 451 452 /** 453 * @brief 32-bit floating-point 128-bit vector triplet data type 454 */ 455 typedef float32x4x3_t f32x4x3_t; 456 457 458 /** 459 * @brief 32-bit fractional 128-bit vector triplet data type in 1.31 format 460 */ 461 typedef int32x4x3_t q31x4x3_t; 462 463 /** 464 * @brief 16-bit fractional 128-bit vector triplet data type in 1.15 format 465 */ 466 typedef int16x8x3_t q15x8x3_t; 467 468 /** 469 * @brief 8-bit fractional 128-bit vector triplet data type in 1.7 format 470 */ 471 typedef int8x16x3_t q7x16x3_t; 472 473 /** 474 * @brief 32-bit floating-point 64-bit vector pair data type 475 */ 476 typedef float32x2x2_t f32x2x2_t; 477 478 /** 479 * @brief 32-bit floating-point 64-bit vector triplet data type 480 */ 481 typedef float32x2x3_t f32x2x3_t; 482 483 /** 484 * @brief 32-bit floating-point 64-bit vector quadruplet data type 485 */ 486 typedef float32x2x4_t f32x2x4_t; 487 488 489 /** 490 * @brief 32-bit fractional 64-bit vector pair data type in 1.31 format 491 */ 492 typedef int32x2x2_t q31x2x2_t; 493 494 /** 495 * @brief 32-bit fractional 64-bit vector triplet data type in 1.31 format 496 */ 497 typedef int32x2x3_t q31x2x3_t; 498 499 /** 500 * @brief 32-bit fractional 64-bit vector quadruplet data type in 1.31 format 501 */ 502 typedef int32x4x3_t q31x2x4_t; 503 504 /** 505 * @brief 16-bit fractional 64-bit vector pair data type in 1.15 format 506 */ 507 typedef int16x4x2_t q15x4x2_t; 508 509 /** 510 * @brief 16-bit fractional 64-bit vector triplet data type in 1.15 format 511 */ 512 typedef int16x4x2_t q15x4x3_t; 513 514 /** 515 * @brief 16-bit fractional 64-bit vector quadruplet data type in 1.15 format 516 */ 517 typedef int16x4x3_t q15x4x4_t; 518 519 /** 520 * @brief 8-bit fractional 64-bit vector pair data type in 1.7 format 521 */ 522 typedef int8x8x2_t q7x8x2_t; 523 524 /** 525 * @brief 8-bit fractional 64-bit vector triplet data type in 1.7 format 526 */ 527 typedef int8x8x3_t q7x8x3_t; 528 529 /** 530 * @brief 8-bit fractional 64-bit vector quadruplet data type in 1.7 format 531 */ 532 typedef int8x8x4_t q7x8x4_t; 533 534 /** 535 * @brief 32-bit ubiquitous 64-bit vector data type 536 */ 537 typedef union _any32x2_t 538 { 539 float32x2_t f; 540 int32x2_t i; 541 } any32x2_t; 542 543 544 /** 545 * @brief 32-bit status 64-bit vector data type. 546 */ 547 typedef int32x4_t status32x2_t; 548 549 /** 550 * @brief 16-bit status 64-bit vector data type. 551 */ 552 typedef int16x8_t status16x4_t; 553 554 /** 555 * @brief 8-bit status 64-bit vector data type. 556 */ 557 typedef int8x16_t status8x8_t; 558 559 #endif 560 561 562 563 564 565 #define F64_MAX ((float64_t)DBL_MAX) 566 #define F32_MAX ((float32_t)FLT_MAX) 567 568 569 570 #define F64_MIN (-DBL_MAX) 571 #define F32_MIN (-FLT_MAX) 572 573 574 575 #define F64_ABSMAX ((float64_t)DBL_MAX) 576 #define F32_ABSMAX ((float32_t)FLT_MAX) 577 578 579 580 #define F64_ABSMIN ((float64_t)0.0) 581 #define F32_ABSMIN ((float32_t)0.0) 582 583 584 #define Q31_MAX ((q31_t)(0x7FFFFFFFL)) 585 #define Q15_MAX ((q15_t)(0x7FFF)) 586 #define Q7_MAX ((q7_t)(0x7F)) 587 #define Q31_MIN ((q31_t)(0x80000000L)) 588 #define Q15_MIN ((q15_t)(0x8000)) 589 #define Q7_MIN ((q7_t)(0x80)) 590 591 #define Q31_ABSMAX ((q31_t)(0x7FFFFFFFL)) 592 #define Q15_ABSMAX ((q15_t)(0x7FFF)) 593 #define Q7_ABSMAX ((q7_t)(0x7F)) 594 #define Q31_ABSMIN ((q31_t)0) 595 #define Q15_ABSMIN ((q15_t)0) 596 #define Q7_ABSMIN ((q7_t)0) 597 598 /* Dimension C vector space */ 599 #define CMPLX_DIM 2 600 601 /** 602 * @brief Error status returned by some functions in the library. 603 */ 604 605 typedef enum 606 { 607 ARM_MATH_SUCCESS = 0, /**< No error */ 608 ARM_MATH_ARGUMENT_ERROR = -1, /**< One or more arguments are incorrect */ 609 ARM_MATH_LENGTH_ERROR = -2, /**< Length of data buffer is incorrect */ 610 ARM_MATH_SIZE_MISMATCH = -3, /**< Size of matrices is not compatible with the operation */ 611 ARM_MATH_NANINF = -4, /**< Not-a-number (NaN) or infinity is generated */ 612 ARM_MATH_SINGULAR = -5, /**< Input matrix is singular and cannot be inverted */ 613 ARM_MATH_TEST_FAILURE = -6, /**< Test Failed */ 614 ARM_MATH_DECOMPOSITION_FAILURE = -7 /**< Decomposition Failed */ 615 } arm_status; 616 617 618 #ifdef __cplusplus 619 } 620 #endif 621 622 #endif /*ifndef _ARM_MATH_TYPES_H_ */ 623