Collision Detection (Point-Polygon)
Quote:Originally posted by DavidA PowerPC instruction that multiplies two floating point numbers and adds a third. It's faster than doing a fmuls (multiply) and fadds (add) separately
What is fmadds?
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: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: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;
}Code:
int Thingier(float blah) {
float foo=2.73;
return foo+blah;
}"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!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Polygon budgets | Kerome | 1 | 2,382 |
Mar 7, 2010 04:55 AM Last Post: mikey |
|
| 2D Pixel Collision Detection using OCCLUSION | Elphaba | 0 | 2,939 |
Jun 8, 2009 06:30 AM Last Post: Elphaba |
|
| the best way to do collision detection | ghettotek | 26 | 9,381 |
Jun 4, 2009 02:30 PM Last Post: AnotherJake |
|
| Getting the Normal for a polygon. | Jaden | 3 | 4,670 |
May 1, 2009 01:47 PM Last Post: Nosredna |
|
| Hierarchy, gluProject and collision detection | lemtoo | 3 | 4,171 |
Nov 30, 2007 09:26 AM Last Post: lemtoo |
|

