Skip to content

Commit c1e6730

Browse files
committed
perf: update ceil and floor to int functions
1 parent a8fd326 commit c1e6730

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/public/mathlib/mathlib.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,11 +1262,16 @@ inline int Floor2Int( float a )
12621262
{
12631263
int RetVal;
12641264
#if defined( PLATFORM_INTEL )
1265+
// Valve original
1266+
#if 0
12651267
// Convert to int and back, compare, subtract one if too big
12661268
__m128 a128 = _mm_set_ss(a);
12671269
RetVal = _mm_cvtss_si32(a128);
12681270
__m128 rounded128 = _mm_cvt_si2ss(_mm_setzero_ps(), RetVal);
12691271
RetVal -= _mm_comigt_ss( rounded128, a128 );
1272+
#else
1273+
RetVal = _mm_cvt_ss2si(_mm_set_ss(a + a - 0.5f)) >> 1;
1274+
#endif
12701275
#else
12711276
RetVal = static_cast<int>( floor(a) );
12721277
#endif
@@ -1319,11 +1324,16 @@ inline int Ceil2Int( float a )
13191324
{
13201325
int RetVal;
13211326
#if defined( PLATFORM_INTEL )
1327+
// Valve original
1328+
#if 0
13221329
// Convert to int and back, compare, add one if too small
13231330
__m128 a128 = _mm_load_ss(&a);
13241331
RetVal = _mm_cvtss_si32(a128);
13251332
__m128 rounded128 = _mm_cvt_si2ss(_mm_setzero_ps(), RetVal);
13261333
RetVal += _mm_comilt_ss( rounded128, a128 );
1334+
#else
1335+
RetVal = -(_mm_cvt_ss2si(_mm_set_ss(-0.5f - (a + a))) >> 1);
1336+
#endif
13271337
#else
13281338
RetVal = static_cast<int>( ceil(a) );
13291339
#endif

0 commit comments

Comments
 (0)