code optimization ...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 21
Reputation: caltiger is an unknown quantity at this point 
Solved Threads: 0
caltiger caltiger is offline Offline
Newbie Poster

code optimization ...

 
0
  #1
Apr 27th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: code optimization ...

 
0
  #2
Apr 27th, 2007
Depends on what you're optimizing for. In general, it's fine to just use efficient algorithms and let the compiler do the nitty-gritty. It doesn't really matter how well you optimize something if you optimize the wrong part.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 539
Reputation: thekashyap will become famous soon enough thekashyap will become famous soon enough 
Solved Threads: 50
thekashyap's Avatar
thekashyap thekashyap is offline Offline
Posting Pro

Re: code optimization ...

 
0
  #3
Apr 27th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: code optimization ...

 
0
  #4
Apr 27th, 2007
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
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: code optimization ...

 
0
  #5
Apr 27th, 2007
Originally Posted by thekashyap View Post
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.
I've never heard of using unsigned being "optimized." How's that one work? The inline and register keywords are (anymore) just hints to the compiler, it'll usually do what it thinks is best unless you give it specific flags.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 21
Reputation: caltiger is an unknown quantity at this point 
Solved Threads: 0
caltiger caltiger is offline Offline
Newbie Poster

Re: code optimization ...

 
0
  #6
Apr 27th, 2007
I`ve seen this data caching in a number of places... wat exactly does that refer to..

does it mean creating and using lookup tables instead of making the compiler calculate n generate values??
Last edited by caltiger; Apr 27th, 2007 at 2:34 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 21
Reputation: caltiger is an unknown quantity at this point 
Solved Threads: 0
caltiger caltiger is offline Offline
Newbie Poster

Re: code optimization ...

 
0
  #7
Apr 27th, 2007
Originally Posted by Infarction View Post
I've never heard of using unsigned being "optimized." How's that one work? The inline and register keywords are (anymore) just hints to the compiler, it'll usually do what it thinks is best unless you give it specific flags.
exactly.. from wat i`ve heard unsigned takes more cycles than signed ...
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: code optimization ...

 
0
  #8
Apr 27th, 2007
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.

  1. int n
goes from -32767 to 32767, so, logically
  1. unsigned int n
goes from 0 to 65524... right?
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: code optimization ...

 
0
  #9
Apr 27th, 2007
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?
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 1,429
Reputation: Nichito is an unknown quantity at this point 
Solved Threads: 29
Featured Poster
Nichito's Avatar
Nichito Nichito is offline Offline
Nearly a Posting Virtuoso

Re: code optimization ...

 
0
  #10
Apr 27th, 2007
Originally Posted by caltiger View Post
exactly.. from wat i`ve heard unsigned takes more cycles than signed ...
its not that it takes more cycles (correct me if i'm wrong)... its just that an unsigned variable uses the memory that is not used innegative numbers in positive numbers... i.e.:

  1. int n
goes from [-32767,32767], and
  1. unsigned int n
goes from [0,65534]... right?
-->sometimes i wanna take my toaster in a bath<--
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC