2023-12-06 12:26 AM
Hello,
In my application i need to run double for loop for data inside SRAM. and I would love to speed up my program as much as possible.
uint32_t xs = 0, yx = 0, sum =0, i = 0;
for(uint32_t x = 0 ; x<600 ; x++)
{
for(uint32_t y = 0 ; y<600 ; y++)
{
xs+=DATA[i]*x;
ys+=DATA[i]*y;
sum+=DATA[i];
i++;
}
}
Any insight into how I can make this faster ? Optimization is already at highest setting, and I am getting 33Hz loop speed with data acquisition.
Last resort is going into inline ASM somehow, just don't understand how do I know if compiler is using some particular CPU registers, that could hold registers longer.
2023-12-06 05:53 AM
You can also get a sense for how optimized a loop is by looking at the generated assembly code. Use that to guide how the code is written.
You can use a pointer to DATA instead of an index. Might save a little.
const uint32_t* ptr = &DATA[0];
...
xs += *ptr * x;
...
++ptr;
2023-12-06 01:22 PM
And try also :