ftoi.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. Index: neo/idlib/math/Math.h
  2. ===================================================================
  3. --- neo/idlib/math/Math.h (revision 1760)
  4. +++ neo/idlib/math/Math.h (working copy)
  5. @@ -776,6 +776,21 @@
  6. m = ( i & ( ( 1 << IEEE_FLT_MANTISSA_BITS ) - 1 ) ) | ( 1 << IEEE_FLT_MANTISSA_BITS );
  7. shift = e - IEEE_FLT_MANTISSA_BITS;
  8. return ( ( ( ( m >> -shift ) | ( m << shift ) ) & ~( e >> 31 ) ) ^ s ) - s;
  9. +//#elif defined( MACOS_X )
  10. +#elif 0
  11. + double ret = __fctiw( f );
  12. + return *( reinterpret_cast<int *>( &ret ) + 1 );
  13. +//#elif defined( MACOS_X )
  14. +#elif 0
  15. + float c;
  16. + // c = __fsels( f, -0x1.0p+52, 0x1.0p+52 );
  17. + __asm__ ("fsel %0,%1,%2,%3"
  18. + /* outputs: */ : "=f" (c)
  19. + /* inputs: */ : "f" (f), "f" (-0x1.0p+52), "f" (0x1.0p+52));
  20. + float result = (f - c) + c;
  21. + if( f < result ) result -= 1.0;
  22. + int i = *reinterpret_cast<int *>( &f );
  23. + return ( i & ( ( 1 << IEEE_FLT_MANTISSA_BITS ) - 1 ) );
  24. #else
  25. return (int) f;
  26. #endif
  27. Index: neo/idlib/precompiled.h
  28. ===================================================================
  29. --- neo/idlib/precompiled.h (revision 1760)
  30. +++ neo/idlib/precompiled.h (working copy)
  31. @@ -47,6 +47,10 @@
  32. #endif /* _WIN32 */
  33. +#if defined( MACOS_X )
  34. +#include <ppc_intrinsics.h>
  35. +#endif
  36. +
  37. //-----------------------------------------------------
  38. #if !defined( _DEBUG ) && !defined( NDEBUG )
  39. Index: neo/TestSIMD/math/Math.h
  40. ===================================================================
  41. --- neo/TestSIMD/math/Math.h (revision 1760)
  42. +++ neo/TestSIMD/math/Math.h (working copy)
  43. @@ -143,6 +143,7 @@
  44. static float Rint( float f ); // returns the nearest integer
  45. static int Ftoi( float f ); // float to int conversion
  46. static int FtoiFast( float f ); // fast float to int conversion but rounds to nearest
  47. + static unsigned int FtouiFast( float f ); // fast float to unsigned int conversion
  48. static unsigned long Ftol( float f ); // float to long conversion
  49. static unsigned long FtolFast( float ); // fast float to long conversion but rounds to nearest
  50. @@ -673,11 +674,31 @@
  51. __asm fld f
  52. __asm fistp i
  53. return i;
  54. +//#elif defined( MACOS_X )
  55. +#elif 0
  56. + int i, s, e, m, shift;
  57. + i = *reinterpret_cast<int *>( &f );
  58. + s = i >> IEEE_FLT_SIGN_BIT;
  59. + e = ( ( i >> IEEE_FLT_MANTISSA_BITS ) & ( ( 1 << IEEE_FLT_EXPONENT_BITS ) - 1 ) ) - IEEE_FLT_EXPONENT_BIAS;
  60. + m = ( i & ( ( 1 << IEEE_FLT_MANTISSA_BITS ) - 1 ) ) | ( 1 << IEEE_FLT_MANTISSA_BITS );
  61. + shift = e - IEEE_FLT_MANTISSA_BITS;
  62. + return ( ( ( ( m >> -shift ) | ( m << shift ) ) & ~( e >> 31 ) ) ^ s ) - s;
  63. #else
  64. return (int) f;
  65. #endif
  66. }
  67. +ID_INLINE unsigned int idMath::FtouiFast( float f ) {
  68. +#ifdef _WIN32
  69. + int i;
  70. + __asm fld f
  71. + __asm fistp i
  72. + return i;
  73. +#else
  74. + return (unsigned int) f;
  75. +#endif
  76. +}
  77. +
  78. ID_INLINE unsigned long idMath::Ftol( float f ) {
  79. return (unsigned long) f;
  80. }
  81. Index: neo/TestSIMD/math/Simd.cpp
  82. ===================================================================
  83. --- neo/TestSIMD/math/Simd.cpp (revision 1760)
  84. +++ neo/TestSIMD/math/Simd.cpp (working copy)
  85. @@ -3886,6 +3886,35 @@
  86. GetBest( start, end, bestClocks );
  87. }
  88. PrintClocks( " idAngles::ToMat3()", 1, bestClocks );
  89. +
  90. + int j;
  91. + int tmp;
  92. +
  93. + bestClocks = 0;
  94. + tst = rnd.CRandomFloat() * 5000.0f;
  95. + for ( i = 0; i < NUMTESTS; i++ ) {
  96. + StartRecordTime( start );
  97. + for ( j = 0; j < NUMTESTS; j++ ) {
  98. + tmp = idMath::FtoiFast( tst );
  99. + }
  100. + StopRecordTime( end );
  101. + GetBest( start, end, bestClocks );
  102. + tst = rnd.CRandomFloat() * 5000.0f;
  103. + }
  104. + PrintClocks( " idMath::FtoiFast()", NUMTESTS, bestClocks );
  105. +
  106. + bestClocks = 0;
  107. + tst = rnd.CRandomFloat() * 5000.0f + 5000.0f;
  108. + for ( i = 0; i < NUMTESTS; i++ ) {
  109. + StartRecordTime( start );
  110. + for ( j = 0; j < NUMTESTS; j++ ) {
  111. + tmp = idMath::FtouiFast( tst );
  112. + }
  113. + StopRecordTime( end );
  114. + GetBest( start, end, bestClocks );
  115. + tst = rnd.CRandomFloat() * 5000.0f + 5000.0f;
  116. + }
  117. + PrintClocks( " idMath::FtouiFast()", NUMTESTS, bestClocks );
  118. }
  119. /*
  120. @@ -3903,7 +3932,7 @@
  121. p_generic = generic;
  122. -#if 0
  123. +#if 1
  124. //patrick : running timing test
  125. TIME_TYPE s1,s2, best;
  126. best = 0;
  127. @@ -3967,8 +3996,9 @@
  128. idLib::common->Printf( "using %s for SIMD processing\n", p_simd->GetName() );
  129. GetBaseClocks();
  130. -#if 1
  131. TestMath();
  132. +#if 0
  133. + TestMath();
  134. TestAdd();
  135. TestSub();
  136. TestMul();