Skip to content

Instantly share code, notes, and snippets.

@davidglezz
Created June 12, 2014 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidglezz/55efa6703ffd63030718 to your computer and use it in GitHub Desktop.
Save davidglezz/55efa6703ffd63030718 to your computer and use it in GitHub Desktop.
Fast Float to Int conversion
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