Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411516 Posts in 69380 Topics- by 58436 Members - Latest Member: GlitchyPSI

May 01, 2024, 06:49:44 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Cheating template specialization
Pages: 1 [2]
Print
Author Topic: Cheating template specialization  (Read 3132 times)
John Nesky
Level 10
*****


aka shaktool


View Profile WWW
« Reply #20 on: April 19, 2010, 02:31:57 PM »

That's a valid point... but it's still an O(1) operation. Smiley Premature optimization and all that.
Logged
muku
Level 10
*****


View Profile
« Reply #21 on: April 19, 2010, 03:19:11 PM »

Semi-on-topic-ish remark: the standard C float-to-int cast is indeed a shockingly slow beast, which has historical reasons related to the C standard. It's very useful to know that there are ways to do this conversion about 10 times faster:

http://www.stereopsis.com/FPU.html#convert
http://mega-nerd.com/FPcast/

If you ever need to convert floats to ints in anything remotely performance sensitive, do yourself the favor and use one of those. I've seen dramatic increases in frames per seconds for certain pieces of code just by making use of these things.
Logged
drChengele
Level 2
**


if (status = UNDER_ATTACK) launch_nukes();


View Profile
« Reply #22 on: April 19, 2010, 03:33:04 PM »

Hey, that should come in really useful! Thanks!

[/derail]
Logged

Praetor
Currently working on : tactical battles.
Will Vale
Level 4
****



View Profile WWW
« Reply #23 on: April 19, 2010, 03:47:22 PM »

IIRC with MSVC the clue is if _ftol() shows up in your profile, you're being bitten by slow runtime library float->int conversions.

Screen coordinates for UI and sprites are a problem. You kind of want them in integers since you're talking about pixels, but (if you're using any graphics hardware) they'll have to be converted to floats to draw them eventually, so maybe it's better to store them in floats. Plus you might have a use for subpixel accuracy. I still don't have a rule of thumb I'm happy with for this Sad
Logged
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #24 on: April 19, 2010, 03:47:44 PM »

Semi-on-topic-ish remark: the standard C float-to-int cast is indeed a shockingly slow beast, which has historical reasons related to the C standard. It's very useful to know that there are ways to do this conversion about 10 times faster:

http://www.stereopsis.com/FPU.html#convert
http://mega-nerd.com/FPcast/

If you ever need to convert floats to ints in anything remotely performance sensitive, do yourself the favor and use one of those. I've seen dramatic increases in frames per seconds for certain pieces of code just by making use of these things.

Interesting.  I wonder if different architectures are better at it.  I would never make such an optimization, because I don't like to assume x86.
Logged



What would John Carmack do?
muku
Level 10
*****


View Profile
« Reply #25 on: April 19, 2010, 11:33:28 PM »

Interesting.  I wonder if different architectures are better at it.  I would never make such an optimization, because I don't like to assume x86.

There's also lrint and friends, which should do this kind of stuff portably (it was also mentioned in the second link, I think). As far as I know it's a C99 thing, so I'm not sure how well-supported it is, and whether it always gives the same speedup. Worth a try I guess.

Even if you don't want to limit yourself to x86, you could still use the preprocessor to disable these optimizations in the unlikely case that you're not on x86.
Logged
Average Software
Level 10
*****

Fleeing all W'rkncacnter


View Profile WWW
« Reply #26 on: April 20, 2010, 04:45:31 AM »

Interesting.  I wonder if different architectures are better at it.  I would never make such an optimization, because I don't like to assume x86.

There's also lrint and friends, which should do this kind of stuff portably (it was also mentioned in the second link, I think). As far as I know it's a C99 thing, so I'm not sure how well-supported it is, and whether it always gives the same speedup. Worth a try I guess.

Even if you don't want to limit yourself to x86, you could still use the preprocessor to disable these optimizations in the unlikely case that you're not on x86.

For me it's not unlikely, it's 100% certain, as I build Mac OS X universal binaries for PowerPC and x86.
Logged



What would John Carmack do?
Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic