Created
June 12, 2014 19:14
-
-
Save davidglezz/55efa6703ffd63030718 to your computer and use it in GitHub Desktop.
Fast Float to Int conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline int FastFtol(const float a) | |
{ | |
static int b; | |
#if defined(_MSVC) | |
__asm fld a | |
__asm fistp b | |
#elif defined(__GNUG__) | |
// use AT&T inline assembly style, document that | |
// we use memory as output (=m) and input (m) | |
__asm__ __volatile__ ( | |
"flds %1 \n\t" | |
"fistpl %0 \n\t" | |
: "=m" (b) | |
: "m" (a)); | |
#endif | |
return b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment