Page 1 of 1

Casting float to int, fast math operations on double/float

Posted: Tue Aug 19, 2008 8:25 pm
by Eke
I've seen ASM routines in cast.h which seems to quickly convert integer into floats and floats into integer: if I directly call these functions instead of doing a simple cast from the compiler like int x= (float) y, how much faster will it be ?

also, I use libsamplerate in my project and it requires LRINT and LRINTF functions to be set: everything compiles fine so I guess they are present in libmath but again, what the performance against the functions in cast.h ?

thanks


PS: libsamplerate also ask about CPU_CLIPS_NEGATIVE and CPU_CLIPS_POSITIVE flags, does the Gekko automatically clips value on negative/positive float to int conversion ?

Re: casting float to int

Posted: Wed Jan 28, 2009 9:37 am
by Eke
I've been recently informed about the bottleneck issues that could occur when using simple float/double to int cast on modern CPU that use pipelining and load&store scheme (like the Power PC)

Some interesting articles here:

http://www.mega-nerd.com/FPcast/
http://assemblyrequired.crashworks.org/ ... s-to-ints/


Any ideas about what I should use ? lrint from math.h or those functions in libogc/cast.h ?
Or is powerpc-gekko-gcc already able to get ride of this alone with optimization enabled ?


Secondly, what about the __FAST_MATH__ define in math.h, is it defined by default or do we have to somehow enable it in gcc ?

Any advices would be appreciated, thanks