From eb0b26cd8205da80eedfc4f252868a8a35dabe31 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Tue, 2 Jan 2007 23:36:44 +0000 Subject: [PATCH] Float to int is slow on ppc. It requires a store, a big stall, and then a load. It's even worse on a G5 if the compiler is dumb (and let's face it, I'm using gcc here...). Just use lroundf when we want an int. It will certainly be no slower. --- stepmania/src/BPMDisplay.cpp | 12 ++++++------ stepmania/src/BitmapText.cpp | 10 +++++----- stepmania/src/Font.cpp | 2 +- stepmania/src/NoteDataUtil.cpp | 6 +++--- stepmania/src/NotesLoaderKSF.cpp | 4 ++-- stepmania/src/NotesWriterDWI.cpp | 2 +- stepmania/src/OptionRow.cpp | 6 +++--- stepmania/src/PlayerOptions.cpp | 2 +- stepmania/src/RageDisplay_OGL.cpp | 4 ++-- stepmania/src/RageDisplay_OGL_Helpers.cpp | 2 +- stepmania/src/RageSurfaceUtils.cpp | 4 ++-- stepmania/src/ScreenEvaluation.cpp | 4 ++-- stepmania/src/ScreenNameEntry.cpp | 4 ++-- stepmania/src/SongOptions.cpp | 2 +- stepmania/src/Trail.cpp | 2 +- stepmania/src/Workout.cpp | 6 +++--- .../src/archutils/Darwin/DarwinThreadHelpers.cpp | 2 +- 17 files changed, 37 insertions(+), 37 deletions(-) diff --git a/stepmania/src/BPMDisplay.cpp b/stepmania/src/BPMDisplay.cpp index 49af662307..208cd9d0ca 100644 --- a/stepmania/src/BPMDisplay.cpp +++ b/stepmania/src/BPMDisplay.cpp @@ -100,23 +100,23 @@ void BPMDisplay::SetBPMRange( const DisplayBpms &bpms ) if( !(bool)CYCLE ) { - int MinBPM = INT_MAX; - int MaxBPM = INT_MIN; + long int MinBPM = INT_MAX; + long int MaxBPM = INT_MIN; for( unsigned i = 0; i < BPMS.size(); ++i ) { - MinBPM = min( MinBPM, (int) roundf(BPMS[i]) ); - MaxBPM = max( MaxBPM, (int) roundf(BPMS[i]) ); + MinBPM = min( MinBPM, lroundf(BPMS[i]) ); + MaxBPM = max( MaxBPM, lroundf(BPMS[i]) ); } if( MinBPM == MaxBPM ) { if( MinBPM == -1 ) SetText( "..." ); // random else - SetText( ssprintf("%i", MinBPM) ); + SetText( ssprintf("%ld", MinBPM) ); } else { - SetText( ssprintf("%i%s%i", MinBPM, SEPARATOR.GetValue().c_str(), MaxBPM) ); + SetText( ssprintf("%ld%s%ld", MinBPM, SEPARATOR.GetValue().c_str(), MaxBPM) ); } } else diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index f7d149fc78..88beebb6c0 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -191,7 +191,7 @@ void BitmapText::BuildChars() switch( m_VertAlign ) { case VertAlign_Top: iY = 0; break; - case VertAlign_Middle: iY = -(int)roundf(m_size.y/2.0f); break; + case VertAlign_Middle: iY = -lroundf(m_size.y/2.0f); break; case VertAlign_Bottom: iY = -(int)m_size.y; break; default: ASSERT( false ); } @@ -209,7 +209,7 @@ void BitmapText::BuildChars() switch( m_HorizAlign ) { case HorizAlign_Left: iX = 0; break; - case HorizAlign_Center: iX = -(int)roundf(iLineWidth/2.0f); break; + case HorizAlign_Center: iX = -lroundf(iLineWidth/2.0f); break; case HorizAlign_Right: iX = -iLineWidth; break; default: ASSERT( false ); } @@ -254,8 +254,8 @@ void BitmapText::DrawChars() return; const int iNumGlyphs = m_pTextures.size(); - int iStartGlyph = (int) roundf( SCALE( m_pTempState->crop.left, 0.f, 1.f, 0, (float) iNumGlyphs ) ); - int iEndGlyph = (int) roundf( SCALE( m_pTempState->crop.right, 0.f, 1.f, (float) iNumGlyphs, 0 ) ); + int iStartGlyph = lroundf( SCALE( m_pTempState->crop.left, 0.f, 1.f, 0, (float) iNumGlyphs ) ); + int iEndGlyph = lroundf( SCALE( m_pTempState->crop.right, 0.f, 1.f, (float) iNumGlyphs, 0 ) ); iStartGlyph = clamp( iStartGlyph, 0, iNumGlyphs ); iEndGlyph = clamp( iEndGlyph, 0, iNumGlyphs ); @@ -565,7 +565,7 @@ void BitmapText::DrawPrimitives() vector vGlyphJitter; if( m_bJitter ) { - int iSeed = (int)roundf( RageTimer::GetTimeSinceStartFast()*8 ); + int iSeed = lroundf( RageTimer::GetTimeSinceStartFast()*8 ); RandomGen rnd( iSeed ); for( unsigned i=0; iGetNumFrames(); i++ ) - aiFrameWidths[i] = int(roundf( aiFrameWidths[i] * cfg.m_fScaleAllWidthsBy )); + aiFrameWidths[i] = lroundf( aiFrameWidths[i] * cfg.m_fScaleAllWidthsBy ); } m_iCharToGlyphNo = cfg.CharToGlyphNo; diff --git a/stepmania/src/NoteDataUtil.cpp b/stepmania/src/NoteDataUtil.cpp index 3d91a6d07a..1e02caf5dc 100644 --- a/stepmania/src/NoteDataUtil.cpp +++ b/stepmania/src/NoteDataUtil.cpp @@ -20,7 +20,7 @@ NoteType NoteDataUtil::GetSmallestNoteTypeForMeasure( const NoteData &n, int iMe for( nt=(NoteType)0; ntTrace("from %f (%i) to (%i)", FromBeat, FromRow, ToRow); -// const int ToRow = (int) roundf(FromRow * song.m_Timing.m_BPMSegments[0].m_fBPM / song.m_BPMSegments[seg].m_fBPM); +// const int ToRow = lroundf(FromRow * song.m_Timing.m_BPMSegments[0].m_fBPM / song.m_BPMSegments[seg].m_fBPM); // const int Rows = out.GetLastRow() - FromRow + 1; // int LastRow; // if(seg+1 < song.m_Timing.m_BPMSegments().size()) @@ -46,7 +46,7 @@ void KSFLoader::RemoveHoles( NoteData &out, const Song &song ) if( tn == TAP_EMPTY ) continue; - const int RealRow = (int) roundf(row * OrigBPM / CurBPM); + const int RealRow = lroundf(row * OrigBPM / CurBPM); if( RealRow == row ) continue; LOG->Trace("from %i to %i", row, RealRow); diff --git a/stepmania/src/NotesWriterDWI.cpp b/stepmania/src/NotesWriterDWI.cpp index b6525a1e7c..477e9071ba 100644 --- a/stepmania/src/NotesWriterDWI.cpp +++ b/stepmania/src/NotesWriterDWI.cpp @@ -361,7 +361,7 @@ bool NotesWriterDWI::Write( RString sPath, const Song &out ) ASSERT( out.m_Timing.m_BPMSegments[0].m_iStartIndex == 0 ); f.PutLine( ssprintf("#FILE:%s;", DwiEscape(out.m_sMusicFile).c_str()) ); f.PutLine( ssprintf("#BPM:%.3f;", out.m_Timing.m_BPMSegments[0].GetBPM()) ); - f.PutLine( ssprintf("#GAP:%d;", int(-roundf( out.m_Timing.m_fBeat0OffsetInSeconds*1000 ))) ); + f.PutLine( ssprintf("#GAP:%ld;", -lroundf( out.m_Timing.m_fBeat0OffsetInSeconds*1000 )) ); f.PutLine( ssprintf("#SAMPLESTART:%.3f;", out.m_fMusicSampleStartSeconds) ); f.PutLine( ssprintf("#SAMPLELENGTH:%.3f;", out.m_fMusicSampleLengthSeconds) ); if( out.m_sCDTitleFile.size() ) diff --git a/stepmania/src/OptionRow.cpp b/stepmania/src/OptionRow.cpp index a731972c1a..f2b4642b86 100644 --- a/stepmania/src/OptionRow.cpp +++ b/stepmania/src/OptionRow.cpp @@ -704,9 +704,9 @@ void OptionRow::GetWidthXY( PlayerNumber pn, int iChoiceOnRow, int &iWidthOut, i { const BitmapText &text = GetTextItemForRow( pn, iChoiceOnRow ); - iWidthOut = int(roundf( text.GetZoomedWidth() )); - iXOut = int(roundf( text.GetDestX() )); - iYOut = int( roundf(m_Frame.GetDestY()) ); + iWidthOut = lroundf( text.GetZoomedWidth() ); + iXOut = lroundf( text.GetDestX() ); + iYOut = lroundf( m_Frame.GetDestY() ); } diff --git a/stepmania/src/PlayerOptions.cpp b/stepmania/src/PlayerOptions.cpp index 0593b1043d..7dde0655d3 100644 --- a/stepmania/src/PlayerOptions.cpp +++ b/stepmania/src/PlayerOptions.cpp @@ -71,7 +71,7 @@ static void AddPart( vector &AddTo, float level, RString name ) if( level == 0 ) return; - const RString LevelStr = (level == 1)? RString(""): ssprintf( "%i%% ", (int) roundf(level*100) ); + const RString LevelStr = (level == 1)? RString(""): ssprintf( "%ld%% ", lroundf(level*100) ); AddTo.push_back( LevelStr + name ); } diff --git a/stepmania/src/RageDisplay_OGL.cpp b/stepmania/src/RageDisplay_OGL.cpp index 6577b42b36..0ffb3e6857 100644 --- a/stepmania/src/RageDisplay_OGL.cpp +++ b/stepmania/src/RageDisplay_OGL.cpp @@ -528,10 +528,10 @@ static void CheckReversePackedPixels() void SetupExtensions() { const float fGLVersion = StringToFloat( (const char *) glGetString(GL_VERSION) ); - g_glVersion = int(roundf(fGLVersion * 10)); + g_glVersion = lroundf( fGLVersion * 10 ); const float fGLUVersion = StringToFloat( (const char *) gluGetString(GLU_VERSION) ); - g_gluVersion = int(roundf(fGLUVersion * 10)); + g_gluVersion = lroundf( fGLUVersion * 10 ); GLExt.Load( g_pWind ); diff --git a/stepmania/src/RageDisplay_OGL_Helpers.cpp b/stepmania/src/RageDisplay_OGL_Helpers.cpp index 28237acf4c..c68d8495b8 100644 --- a/stepmania/src/RageDisplay_OGL_Helpers.cpp +++ b/stepmania/src/RageDisplay_OGL_Helpers.cpp @@ -208,7 +208,7 @@ void GLExt_t::Load( LowLevelWindow *pWind ) else { const float fVersion = StringToFloat( pzVersion ); - m_iShadingLanguageVersion = int(roundf(fVersion * 100)); + m_iShadingLanguageVersion = lroundf( fVersion * 100 ); /* The version string may contain extra information beyond the version number. */ LOG->Info( "OpenGL shading language: %s", pzVersion ); } diff --git a/stepmania/src/RageSurfaceUtils.cpp b/stepmania/src/RageSurfaceUtils.cpp index 6cdc755607..18be46939f 100644 --- a/stepmania/src/RageSurfaceUtils.cpp +++ b/stepmania/src/RageSurfaceUtils.cpp @@ -876,13 +876,13 @@ RageSurface *RageSurfaceUtils::PalettizeToGrayscale( const RageSurface *src_surf if( Ivalues == 1 ) ScaledI = 255; // if only one intensity value, always fullbright else - ScaledI = clamp( int(roundf(I * (255.0f / (Ivalues-1)))), 0, 255 ); + ScaledI = clamp( lroundf(I * (255.0f / (Ivalues-1))), 0L, 255L ); int ScaledA; if( Avalues == 1 ) ScaledA = 255; // if only one alpha value, always opaque else - ScaledA = clamp( int(roundf(A * (255.0f / (Avalues-1)))), 0, 255 ); + ScaledA = clamp( lroundf(A * (255.0f / (Avalues-1))), 0L, 255L ); RageSurfaceColor c; c.r = uint8_t(ScaledI); diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index 0e2ecad199..3ccb1ccea8 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -559,8 +559,8 @@ void ScreenEvaluation::Init() RadarCategory_Jumps, RadarCategory_Holds, RadarCategory_Mines, RadarCategory_Hands, RadarCategory_Rolls }; const int ind = indeces[l]; - const int iActual = (int) roundf(STATSMAN->m_CurStageStats.m_player[p].m_radarActual[ind]); - const int iPossible = (int) roundf(STATSMAN->m_CurStageStats.m_player[p].m_radarPossible[ind]); + const int iActual = lroundf(STATSMAN->m_CurStageStats.m_player[p].m_radarActual[ind]); + const int iPossible = lroundf(STATSMAN->m_CurStageStats.m_player[p].m_radarPossible[ind]); m_textStatsText[l][p].SetText( ssprintf("%3d/%3d",iActual,iPossible) ); } diff --git a/stepmania/src/ScreenNameEntry.cpp b/stepmania/src/ScreenNameEntry.cpp index 1680096e7f..63a80ee75b 100644 --- a/stepmania/src/ScreenNameEntry.cpp +++ b/stepmania/src/ScreenNameEntry.cpp @@ -67,7 +67,7 @@ void ScreenNameEntry::ScrollingText::Init( const RString &sName, const vectorm_fSongBeat; - const size_t iClosestIndex = (int)roundf( fFakeBeat ) % g_sNameChars.size(); + const size_t iClosestIndex = lroundf( fFakeBeat ) % g_sNameChars.size(); const float fClosestYOffset = GetClosestCharYOffset( fFakeBeat ); size_t iCharIndex = ( iClosestIndex - NUM_CHARS_TO_DRAW_BEHIND + g_sNameChars.size() ) % g_sNameChars.size(); @@ -103,7 +103,7 @@ void ScreenNameEntry::ScrollingText::DrawPrimitives() char ScreenNameEntry::ScrollingText::GetClosestChar( float fFakeBeat ) const { ASSERT( fFakeBeat >= 0.f ); - return g_sNameChars[(size_t)roundf(fFakeBeat) % g_sNameChars.size()]; + return g_sNameChars[lroundf(fFakeBeat) % g_sNameChars.size()]; } // return value is relative to gray arrows diff --git a/stepmania/src/SongOptions.cpp b/stepmania/src/SongOptions.cpp index bef223415d..a69cdb53d7 100644 --- a/stepmania/src/SongOptions.cpp +++ b/stepmania/src/SongOptions.cpp @@ -43,7 +43,7 @@ static void AddPart( vector &AddTo, float level, RString name ) if( level == 0 ) return; - const RString LevelStr = (level == 1)? RString(""): ssprintf( "%i%% ", (int) roundf(level*100) ); + const RString LevelStr = (level == 1)? RString(""): ssprintf( "%ld%% ", lroundf(level*100) ); AddTo.push_back( LevelStr + name ); } diff --git a/stepmania/src/Trail.cpp b/stepmania/src/Trail.cpp index a98ff002d8..dcbf89bdf6 100644 --- a/stepmania/src/Trail.cpp +++ b/stepmania/src/Trail.cpp @@ -112,7 +112,7 @@ int Trail::GetMeter() const float fMeter = GetTotalMeter() / (float)m_vEntries.size(); - return (int)roundf( fMeter ); + return lroundf( fMeter ); } int Trail::GetTotalMeter() const diff --git a/stepmania/src/Workout.cpp b/stepmania/src/Workout.cpp index 4a98ea37a6..9f18ad60ab 100644 --- a/stepmania/src/Workout.cpp +++ b/stepmania/src/Workout.cpp @@ -69,7 +69,7 @@ static int CalculateWorkoutProgramMeter( WorkoutProgram wp, int iAverageMeter, i case WorkoutProgram_FatBurn: { float fMeter = SCALE( iSongInBodyIndex % 4, 0.0f, 3.0f, (float)iMinMeter, (float)iMaxMeter ); - iMeter = (int)roundf( fMeter ); + iMeter = lroundf( fMeter ); } break; case WorkoutProgram_FitnessTest: @@ -92,7 +92,7 @@ static int CalculateWorkoutProgramMeter( WorkoutProgram wp, int iAverageMeter, i break; case 4: case 5: - iMeter = (int) roundf( SCALE( 0.5f, 0.0f, 1.0f, (float)iMinMeter, (float)iMaxMeter ) ); + iMeter = lroundf( SCALE( 0.5f, 0.0f, 1.0f, (float)iMinMeter, (float)iMaxMeter ) ); break; } } @@ -107,7 +107,7 @@ static int CalculateWorkoutProgramMeter( WorkoutProgram wp, int iAverageMeter, i float fMeter = SCALE( iSongInBodyIndex % 4, 0.0f, 3.0f, (float)iMinMeter, (float)iMaxMeter ); if( (iSongInBodyIndex % 8) >= 4 ) fMeter = SCALE( fMeter, (float)iMinMeter, (float)iMaxMeter, (float)iMaxMeter, (float)iMinMeter ); - iMeter = (int)roundf( fMeter ); + iMeter = lroundf( fMeter ); } break; case WorkoutProgram_Flat: diff --git a/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp b/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp index 412436de43..16b9bd882e 100644 --- a/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp +++ b/stepmania/src/archutils/Darwin/DarwinThreadHelpers.cpp @@ -58,7 +58,7 @@ void SetThreadPrecedence( float prec ) // Real values are between 0 and 63. if( CLAMP(prec, 0.0f, 1.0f) ) LOG->Warn( "Thread precedence clamped to %f.", prec ); - thread_precedence_policy po = { integer_t( roundf(prec * 63) ) }; + thread_precedence_policy po = { integer_t( lroundf(prec * 63) ) }; kern_return_t ret = thread_policy_set( mach_thread_self(), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&po, THREAD_PRECEDENCE_POLICY_COUNT );