Code Optimization (for speed)?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Code Optimization (for speed)?

1,250 Views
GregM
Contributor I
Hi,

I'm using CW7.3 on the DSP56F805EVM board and I need my code to run as quickly as possible.

1) Will the code run faster if all variables are declared as signed rather than unsigned - or does the built is optimization correct these for the quickest possible operation?

2) Which will result in fewer instructions, a for( ; ; ) or a while(1)? In an un-optimized environment, the while(1) would result in a fetch from ROM, a compare & goto - whereas a for( ; ; ) would result in just a goto. Does the compiler optimize the while(1) correctly to just a goto?
(yes - I am stretching for clock cycles)

3) Can anyone provide me with more tips/tricks/techniques to code for speedy execution?

Code size is not a worry - it's the execution time I need to get down, whilst still coding in C.

Thanks for any assistance,

Greg
Labels (1)
Tags (1)
0 Kudos
Reply
1 Reply

311 Views
bobc
Contributor II
My main tip would be to turn on optimisation and look at the output of the compiler to see what code it generates. There is a lot of "folklore" around optimisation which either was true once but isn't now or never was true anyway. There are a lot of special cases which depend on the specific target and compiler implementation. It's best not to rely on second hand info or make assumptions about what the compiler will do.

I have never heard signed variables are faster, what makes you think that?

To look at the assembler output use the Debugger "mixed" view, or turn on the option to generate assembler.

Cheers


Message Edited by bobc on 2009-02-17 12:20 PM
0 Kudos
Reply