I have an application which performs a number of trig functions.
Is there a way to get faster trig functions in the MCUXPresso tool chain?
Below is a snip from the code.
sinr_cosp = 2.0 * (qMeas0 * qMeas1 + qMeas2 * qMeas3);
cosr_cosp = 1 - 2 *(qMeas1 * qMeas1 + qMeas2 * qMeas2);
r = (atan2(sinr_cosp, cosr_cosp)) * DegRad;
sinp = -2.0 * ((qMeas0 * qMeas2) - (qMeas3 * qMeas1)); //possible error. should be ((qMeas0 * qMeas2) - (qMeas2 * qMeas1)) 7Aug2021 negated
if(fabs(sinp) >= 1)
{
if (sinp < 0)
{
p = -(fabs(M_PI / 2)) * DegRad;
}
else
{
p = (fabs(M_PI / 2)) * DegRad;
} //p = copysign(M_PI / 2, sinp) * DegRad;
}
else
{
p = asin(sinp) * DegRad;
}
siny_cosp = 2.0 * (qMeas0 * qMeas3 + qMeas1 * qMeas2);
cosy_cosp = 1.0 - 2.0 * (qMeas2 * qMeas2 + qMeas3 * qMeas3);
y = (atan2(siny_cosp, cosy_cosp)) * DegRad;
This is running on a Kinetis KE04. When compiled using KDS, the above snip takes
1.6 msec to run, as measured using free-running counter captures before and after
the snip. I am porting to MCUXPresso, and this same sequence takes about two
times as long to run.
Again, is there a way to get faster trig functions in the MCUXPresso tool chain?
Andy.
Celeste,
I did the Accept as Solution incorrectly. My apologies!
Andy.
Celeste,
Thank you. I will work with the options you have sent. First I will look at optimizations to see whether I have missed anything there. Thank you for your help!
Andy.
Hello @andyvoss ,
Thanks for your post.
Strictly speaking about the different results between the two IDEs, they are unintended and difficult to avoid. This is because of the different build systems, potential difference between build flags used in manifest-based SDK packages vs ARM GCC packages (e.g. optimization levels), different C libraries etc. Most of the build process is controlled through the SDK manifest in the MCUXpresso IDE. Even for different versions of MCUXpresso, due to differences in compiler versions and optimization levels, their speed might be vary.
You can try to optimize the time by replacing the math library or adding the Angle Calculation component. The following two documents are provided for your reference:
CM0MLIBUG.pdf
UM11546, Angle calculation component user manual
Hope it can help you.
BRs,
Celeste
---------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the "ACCEPT AS SOLUTION" button. Thank you!
---------------------------------------------------------------------------------------------------------------