quadrilateralcowboy/sys/osx/misc/ftoi.patch

146 lines
4.2 KiB
Diff

Index: neo/idlib/math/Math.h
===================================================================
--- neo/idlib/math/Math.h (revision 1760)
+++ neo/idlib/math/Math.h (working copy)
@@ -776,6 +776,21 @@
m = ( i & ( ( 1 << IEEE_FLT_MANTISSA_BITS ) - 1 ) ) | ( 1 << IEEE_FLT_MANTISSA_BITS );
shift = e - IEEE_FLT_MANTISSA_BITS;
return ( ( ( ( m >> -shift ) | ( m << shift ) ) & ~( e >> 31 ) ) ^ s ) - s;
+//#elif defined( MACOS_X )
+#elif 0
+ double ret = __fctiw( f );
+ return *( reinterpret_cast<int *>( &ret ) + 1 );
+//#elif defined( MACOS_X )
+#elif 0
+ float c;
+ // c = __fsels( f, -0x1.0p+52, 0x1.0p+52 );
+ __asm__ ("fsel %0,%1,%2,%3"
+ /* outputs: */ : "=f" (c)
+ /* inputs: */ : "f" (f), "f" (-0x1.0p+52), "f" (0x1.0p+52));
+ float result = (f - c) + c;
+ if( f < result ) result -= 1.0;
+ int i = *reinterpret_cast<int *>( &f );
+ return ( i & ( ( 1 << IEEE_FLT_MANTISSA_BITS ) - 1 ) );
#else
return (int) f;
#endif
Index: neo/idlib/precompiled.h
===================================================================
--- neo/idlib/precompiled.h (revision 1760)
+++ neo/idlib/precompiled.h (working copy)
@@ -47,6 +47,10 @@
#endif /* _WIN32 */
+#if defined( MACOS_X )
+#include <ppc_intrinsics.h>
+#endif
+
//-----------------------------------------------------
#if !defined( _DEBUG ) && !defined( NDEBUG )
Index: neo/TestSIMD/math/Math.h
===================================================================
--- neo/TestSIMD/math/Math.h (revision 1760)
+++ neo/TestSIMD/math/Math.h (working copy)
@@ -143,6 +143,7 @@
static float Rint( float f ); // returns the nearest integer
static int Ftoi( float f ); // float to int conversion
static int FtoiFast( float f ); // fast float to int conversion but rounds to nearest
+ static unsigned int FtouiFast( float f ); // fast float to unsigned int conversion
static unsigned long Ftol( float f ); // float to long conversion
static unsigned long FtolFast( float ); // fast float to long conversion but rounds to nearest
@@ -673,11 +674,31 @@
__asm fld f
__asm fistp i
return i;
+//#elif defined( MACOS_X )
+#elif 0
+ int i, s, e, m, shift;
+ i = *reinterpret_cast<int *>( &f );
+ s = i >> IEEE_FLT_SIGN_BIT;
+ e = ( ( i >> IEEE_FLT_MANTISSA_BITS ) & ( ( 1 << IEEE_FLT_EXPONENT_BITS ) - 1 ) ) - IEEE_FLT_EXPONENT_BIAS;
+ m = ( i & ( ( 1 << IEEE_FLT_MANTISSA_BITS ) - 1 ) ) | ( 1 << IEEE_FLT_MANTISSA_BITS );
+ shift = e - IEEE_FLT_MANTISSA_BITS;
+ return ( ( ( ( m >> -shift ) | ( m << shift ) ) & ~( e >> 31 ) ) ^ s ) - s;
#else
return (int) f;
#endif
}
+ID_INLINE unsigned int idMath::FtouiFast( float f ) {
+#ifdef _WIN32
+ int i;
+ __asm fld f
+ __asm fistp i
+ return i;
+#else
+ return (unsigned int) f;
+#endif
+}
+
ID_INLINE unsigned long idMath::Ftol( float f ) {
return (unsigned long) f;
}
Index: neo/TestSIMD/math/Simd.cpp
===================================================================
--- neo/TestSIMD/math/Simd.cpp (revision 1760)
+++ neo/TestSIMD/math/Simd.cpp (working copy)
@@ -3886,6 +3886,35 @@
GetBest( start, end, bestClocks );
}
PrintClocks( " idAngles::ToMat3()", 1, bestClocks );
+
+ int j;
+ int tmp;
+
+ bestClocks = 0;
+ tst = rnd.CRandomFloat() * 5000.0f;
+ for ( i = 0; i < NUMTESTS; i++ ) {
+ StartRecordTime( start );
+ for ( j = 0; j < NUMTESTS; j++ ) {
+ tmp = idMath::FtoiFast( tst );
+ }
+ StopRecordTime( end );
+ GetBest( start, end, bestClocks );
+ tst = rnd.CRandomFloat() * 5000.0f;
+ }
+ PrintClocks( " idMath::FtoiFast()", NUMTESTS, bestClocks );
+
+ bestClocks = 0;
+ tst = rnd.CRandomFloat() * 5000.0f + 5000.0f;
+ for ( i = 0; i < NUMTESTS; i++ ) {
+ StartRecordTime( start );
+ for ( j = 0; j < NUMTESTS; j++ ) {
+ tmp = idMath::FtouiFast( tst );
+ }
+ StopRecordTime( end );
+ GetBest( start, end, bestClocks );
+ tst = rnd.CRandomFloat() * 5000.0f + 5000.0f;
+ }
+ PrintClocks( " idMath::FtouiFast()", NUMTESTS, bestClocks );
}
/*
@@ -3903,7 +3932,7 @@
p_generic = generic;
-#if 0
+#if 1
//patrick : running timing test
TIME_TYPE s1,s2, best;
best = 0;
@@ -3967,8 +3996,9 @@
idLib::common->Printf( "using %s for SIMD processing\n", p_simd->GetName() );
GetBaseClocks();
-#if 1
TestMath();
+#if 0
+ TestMath();
TestAdd();
TestSub();
TestMul();