MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / arm_recip_q31

Function arm_recip_q31

bsp/efm32/Libraries/CMSIS/Include/arm_math.h:496–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

494 */
495
496 __STATIC_INLINE uint32_t arm_recip_q31(
497 q31_t in,
498 q31_t * dst,
499 q31_t * pRecipTable)
500 {
501
502 uint32_t out, tempVal;
503 uint32_t index, i;
504 uint32_t signBits;
505
506 if(in > 0)
507 {
508 signBits = __CLZ(in) - 1;
509 }
510 else
511 {
512 signBits = __CLZ(-in) - 1;
513 }
514
515 /* Convert input sample to 1.31 format */
516 in = in << signBits;
517
518 /* calculation of index for initial approximated Val */
519 index = (uint32_t) (in >> 24u);
520 index = (index & INDEX_MASK);
521
522 /* 1.31 with exp 1 */
523 out = pRecipTable[index];
524
525 /* calculation of reciprocal value */
526 /* running approximation for two iterations */
527 for (i = 0u; i < 2u; i++)
528 {
529 tempVal = (q31_t) (((q63_t) in * out) >> 31u);
530 tempVal = 0x7FFFFFFF - tempVal;
531 /* 1.31 with exp 1 */
532 //out = (q31_t) (((q63_t) out * tempVal) >> 30u);
533 out = (q31_t) clip_q63_to_q31(((q63_t) out * tempVal) >> 30u);
534 }
535
536 /* write output */
537 *dst = out;
538
539 /* return num of signbits of out = 1/in value */
540 return (signBits + 1u);
541
542 }
543
544 /**
545 * @brief Function to Calculates 1/in(reciprocal) value of Q15 Data type.

Callers

nothing calls this directly

Calls 2

__CLZFunction · 0.70
clip_q63_to_q31Function · 0.70

Tested by

no test coverage detected