* @brief Function to Calculates 1/in(reciprocal) value of Q15 Data type. */
| 545 | * @brief Function to Calculates 1/in(reciprocal) value of Q15 Data type. |
| 546 | */ |
| 547 | __STATIC_INLINE uint32_t arm_recip_q15( |
| 548 | q15_t in, |
| 549 | q15_t * dst, |
| 550 | q15_t * pRecipTable) |
| 551 | { |
| 552 | |
| 553 | uint32_t out = 0, tempVal = 0; |
| 554 | uint32_t index = 0, i = 0; |
| 555 | uint32_t signBits = 0; |
| 556 | |
| 557 | if(in > 0) |
| 558 | { |
| 559 | signBits = __CLZ(in) - 17; |
| 560 | } |
| 561 | else |
| 562 | { |
| 563 | signBits = __CLZ(-in) - 17; |
| 564 | } |
| 565 | |
| 566 | /* Convert input sample to 1.15 format */ |
| 567 | in = in << signBits; |
| 568 | |
| 569 | /* calculation of index for initial approximated Val */ |
| 570 | index = in >> 8; |
| 571 | index = (index & INDEX_MASK); |
| 572 | |
| 573 | /* 1.15 with exp 1 */ |
| 574 | out = pRecipTable[index]; |
| 575 | |
| 576 | /* calculation of reciprocal value */ |
| 577 | /* running approximation for two iterations */ |
| 578 | for (i = 0; i < 2; i++) |
| 579 | { |
| 580 | tempVal = (q15_t) (((q31_t) in * out) >> 15); |
| 581 | tempVal = 0x7FFF - tempVal; |
| 582 | /* 1.15 with exp 1 */ |
| 583 | out = (q15_t) (((q31_t) out * tempVal) >> 14); |
| 584 | } |
| 585 | |
| 586 | /* write output */ |
| 587 | *dst = out; |
| 588 | |
| 589 | /* return num of signbits of out = 1/in value */ |
| 590 | return (signBits + 1); |
| 591 | |
| 592 | } |
| 593 | |
| 594 | |
| 595 | /* |