Collision Detection (Point-Polygon)

Member
Posts: 145
Joined: 2002.06
Post: #31
Quote:Originally posted by David
What is fmadds?
A PowerPC instruction that multiplies two floating point numbers and adds a third. It's faster than doing a fmuls (multiply) and fadds (add) separately

Quote:Is it slower to have a static float and use it every time the function is called or make a local float?
In theory a good compiler would do whatever is fastest in both cases. If you are going to use a local, make sure it's const (though a good compiler with auto-const it).

Quote:What does inlining a function do?
There's non-trivial overhead involved in any function call. Inlining avoids this by "inlining" the code of the function into the caller. It also allows the compiler to make optimizations in the called function specific to the call being replaced (such as replacing variables with constants).

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #32
Quote:Originally posted by inio
In theory a good compiler would do whatever is fastest in both cases. If you are going to use a local, make sure it's const (though a good compiler with auto-const it).

In practice, a static variable will (almost?) always be slower, since the compiler will feel compelled to write to memory whatever value the variable has at the end of the function, where the value of a local can just be discarded. Yes, in theory a good compiler could tell whether writing to memory was necessary or not, but since there's an explicit language flag 'static' to do that, I'd guess it's not a common optimization for compilers to perform. GCC certainly generates more code for the static case than the non-static.
Quote this message in a reply
Member
Posts: 145
Joined: 2002.06
Post: #33
Quote:Originally posted by OneSadCookie
In practice, a static variable will (almost?) always be slower, since the compiler will feel compelled to write to memory whatever value the variable has at the end of the function, where the value of a local can just be discarded. Yes, in theory a good compiler could tell whether writing to memory was necessary or not, but since there's an explicit language flag 'static' to do that, I'd guess it's not a common optimization for compilers to perform. GCC certainly generates more code for the static case than the non-static.


Oops, I misread static as const. And I didn't read his question closely enough

I thought the question was:
Code:
const float foo=2.73;
int Thinger(float blah) {
return foo+blah;
}
vs.
Code:
int Thingier(float blah) {
float foo=2.73;
return foo+blah;
}
if you use foo multiple times in a function, these will be faster than inlining the value in each statement. However, these should generate equivelant code as all FP constants have to be stored as const globals (vs. small integer constants, which can be stored in the instruction stream).

"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat

Bring Alistair Cooke's America to DVD!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Polygon budgets Kerome 1 2,750 Mar 7, 2010 04:55 AM
Last Post: mikey
  glut polygon winding strangeness OptimisticMonkey 2 2,890 Sep 7, 2009 06:27 PM
Last Post: OptimisticMonkey
  2D Pixel Collision Detection using OCCLUSION Elphaba 0 3,205 Jun 8, 2009 06:30 AM
Last Post: Elphaba
  the best way to do collision detection ghettotek 26 9,935 Jun 4, 2009 02:30 PM
Last Post: AnotherJake
  Getting the Normal for a polygon. Jaden 3 5,497 May 1, 2009 01:47 PM
Last Post: Nosredna