I'm trying to optimize this twiddle computing function:
void twiddle(int N)
{
int i;
for (i=0;i<N;i++)
{
twiddle_table[i].re = (float) cos((float)i * 2.0 * PI /(float)N);
twiddle_table[i].im = (float) - sin((float)i * 2.0 * PI /(float)N);
}
}
where N = 4096
size of twiddle table and could be bigger!
And then, I did the following:
void twiddle(int N)
{
int i;
float Tconst;
Tconst = 2.0 * PI /(float)N;
for (i=0;i<N;i++)
{
twiddle_table[i].re = (float) cos((float)i * Tconst);
twiddle_table[i].im = (float) - sin((float)i * Tconst);
}
}
But, I'm getting a performance of 340,000 cycles for the for
loop, which I think is bad.
Any hints that could enhance the performance of this function?
twiddle_table
defined? You didn't show all of your code. Also, what does340 000
cycles for the for loop mean, when we don't even know the value ofN
or the size of the twiddle_table? – Justin 12 hours agoTconst = 2.0 * PI /(float)N;
will be performed indouble
due to the2.0
to perform it infloat
, change the2.0
to2.0f
– user3629249 6 hours ago(float)i*Tconst
to assign afloat
variable, inside the top of thefor()
loop and use that variable in the actual calculations – user3629249 6 hours agotwiddle_table[]
– user3629249 6 hours ago