--- libvorbis-1.2.0-original\lib\os.h Tue Jul 24 02:09:48 2007 +++ libvorbis-1.2.0\lib\os.h Tue May 20 10:39:06 2008 @@ -116,11 +116,22 @@ #endif +// Win32 implementation for Visual C++ (any others with this combination of flags?) #if defined(_WIN32) && !defined(__GNUC__) && !defined(__BORLANDC__) # define VORBIS_FPU_CONTROL typedef ogg_int16_t vorbis_fpu_control; +#ifdef _M_X64 + +// Special implementation for msvc x64 where inline asm doesn't work +#include +static int vorbis_ftoi(double f){ + return _mm_cvtss_si32(_mm_load_ss(&f)); +} + +#else + static __inline int vorbis_ftoi(double f){ int i; __asm{ @@ -130,6 +141,8 @@ return i; } +#endif + static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){ } @@ -144,7 +157,11 @@ typedef int vorbis_fpu_control; static int vorbis_ftoi(double f){ - return (int)(f+.5); + // Old implementation (only correct when no negative numbers encountered): + // return (int)(f+.5); + + // Proper but slower implementation (avoids branching for speed) + return (int)(fabs(f) + 0.5) * sgn(f); } /* We don't have special code for this compiler/arch, so do it the slow way */