Uh oh!
There was an error while loading. Please reload this page.
[RFC]Math: Trignometry: Added cordic cos function - #4053
Conversation
458b5f3 to
81a0484Compare
cujomalainey
left a comment
There was a problem hiding this comment.
please address checkpatch comments, also im not sure if Johny has mentioned but we are seeing a performance regression with the new sign function that i think we need to figure out before we land this
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
ShriramShastry
commented
Apr 20, 2021
It seems exp_fixed function is consuming most of the computation time in 3 band DRC. CORDIC SINE when compared with old sine performs better #3990 (comment) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
paulstelian97
commented
Apr 20, 2021
Isn't it literally possible to do cos(x) = sin(pi/2 - x)? |
Yes, this is done by the during coordinate check pi/2. Variable xn and b_yn share
Yes , this is done during co-ordinate check. th_rad_fxp = sign * b_yn; for sine and th_rad_fxp = sign * xn for cosine. |
paulstelian97
commented
Apr 20, 2021
Guess that's a lot of common code then, we can factor out the common part into a single function to avoid code duplication. |
ShriramShastry
commented
Apr 20, 2021
Yes. That's correct, will make common function with a separator for sine and cosine. |
6042ff3 to
d5d1363CompareUh oh!
There was an error while loading. Please reload this page.
d5d1363 to
8e5ff14Compare
johnylin76
left a comment
There was a problem hiding this comment.
After testing on Eldrid (TGL board) I still found the time cost is more than the legacy one (non-cordic sine). I still think the burden is the for loop even if reduces from 32 to 16 fort 16bit.
Uh oh!
There was an error while loading. Please reload this page.
singalsu
left a comment
There was a problem hiding this comment.
Looks pretty good now, please address the int32_t conversion in drc sine function!
Uh oh!
There was an error while loading. Please reload this page.
johnylin76
commented
May 6, 2021
I used perf_tic/toc to simply measure the cost of one call of different sine functions (run on TGL). Here are the logger results: Legacy LUT sine: It does reveal that the cost of Cordic functions are larger than the legacy LUT one. |
johnylin76
commented
May 6, 2021
Here are the measured values: I consider that the absolute value of time might be inaccurate. It may contain the time spent on tracing or something else. |
b0c33c0 to
320b58fComparesingalsu
commented
May 7, 2021
@johnylin76 Thanks for doing measurements! It might be possible to get the cordic cycles to same level as LUT based with intrinsics. There's not really parallelization opportunities but the multiple, shift, saturate operations should get a speed up. Since the drop of iterations count didn't half the cycles the computation load is equally before/after it. Optimization is something e.g. I could do as patch later. What kind of schedule is preferred? |
singalsu
left a comment
There was a problem hiding this comment.
I think the flags should be changed, e.g. to enum.
Uh oh!
There was an error while loading. Please reload this page.
320b58f to
49ad0d2CompareUh oh!
There was an error while loading. Please reload this page.
paulstelian97
left a comment
There was a problem hiding this comment.
I assume by now the mathematical kinks of the function itself are solved (and thus we now know it's correct); the code itself looks good.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Cordic sin cos input value range is [-2*pi to 2*pi] and output range is [-1 to +1] This is common function to calculate trignometric sine and cosine using separate lookup table size for speeds and accuracy calculation. For 32bit sine and cosine Error (max = 0.000000011175871), THD+N = -170.152933 For 16bit sine and cosine Error (max = 0.000061), THD+N = -91.518584 Signed-off-by: ShriramShastry <malladi.sastry@intel.com>
singalsu
left a comment
There was a problem hiding this comment.
Looks good, thanks Sriram!
| inline int32_t drc_sin_fixed(int32_t x) | ||
| { | ||
| const int32_t PI_OVER_TWO = Q_CONVERT_FLOAT(1.57079632679489661923f, 30); | ||
| const int32_t PI_OVER_TWO = Q_CONVERT_FLOAT(1.57079632679489661923, 30); |
There was a problem hiding this comment.
These will only be inline if they are used in the same C file. @ShriramShastry can you do an incremental update that takes all these small inline maths function and moves them to the maths headers (and changes them to static inline).
This will save us a function call on all our small maths ops.
There was a problem hiding this comment.
Thanks Liam, Seppo. I have a new PR #4218 to include your inputs.
| */ | ||
| inline int32_t sin_fixed_32b(int32_t th_rad_fxp) | ||
| { | ||
| int32_t sign; |
There was a problem hiding this comment.
e.g. here, as this will generate 2 function calls when used outside of trig.c i.e.
- sin_fixed_32b()
- cordic_sin_cos()
We want to eliminate call 1.
Same for all the other small maths functions.
…ange is [-2pi to 2pi] and output range is [-1 to +1] Mean and maximum value for the difference between floating to fixed point output is 3.2136e-09 and 0.0000000596
Signed-off-by: ShriramShastry malladi.sastry@intel.com