| | |
code optimization ...
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2006
Posts: 21
Reputation:
Solved Threads: 0
Hi,
I have to port a code onto an ARM processor... what is the most commonly used methods for optimizing C code?
I`ve read abt limiting the number of parameters in a function, pass values by refernce in argunments rather than by value, and trying to avoid global variables...
My question is .. other than these commonly used techniques, are there any other techniques?
Thanks.
I have to port a code onto an ARM processor... what is the most commonly used methods for optimizing C code?
I`ve read abt limiting the number of parameters in a function, pass values by refernce in argunments rather than by value, and trying to avoid global variables...
My question is .. other than these commonly used techniques, are there any other techniques?
Thanks.
Of course.. let the machine do your job. 
Compilers provide options to generate optimized for a given hardware (it optimizes using the full instruction set of that hardware). I have no idea abt the ARM processor you mentioned but check your compiler's manual if it provides any option for it.
Of course almost every compiler support the generic optimization options. So those you can anyway use (these are platform independent).
Finally just 2 words of caution:
1. When you use optimization options you loose debug information. Suggest you also test your application in optimized form (if you are doing it in debug only so far).
2. Regarding the "commonly used techniques", I suggest you first find out what has to be optimized using some tools like Quantify, there is no point in spending time/effort to optimize a function that's called only 10 times in an hour. Sometimes removing a temporary variable in a small function helps performance because it's called 10000 times. So if you're using the "commonly used techniques" use it where it's needed.
Other things you can do:
- data caching
- using unsigned vars,
- use inline functions (new compilers do this implicitly though)
- use registers.
- Finally I hope you've had a look at what everyone else has said in this thread.

Compilers provide options to generate optimized for a given hardware (it optimizes using the full instruction set of that hardware). I have no idea abt the ARM processor you mentioned but check your compiler's manual if it provides any option for it.
Of course almost every compiler support the generic optimization options. So those you can anyway use (these are platform independent).
Finally just 2 words of caution:
1. When you use optimization options you loose debug information. Suggest you also test your application in optimized form (if you are doing it in debug only so far).
2. Regarding the "commonly used techniques", I suggest you first find out what has to be optimized using some tools like Quantify, there is no point in spending time/effort to optimize a function that's called only 10 times in an hour. Sometimes removing a temporary variable in a small function helps performance because it's called 10000 times. So if you're using the "commonly used techniques" use it where it's needed.
Other things you can do:
- data caching
- using unsigned vars,
- use inline functions (new compilers do this implicitly though)
- use registers.
- Finally I hope you've had a look at what everyone else has said in this thread.
besides, you should consider:
-- using the right type of variable, meaning, if yyou need to use decimal values in your program, if they're not too big, consider using float rather than double...
-- (where you can) using pointers instead of arrays, since it uses less memory
-- being specific and simple in your processes, meaning you develop in 10 lines of programming what, with another process working just the same, you could use 25.
-- cleaning useless information off the buffer
-- using struct arrays instead of single variable arrays where you can
and such things that may seem simple, but can optimize your memory usage
-- using the right type of variable, meaning, if yyou need to use decimal values in your program, if they're not too big, consider using float rather than double...
-- (where you can) using pointers instead of arrays, since it uses less memory
-- being specific and simple in your processes, meaning you develop in 10 lines of programming what, with another process working just the same, you could use 25.
-- cleaning useless information off the buffer
-- using struct arrays instead of single variable arrays where you can
and such things that may seem simple, but can optimize your memory usage
-->sometimes i wanna take my toaster in a bath<-- •
•
•
•
Other things you can do:
- data caching
- using unsigned vars,
- use inline functions (new compilers do this implicitly though)
- use registers.
- Finally I hope you've had a look at what everyone else has said in this thread.
•
•
Join Date: Sep 2006
Posts: 21
Reputation:
Solved Threads: 0
exactly.. from wat i`ve heard unsigned takes more cycles than signed ...
it's not that unsigned takes more cycles that signed 8correct me if i'm wrong), but the thing is that the space unsigned variables do not use in negative numbers is used in positive numbers... i.e.
goes from -32767 to 32767, so, logically goes from 0 to 65524... right?
c Syntax (Toggle Plain Text)
int n
c Syntax (Toggle Plain Text)
unsigned int n
-->sometimes i wanna take my toaster in a bath<-- Unsigned is no more optimized than signed; they're the exact same instructions for addition, multiplication, and division.
If you really want to optimize numerical code, use Fortran.
And before you optimize your code, ask if you really need to optimize anything.
And what are you optimizing for? Memory usage? Speed?
If you really want to optimize numerical code, use Fortran.
And before you optimize your code, ask if you really need to optimize anything.
And what are you optimizing for? Memory usage? Speed?
All my posts may be redistributed under the GNU Free Documentation License.
•
•
•
•
exactly.. from wat i`ve heard unsigned takes more cycles than signed ...
c Syntax (Toggle Plain Text)
int n
c Syntax (Toggle Plain Text)
unsigned int n
-->sometimes i wanna take my toaster in a bath<-- ![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: Hey, I got a very simple program here. Yet the compiler is disagreeing with me.
- Next Thread: String class
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






