1 /****************************************************************************** 2 * @file basic_math_functions.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-2020 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 27 #ifndef _BASIC_MATH_FUNCTIONS_H_ 28 #define _BASIC_MATH_FUNCTIONS_H_ 29 30 #include "arm_math_types.h" 31 #include "arm_math_memory.h" 32 33 #include "dsp/none.h" 34 #include "dsp/utils.h" 35 36 37 #ifdef __cplusplus 38 extern "C" 39 { 40 #endif 41 42 /** 43 * @defgroup groupMath Basic Math Functions 44 */ 45 46 /** 47 * @brief Q7 vector multiplication. 48 * @param[in] pSrcA points to the first input vector 49 * @param[in] pSrcB points to the second input vector 50 * @param[out] pDst points to the output vector 51 * @param[in] blockSize number of samples in each vector 52 */ 53 void arm_mult_q7( 54 const q7_t * pSrcA, 55 const q7_t * pSrcB, 56 q7_t * pDst, 57 uint32_t blockSize); 58 59 60 /** 61 * @brief Q15 vector multiplication. 62 * @param[in] pSrcA points to the first input vector 63 * @param[in] pSrcB points to the second input vector 64 * @param[out] pDst points to the output vector 65 * @param[in] blockSize number of samples in each vector 66 */ 67 void arm_mult_q15( 68 const q15_t * pSrcA, 69 const q15_t * pSrcB, 70 q15_t * pDst, 71 uint32_t blockSize); 72 73 74 /** 75 * @brief Q31 vector multiplication. 76 * @param[in] pSrcA points to the first input vector 77 * @param[in] pSrcB points to the second input vector 78 * @param[out] pDst points to the output vector 79 * @param[in] blockSize number of samples in each vector 80 */ 81 void arm_mult_q31( 82 const q31_t * pSrcA, 83 const q31_t * pSrcB, 84 q31_t * pDst, 85 uint32_t blockSize); 86 87 88 /** 89 * @brief Floating-point vector multiplication. 90 * @param[in] pSrcA points to the first input vector 91 * @param[in] pSrcB points to the second input vector 92 * @param[out] pDst points to the output vector 93 * @param[in] blockSize number of samples in each vector 94 */ 95 void arm_mult_f32( 96 const float32_t * pSrcA, 97 const float32_t * pSrcB, 98 float32_t * pDst, 99 uint32_t blockSize); 100 101 102 103 /** 104 * @brief Floating-point vector addition. 105 * @param[in] pSrcA points to the first input vector 106 * @param[in] pSrcB points to the second input vector 107 * @param[out] pDst points to the output vector 108 * @param[in] blockSize number of samples in each vector 109 */ 110 void arm_add_f32( 111 const float32_t * pSrcA, 112 const float32_t * pSrcB, 113 float32_t * pDst, 114 uint32_t blockSize); 115 116 117 118 /** 119 * @brief Q7 vector addition. 120 * @param[in] pSrcA points to the first input vector 121 * @param[in] pSrcB points to the second input vector 122 * @param[out] pDst points to the output vector 123 * @param[in] blockSize number of samples in each vector 124 */ 125 void arm_add_q7( 126 const q7_t * pSrcA, 127 const q7_t * pSrcB, 128 q7_t * pDst, 129 uint32_t blockSize); 130 131 132 /** 133 * @brief Q15 vector addition. 134 * @param[in] pSrcA points to the first input vector 135 * @param[in] pSrcB points to the second input vector 136 * @param[out] pDst points to the output vector 137 * @param[in] blockSize number of samples in each vector 138 */ 139 void arm_add_q15( 140 const q15_t * pSrcA, 141 const q15_t * pSrcB, 142 q15_t * pDst, 143 uint32_t blockSize); 144 145 146 /** 147 * @brief Q31 vector addition. 148 * @param[in] pSrcA points to the first input vector 149 * @param[in] pSrcB points to the second input vector 150 * @param[out] pDst points to the output vector 151 * @param[in] blockSize number of samples in each vector 152 */ 153 void arm_add_q31( 154 const q31_t * pSrcA, 155 const q31_t * pSrcB, 156 q31_t * pDst, 157 uint32_t blockSize); 158 159 160 /** 161 * @brief Floating-point vector subtraction. 162 * @param[in] pSrcA points to the first input vector 163 * @param[in] pSrcB points to the second input vector 164 * @param[out] pDst points to the output vector 165 * @param[in] blockSize number of samples in each vector 166 */ 167 void arm_sub_f32( 168 const float32_t * pSrcA, 169 const float32_t * pSrcB, 170 float32_t * pDst, 171 uint32_t blockSize); 172 173 174 175 /** 176 * @brief Q7 vector subtraction. 177 * @param[in] pSrcA points to the first input vector 178 * @param[in] pSrcB points to the second input vector 179 * @param[out] pDst points to the output vector 180 * @param[in] blockSize number of samples in each vector 181 */ 182 void arm_sub_q7( 183 const q7_t * pSrcA, 184 const q7_t * pSrcB, 185 q7_t * pDst, 186 uint32_t blockSize); 187 188 189 /** 190 * @brief Q15 vector subtraction. 191 * @param[in] pSrcA points to the first input vector 192 * @param[in] pSrcB points to the second input vector 193 * @param[out] pDst points to the output vector 194 * @param[in] blockSize number of samples in each vector 195 */ 196 void arm_sub_q15( 197 const q15_t * pSrcA, 198 const q15_t * pSrcB, 199 q15_t * pDst, 200 uint32_t blockSize); 201 202 203 /** 204 * @brief Q31 vector subtraction. 205 * @param[in] pSrcA points to the first input vector 206 * @param[in] pSrcB points to the second input vector 207 * @param[out] pDst points to the output vector 208 * @param[in] blockSize number of samples in each vector 209 */ 210 void arm_sub_q31( 211 const q31_t * pSrcA, 212 const q31_t * pSrcB, 213 q31_t * pDst, 214 uint32_t blockSize); 215 216 217 /** 218 * @brief Multiplies a floating-point vector by a scalar. 219 * @param[in] pSrc points to the input vector 220 * @param[in] scale scale factor to be applied 221 * @param[out] pDst points to the output vector 222 * @param[in] blockSize number of samples in the vector 223 */ 224 void arm_scale_f32( 225 const float32_t * pSrc, 226 float32_t scale, 227 float32_t * pDst, 228 uint32_t blockSize); 229 230 231 232 /** 233 * @brief Multiplies a Q7 vector by a scalar. 234 * @param[in] pSrc points to the input vector 235 * @param[in] scaleFract fractional portion of the scale value 236 * @param[in] shift number of bits to shift the result by 237 * @param[out] pDst points to the output vector 238 * @param[in] blockSize number of samples in the vector 239 */ 240 void arm_scale_q7( 241 const q7_t * pSrc, 242 q7_t scaleFract, 243 int8_t shift, 244 q7_t * pDst, 245 uint32_t blockSize); 246 247 248 /** 249 * @brief Multiplies a Q15 vector by a scalar. 250 * @param[in] pSrc points to the input vector 251 * @param[in] scaleFract fractional portion of the scale value 252 * @param[in] shift number of bits to shift the result by 253 * @param[out] pDst points to the output vector 254 * @param[in] blockSize number of samples in the vector 255 */ 256 void arm_scale_q15( 257 const q15_t * pSrc, 258 q15_t scaleFract, 259 int8_t shift, 260 q15_t * pDst, 261 uint32_t blockSize); 262 263 264 /** 265 * @brief Multiplies a Q31 vector by a scalar. 266 * @param[in] pSrc points to the input vector 267 * @param[in] scaleFract fractional portion of the scale value 268 * @param[in] shift number of bits to shift the result by 269 * @param[out] pDst points to the output vector 270 * @param[in] blockSize number of samples in the vector 271 */ 272 void arm_scale_q31( 273 const q31_t * pSrc, 274 q31_t scaleFract, 275 int8_t shift, 276 q31_t * pDst, 277 uint32_t blockSize); 278 279 280 /** 281 * @brief Q7 vector absolute value. 282 * @param[in] pSrc points to the input buffer 283 * @param[out] pDst points to the output buffer 284 * @param[in] blockSize number of samples in each vector 285 */ 286 void arm_abs_q7( 287 const q7_t * pSrc, 288 q7_t * pDst, 289 uint32_t blockSize); 290 291 292 /** 293 * @brief Floating-point vector absolute value. 294 * @param[in] pSrc points to the input buffer 295 * @param[out] pDst points to the output buffer 296 * @param[in] blockSize number of samples in each vector 297 */ 298 void arm_abs_f32( 299 const float32_t * pSrc, 300 float32_t * pDst, 301 uint32_t blockSize); 302 303 304 305 306 /** 307 * @brief Q15 vector absolute value. 308 * @param[in] pSrc points to the input buffer 309 * @param[out] pDst points to the output buffer 310 * @param[in] blockSize number of samples in each vector 311 */ 312 void arm_abs_q15( 313 const q15_t * pSrc, 314 q15_t * pDst, 315 uint32_t blockSize); 316 317 318 /** 319 * @brief Q31 vector absolute value. 320 * @param[in] pSrc points to the input buffer 321 * @param[out] pDst points to the output buffer 322 * @param[in] blockSize number of samples in each vector 323 */ 324 void arm_abs_q31( 325 const q31_t * pSrc, 326 q31_t * pDst, 327 uint32_t blockSize); 328 329 330 /** 331 * @brief Dot product of floating-point vectors. 332 * @param[in] pSrcA points to the first input vector 333 * @param[in] pSrcB points to the second input vector 334 * @param[in] blockSize number of samples in each vector 335 * @param[out] result output result returned here 336 */ 337 void arm_dot_prod_f32( 338 const float32_t * pSrcA, 339 const float32_t * pSrcB, 340 uint32_t blockSize, 341 float32_t * result); 342 343 344 345 /** 346 * @brief Dot product of Q7 vectors. 347 * @param[in] pSrcA points to the first input vector 348 * @param[in] pSrcB points to the second input vector 349 * @param[in] blockSize number of samples in each vector 350 * @param[out] result output result returned here 351 */ 352 void arm_dot_prod_q7( 353 const q7_t * pSrcA, 354 const q7_t * pSrcB, 355 uint32_t blockSize, 356 q31_t * result); 357 358 359 /** 360 * @brief Dot product of Q15 vectors. 361 * @param[in] pSrcA points to the first input vector 362 * @param[in] pSrcB points to the second input vector 363 * @param[in] blockSize number of samples in each vector 364 * @param[out] result output result returned here 365 */ 366 void arm_dot_prod_q15( 367 const q15_t * pSrcA, 368 const q15_t * pSrcB, 369 uint32_t blockSize, 370 q63_t * result); 371 372 373 /** 374 * @brief Dot product of Q31 vectors. 375 * @param[in] pSrcA points to the first input vector 376 * @param[in] pSrcB points to the second input vector 377 * @param[in] blockSize number of samples in each vector 378 * @param[out] result output result returned here 379 */ 380 void arm_dot_prod_q31( 381 const q31_t * pSrcA, 382 const q31_t * pSrcB, 383 uint32_t blockSize, 384 q63_t * result); 385 386 387 /** 388 * @brief Shifts the elements of a Q7 vector a specified number of bits. 389 * @param[in] pSrc points to the input vector 390 * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right. 391 * @param[out] pDst points to the output vector 392 * @param[in] blockSize number of samples in the vector 393 */ 394 void arm_shift_q7( 395 const q7_t * pSrc, 396 int8_t shiftBits, 397 q7_t * pDst, 398 uint32_t blockSize); 399 400 401 /** 402 * @brief Shifts the elements of a Q15 vector a specified number of bits. 403 * @param[in] pSrc points to the input vector 404 * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right. 405 * @param[out] pDst points to the output vector 406 * @param[in] blockSize number of samples in the vector 407 */ 408 void arm_shift_q15( 409 const q15_t * pSrc, 410 int8_t shiftBits, 411 q15_t * pDst, 412 uint32_t blockSize); 413 414 415 /** 416 * @brief Shifts the elements of a Q31 vector a specified number of bits. 417 * @param[in] pSrc points to the input vector 418 * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right. 419 * @param[out] pDst points to the output vector 420 * @param[in] blockSize number of samples in the vector 421 */ 422 void arm_shift_q31( 423 const q31_t * pSrc, 424 int8_t shiftBits, 425 q31_t * pDst, 426 uint32_t blockSize); 427 428 429 /** 430 * @brief Adds a constant offset to a floating-point vector. 431 * @param[in] pSrc points to the input vector 432 * @param[in] offset is the offset to be added 433 * @param[out] pDst points to the output vector 434 * @param[in] blockSize number of samples in the vector 435 */ 436 void arm_offset_f32( 437 const float32_t * pSrc, 438 float32_t offset, 439 float32_t * pDst, 440 uint32_t blockSize); 441 442 443 444 /** 445 * @brief Adds a constant offset to a Q7 vector. 446 * @param[in] pSrc points to the input vector 447 * @param[in] offset is the offset to be added 448 * @param[out] pDst points to the output vector 449 * @param[in] blockSize number of samples in the vector 450 */ 451 void arm_offset_q7( 452 const q7_t * pSrc, 453 q7_t offset, 454 q7_t * pDst, 455 uint32_t blockSize); 456 457 458 /** 459 * @brief Adds a constant offset to a Q15 vector. 460 * @param[in] pSrc points to the input vector 461 * @param[in] offset is the offset to be added 462 * @param[out] pDst points to the output vector 463 * @param[in] blockSize number of samples in the vector 464 */ 465 void arm_offset_q15( 466 const q15_t * pSrc, 467 q15_t offset, 468 q15_t * pDst, 469 uint32_t blockSize); 470 471 472 /** 473 * @brief Adds a constant offset to a Q31 vector. 474 * @param[in] pSrc points to the input vector 475 * @param[in] offset is the offset to be added 476 * @param[out] pDst points to the output vector 477 * @param[in] blockSize number of samples in the vector 478 */ 479 void arm_offset_q31( 480 const q31_t * pSrc, 481 q31_t offset, 482 q31_t * pDst, 483 uint32_t blockSize); 484 485 486 /** 487 * @brief Negates the elements of a floating-point vector. 488 * @param[in] pSrc points to the input vector 489 * @param[out] pDst points to the output vector 490 * @param[in] blockSize number of samples in the vector 491 */ 492 void arm_negate_f32( 493 const float32_t * pSrc, 494 float32_t * pDst, 495 uint32_t blockSize); 496 497 498 /** 499 * @brief Negates the elements of a Q7 vector. 500 * @param[in] pSrc points to the input vector 501 * @param[out] pDst points to the output vector 502 * @param[in] blockSize number of samples in the vector 503 */ 504 void arm_negate_q7( 505 const q7_t * pSrc, 506 q7_t * pDst, 507 uint32_t blockSize); 508 509 510 /** 511 * @brief Negates the elements of a Q15 vector. 512 * @param[in] pSrc points to the input vector 513 * @param[out] pDst points to the output vector 514 * @param[in] blockSize number of samples in the vector 515 */ 516 void arm_negate_q15( 517 const q15_t * pSrc, 518 q15_t * pDst, 519 uint32_t blockSize); 520 521 522 /** 523 * @brief Negates the elements of a Q31 vector. 524 * @param[in] pSrc points to the input vector 525 * @param[out] pDst points to the output vector 526 * @param[in] blockSize number of samples in the vector 527 */ 528 void arm_negate_q31( 529 const q31_t * pSrc, 530 q31_t * pDst, 531 uint32_t blockSize); 532 533 /** 534 * @brief Compute the logical bitwise AND of two fixed-point vectors. 535 * @param[in] pSrcA points to input vector A 536 * @param[in] pSrcB points to input vector B 537 * @param[out] pDst points to output vector 538 * @param[in] blockSize number of samples in each vector 539 * @return none 540 */ 541 void arm_and_u16( 542 const uint16_t * pSrcA, 543 const uint16_t * pSrcB, 544 uint16_t * pDst, 545 uint32_t blockSize); 546 547 /** 548 * @brief Compute the logical bitwise AND of two fixed-point vectors. 549 * @param[in] pSrcA points to input vector A 550 * @param[in] pSrcB points to input vector B 551 * @param[out] pDst points to output vector 552 * @param[in] blockSize number of samples in each vector 553 * @return none 554 */ 555 void arm_and_u32( 556 const uint32_t * pSrcA, 557 const uint32_t * pSrcB, 558 uint32_t * pDst, 559 uint32_t blockSize); 560 561 /** 562 * @brief Compute the logical bitwise AND of two fixed-point vectors. 563 * @param[in] pSrcA points to input vector A 564 * @param[in] pSrcB points to input vector B 565 * @param[out] pDst points to output vector 566 * @param[in] blockSize number of samples in each vector 567 * @return none 568 */ 569 void arm_and_u8( 570 const uint8_t * pSrcA, 571 const uint8_t * pSrcB, 572 uint8_t * pDst, 573 uint32_t blockSize); 574 575 /** 576 * @brief Compute the logical bitwise OR of two fixed-point vectors. 577 * @param[in] pSrcA points to input vector A 578 * @param[in] pSrcB points to input vector B 579 * @param[out] pDst points to output vector 580 * @param[in] blockSize number of samples in each vector 581 * @return none 582 */ 583 void arm_or_u16( 584 const uint16_t * pSrcA, 585 const uint16_t * pSrcB, 586 uint16_t * pDst, 587 uint32_t blockSize); 588 589 /** 590 * @brief Compute the logical bitwise OR of two fixed-point vectors. 591 * @param[in] pSrcA points to input vector A 592 * @param[in] pSrcB points to input vector B 593 * @param[out] pDst points to output vector 594 * @param[in] blockSize number of samples in each vector 595 * @return none 596 */ 597 void arm_or_u32( 598 const uint32_t * pSrcA, 599 const uint32_t * pSrcB, 600 uint32_t * pDst, 601 uint32_t blockSize); 602 603 /** 604 * @brief Compute the logical bitwise OR of two fixed-point vectors. 605 * @param[in] pSrcA points to input vector A 606 * @param[in] pSrcB points to input vector B 607 * @param[out] pDst points to output vector 608 * @param[in] blockSize number of samples in each vector 609 * @return none 610 */ 611 void arm_or_u8( 612 const uint8_t * pSrcA, 613 const uint8_t * pSrcB, 614 uint8_t * pDst, 615 uint32_t blockSize); 616 617 /** 618 * @brief Compute the logical bitwise NOT of a fixed-point vector. 619 * @param[in] pSrc points to input vector 620 * @param[out] pDst points to output vector 621 * @param[in] blockSize number of samples in each vector 622 * @return none 623 */ 624 void arm_not_u16( 625 const uint16_t * pSrc, 626 uint16_t * pDst, 627 uint32_t blockSize); 628 629 /** 630 * @brief Compute the logical bitwise NOT of a fixed-point vector. 631 * @param[in] pSrc points to input vector 632 * @param[out] pDst points to output vector 633 * @param[in] blockSize number of samples in each vector 634 * @return none 635 */ 636 void arm_not_u32( 637 const uint32_t * pSrc, 638 uint32_t * pDst, 639 uint32_t blockSize); 640 641 /** 642 * @brief Compute the logical bitwise NOT of a fixed-point vector. 643 * @param[in] pSrc points to input vector 644 * @param[out] pDst points to output vector 645 * @param[in] blockSize number of samples in each vector 646 * @return none 647 */ 648 void arm_not_u8( 649 const uint8_t * pSrc, 650 uint8_t * pDst, 651 uint32_t blockSize); 652 653 /** 654 * @brief Compute the logical bitwise XOR of two fixed-point vectors. 655 * @param[in] pSrcA points to input vector A 656 * @param[in] pSrcB points to input vector B 657 * @param[out] pDst points to output vector 658 * @param[in] blockSize number of samples in each vector 659 * @return none 660 */ 661 void arm_xor_u16( 662 const uint16_t * pSrcA, 663 const uint16_t * pSrcB, 664 uint16_t * pDst, 665 uint32_t blockSize); 666 667 /** 668 * @brief Compute the logical bitwise XOR of two fixed-point vectors. 669 * @param[in] pSrcA points to input vector A 670 * @param[in] pSrcB points to input vector B 671 * @param[out] pDst points to output vector 672 * @param[in] blockSize number of samples in each vector 673 * @return none 674 */ 675 void arm_xor_u32( 676 const uint32_t * pSrcA, 677 const uint32_t * pSrcB, 678 uint32_t * pDst, 679 uint32_t blockSize); 680 681 /** 682 * @brief Compute the logical bitwise XOR of two fixed-point vectors. 683 * @param[in] pSrcA points to input vector A 684 * @param[in] pSrcB points to input vector B 685 * @param[out] pDst points to output vector 686 * @param[in] blockSize number of samples in each vector 687 * @return none 688 */ 689 void arm_xor_u8( 690 const uint8_t * pSrcA, 691 const uint8_t * pSrcB, 692 uint8_t * pDst, 693 uint32_t blockSize); 694 695 /** 696 @brief Elementwise floating-point clipping 697 @param[in] pSrc points to input values 698 @param[out] pDst points to output clipped values 699 @param[in] low lower bound 700 @param[in] high higher bound 701 @param[in] numSamples number of samples to clip 702 @return none 703 */ 704 705 void arm_clip_f32(const float32_t * pSrc, 706 float32_t * pDst, 707 float32_t low, 708 float32_t high, 709 uint32_t numSamples); 710 711 /** 712 @brief Elementwise fixed-point clipping 713 @param[in] pSrc points to input values 714 @param[out] pDst points to output clipped values 715 @param[in] low lower bound 716 @param[in] high higher bound 717 @param[in] numSamples number of samples to clip 718 @return none 719 */ 720 721 void arm_clip_q31(const q31_t * pSrc, 722 q31_t * pDst, 723 q31_t low, 724 q31_t high, 725 uint32_t numSamples); 726 727 /** 728 @brief Elementwise fixed-point clipping 729 @param[in] pSrc points to input values 730 @param[out] pDst points to output clipped values 731 @param[in] low lower bound 732 @param[in] high higher bound 733 @param[in] numSamples number of samples to clip 734 @return none 735 */ 736 737 void arm_clip_q15(const q15_t * pSrc, 738 q15_t * pDst, 739 q15_t low, 740 q15_t high, 741 uint32_t numSamples); 742 743 /** 744 @brief Elementwise fixed-point clipping 745 @param[in] pSrc points to input values 746 @param[out] pDst points to output clipped values 747 @param[in] low lower bound 748 @param[in] high higher bound 749 @param[in] numSamples number of samples to clip 750 @return none 751 */ 752 753 void arm_clip_q7(const q7_t * pSrc, 754 q7_t * pDst, 755 q7_t low, 756 q7_t high, 757 uint32_t numSamples); 758 759 760 #ifdef __cplusplus 761 } 762 #endif 763 764 #endif /* ifndef _BASIC_MATH_FUNCTIONS_H_ */ 765