Skip to content

Conversation

@ShriramShastry
Copy link
Contributor

…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

@ShriramShastry ShriramShastry force-pushed the shastry_cordiccos_dev branch 5 times, most recently from 458b5f3 to 81a0484 Compare April 19, 2021 14:07
@ShriramShastry ShriramShastry changed the title Math: Trignometry: Added cordic cos function Cordic cos input value r… [RFC]Math: Trignometry: Added cordic cos function Apr 19, 2021
Copy link
Contributor

@cujomalainey cujomalainey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ShriramShastry
Copy link
Contributor Author

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

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)

@paulstelian97
Copy link
Collaborator

Isn't it literally possible to do cos(x) = sin(pi/2 - x)?

@ShriramShastry
Copy link
Contributor Author

ShriramShastry 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

Isn't it literally possible to do cos(x) = sin(pi/2 - x)?

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
Copy link
Collaborator

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

Isn't it literally possible to do cos(x) = sin(pi/2 - x)?

Yes , this is done during co-ordinate check. th_rad_fxp = sign * b_yn; for sine and th_rad_fxp = sign * xn for cosine.

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
Copy link
Contributor Author

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

Isn't it literally possible to do cos(x) = sin(pi/2 - x)?

Yes , this is done during co-ordinate check. th_rad_fxp = sign * b_yn; for sine and th_rad_fxp = sign * xn for cosine.

Guess that's a lot of common code then, we can factor out the common part into a single function to avoid code duplication.

Yes. That's correct, will make common function with a separator for sine and cosine.

@ShriramShastry ShriramShastry force-pushed the shastry_cordiccos_dev branch 11 times, most recently from 6042ff3 to d5d1363 Compare April 21, 2021 02:00
@ShriramShastry ShriramShastry force-pushed the shastry_cordiccos_dev branch from d5d1363 to 8e5ff14 Compare April 21, 2021 07:15
@ShriramShastry ShriramShastry force-pushed the shastry_cordiccos_dev branch 5 times, most recently from 2a3b52b to 25395e0 Compare May 12, 2021 13:42
Copy link
Collaborator

@paulstelian97 paulstelian97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ShriramShastry ShriramShastry force-pushed the shastry_cordiccos_dev branch 5 times, most recently from 3bf1747 to e1b3ddd Compare May 12, 2021 17:37
@ShriramShastry ShriramShastry requested a review from singalsu May 13, 2021 01:54
@ShriramShastry ShriramShastry force-pushed the shastry_cordiccos_dev branch from e1b3ddd to cbd20c9 Compare May 14, 2021 12:04
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>
@ShriramShastry ShriramShastry force-pushed the shastry_cordiccos_dev branch from 324697a to d5e2273 Compare May 17, 2021 11:39
Copy link
Collaborator

@singalsu singalsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks Sriram!

@ShriramShastry ShriramShastry requested a review from singalsu May 17, 2021 12:25
Copy link
Collaborator

@singalsu singalsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approve, previous got cleared.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

@ShriramShastry ShriramShastry May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g. here, as this will generate 2 function calls when used outside of trig.c i.e.

  1. sin_fixed_32b()
  2. cordic_sin_cos()

We want to eliminate call 1.

Same for all the other small maths functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lgirdwood lgirdwood merged commit 845c278 into main May 19, 2021
@lgirdwood lgirdwood deleted the shastry_cordiccos_dev branch May 19, 2021 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants