Better a DIV.F or Reciprocal SQRT (QSEED.F) squared ?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User19650
Level 1
Level 1
Hi All,

I have a piece of code which makes use of divisions. The fixed-point version was guaranteed to not cause exception, because of the data flow through the algorithm (still required commenting for QA).
The numerator and denominator come from ADC readings, so absolute precision is limited.

I'm moving the code to single-precision floating point on Aurix.
In this case, I see an option in replacing the division (DIV.F) with a multiplication by the square of the reciprocal sqrt, obtained by using QSEED.F, with a single Newton-Raphson iteration.

Theoretically - from the FPU timing table - the 2 options should have very similar latency, but the repeat rate could favour the reciprocal sqrt, which could be a factor, because there's more than one division to calculate.
Additionally, the "guaranteed no exception" would not need justification in this case.

Has anyone tried something similar ?

Is QSEED.F supported by compilers or should I get down writing assembly code to make use of it ?
0 Likes
4 Replies
NeMa_4793301
Level 6
Level 6
10 likes received 10 solutions authored 5 solutions authored
I don't believe the compilers emit qseed. There is a DSPLib library that has some functions that use qseed, as well as other hand-crafted assembly optimizations.

It's on MyICP here:
https://myicp.infineon.com/sites/microcontrollers-aurix_customer_doc/Lists/MyICP%20Customer%20Docume...
0 Likes
User13836
Level 6
Level 6
50 likes received 50 solutions authored 100 sign-ins
The TASKING C compiler won't generate the qseed.f instruction. But the sqrtf library function is using this instruction in the flavor using the hardware FPU (libcs_fpu.a). Here it's used in an inline assembly code sequence:

/* get reciprocal of the square root (6.75 bits accuracy) */
__asm(" QSEED.F %0,%1 \n": "=d" (xn):"d" (arg): );

Best regards,
Ulrich

TASKING tools support staff
0 Likes
User19650
Level 1
Level 1
Thx for the prompt reply.

That is my impression as well - been looking through Tasking libraries and there's no reciprocal sqrt entry there.
0 Likes
User19650
Level 1
Level 1
Thanks ulrichk.

That's useful.
0 Likes