Use lrintf to fast convert floats to ints when possible

This commit is contained in:
Chris Robinson
2012-09-28 04:20:55 -07:00
parent 25ca179389
commit 825c5b5282
3 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -258,7 +258,7 @@ ENDIF()
CHECK_SYMBOL_EXISTS(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
CHECK_SYMBOL_EXISTS(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
CHECK_SYMBOL_EXISTS(powf math.h HAVE_POWF)
CHECK_SYMBOL_EXISTS(lrintf math.h HAVE_LRINTF)
CHECK_SYMBOL_EXISTS(powf math.h HAVE_POWF)
CHECK_SYMBOL_EXISTS(sqrtf math.h HAVE_SQRTF)
CHECK_SYMBOL_EXISTS(cosf math.h HAVE_COSF)
+5 -8
View File
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
#include <math.h>
#ifdef HAVE_FENV_H
#include <fenv.h>
@@ -406,19 +407,15 @@ static __inline ALuint NextPowerOf2(ALuint value)
* mode. */
static __inline ALint fastf2i(ALfloat f)
{
#ifdef HAVE_LRINTF
return lrintf(f);
#elif defined(_MSC_VER) && defined(_M_IX86)
ALint i;
#if defined(_MSC_VER) && defined(_M_IX86)
__asm fld f
__asm fistp i
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
__asm__ __volatile__("flds %1\n\t"
"fistpl %0\n\t"
: "=m" (i)
: "m" (f));
#else
i = (ALint)f;
return (ALint)f;
#endif
return i;
}
/* Fast float-to-uint conversion. Assumes the FPU is already in round-to-zero
+3
View File
@@ -67,6 +67,9 @@
/* Define if we have the stat function */
#cmakedefine HAVE_STAT
/* Define if we have the lrintf function */
#cmakedefine HAVE_LRINTF
/* Define if we have the powf function */
#cmakedefine HAVE_POWF