This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

C2000 unroll loop to execute a fast sum



Hello.

I'm using C28x and Code Composer.

I want to extract a sum from an array of 20 Uint16 as fast as possible.

If I write the code

Uint16 SUM(Uint16* array) {

 

 

Uint16 sum; Uint16 index;

for(index=0;index<20;index++) sum = array[index];

return (sum);}

the dsp spent more time to execute the loop.

If I write

Uint16 SUM(Uint16 *array) {

Uint16 sum;

sum+=*array++;

 

sum+=*array++;

... (20-times)...

return (sum);}

The dsp spent about 20 instructions but the C-code is longer.

Is there a way to use for-loop and tell the compiler to unroll the loop ?

Thankyou in advice