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.

This commit is contained in:
Steve Checkoway
2007-01-02 23:36:44 +00:00
parent 7a6eabd616
commit eb0b26cd82
17 changed files with 37 additions and 37 deletions
+6 -6
View File
@@ -100,23 +100,23 @@ void BPMDisplay::SetBPMRange( const DisplayBpms &bpms )
if( !(bool)CYCLE ) if( !(bool)CYCLE )
{ {
int MinBPM = INT_MAX; long int MinBPM = INT_MAX;
int MaxBPM = INT_MIN; long int MaxBPM = INT_MIN;
for( unsigned i = 0; i < BPMS.size(); ++i ) for( unsigned i = 0; i < BPMS.size(); ++i )
{ {
MinBPM = min( MinBPM, (int) roundf(BPMS[i]) ); MinBPM = min( MinBPM, lroundf(BPMS[i]) );
MaxBPM = max( MaxBPM, (int) roundf(BPMS[i]) ); MaxBPM = max( MaxBPM, lroundf(BPMS[i]) );
} }
if( MinBPM == MaxBPM ) if( MinBPM == MaxBPM )
{ {
if( MinBPM == -1 ) if( MinBPM == -1 )
SetText( "..." ); // random SetText( "..." ); // random
else else
SetText( ssprintf("%i", MinBPM) ); SetText( ssprintf("%ld", MinBPM) );
} }
else else
{ {
SetText( ssprintf("%i%s%i", MinBPM, SEPARATOR.GetValue().c_str(), MaxBPM) ); SetText( ssprintf("%ld%s%ld", MinBPM, SEPARATOR.GetValue().c_str(), MaxBPM) );
} }
} }
else else
+5 -5
View File
@@ -191,7 +191,7 @@ void BitmapText::BuildChars()
switch( m_VertAlign ) switch( m_VertAlign )
{ {
case VertAlign_Top: iY = 0; break; 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; case VertAlign_Bottom: iY = -(int)m_size.y; break;
default: ASSERT( false ); default: ASSERT( false );
} }
@@ -209,7 +209,7 @@ void BitmapText::BuildChars()
switch( m_HorizAlign ) switch( m_HorizAlign )
{ {
case HorizAlign_Left: iX = 0; break; 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; case HorizAlign_Right: iX = -iLineWidth; break;
default: ASSERT( false ); default: ASSERT( false );
} }
@@ -254,8 +254,8 @@ void BitmapText::DrawChars()
return; return;
const int iNumGlyphs = m_pTextures.size(); const int iNumGlyphs = m_pTextures.size();
int iStartGlyph = (int) roundf( SCALE( m_pTempState->crop.left, 0.f, 1.f, 0, (float) iNumGlyphs ) ); int iStartGlyph = lroundf( 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 iEndGlyph = lroundf( SCALE( m_pTempState->crop.right, 0.f, 1.f, (float) iNumGlyphs, 0 ) );
iStartGlyph = clamp( iStartGlyph, 0, iNumGlyphs ); iStartGlyph = clamp( iStartGlyph, 0, iNumGlyphs );
iEndGlyph = clamp( iEndGlyph, 0, iNumGlyphs ); iEndGlyph = clamp( iEndGlyph, 0, iNumGlyphs );
@@ -565,7 +565,7 @@ void BitmapText::DrawPrimitives()
vector<RageVector3> vGlyphJitter; vector<RageVector3> vGlyphJitter;
if( m_bJitter ) if( m_bJitter )
{ {
int iSeed = (int)roundf( RageTimer::GetTimeSinceStartFast()*8 ); int iSeed = lroundf( RageTimer::GetTimeSinceStartFast()*8 );
RandomGen rnd( iSeed ); RandomGen rnd( iSeed );
for( unsigned i=0; i<m_aVertices.size(); i+=4 ) for( unsigned i=0; i<m_aVertices.size(); i+=4 )
+1 -1
View File
@@ -56,7 +56,7 @@ void FontPage::Load( const FontPageSettings &cfg )
if( cfg.m_fScaleAllWidthsBy != 1 ) if( cfg.m_fScaleAllWidthsBy != 1 )
{ {
for( int i=0; i<m_pTexture->GetNumFrames(); i++ ) for( int i=0; i<m_pTexture->GetNumFrames(); i++ )
aiFrameWidths[i] = int(roundf( aiFrameWidths[i] * cfg.m_fScaleAllWidthsBy )); aiFrameWidths[i] = lroundf( aiFrameWidths[i] * cfg.m_fScaleAllWidthsBy );
} }
m_iCharToGlyphNo = cfg.CharToGlyphNo; m_iCharToGlyphNo = cfg.CharToGlyphNo;
+3 -3
View File
@@ -20,7 +20,7 @@ NoteType NoteDataUtil::GetSmallestNoteTypeForMeasure( const NoteData &n, int iMe
for( nt=(NoteType)0; nt<NUM_NoteType; nt=NoteType(nt+1) ) // for each NoteType, largest to largest for( nt=(NoteType)0; nt<NUM_NoteType; nt=NoteType(nt+1) ) // for each NoteType, largest to largest
{ {
float fBeatSpacing = NoteTypeToBeat( nt ); float fBeatSpacing = NoteTypeToBeat( nt );
int iRowSpacing = int(roundf( fBeatSpacing * ROWS_PER_BEAT )); int iRowSpacing = lroundf( fBeatSpacing * ROWS_PER_BEAT );
bool bFoundSmallerNote = false; bool bFoundSmallerNote = false;
// for each index in this measure // for each index in this measure
@@ -340,7 +340,7 @@ void NoteDataUtil::GetSMNoteDataString( const NoteData &in, RString &sRet )
if( nt == NoteType_Invalid ) if( nt == NoteType_Invalid )
iRowSpacing = 1; iRowSpacing = 1;
else else
iRowSpacing = int(roundf( NoteTypeToBeat(nt) * ROWS_PER_BEAT )); iRowSpacing = lroundf( NoteTypeToBeat(nt) * ROWS_PER_BEAT );
// (verify first) // (verify first)
// iRowSpacing = BeatToNoteRow( NoteTypeToBeat(nt) ); // iRowSpacing = BeatToNoteRow( NoteTypeToBeat(nt) );
@@ -1221,7 +1221,7 @@ void NoteDataUtil::Wide( NoteData &inout, int iStartIndex, int iEndIndex )
continue; // skip continue; // skip
// add a note determinitsitcally // add a note determinitsitcally
int iBeat = (int)roundf( NoteRowToBeat(i) ); int iBeat = lroundf( NoteRowToBeat(i) );
int iTrackOfNote = inout.GetFirstTrackWithTap(i); int iTrackOfNote = inout.GetFirstTrackWithTap(i);
int iTrackToAdd = iTrackOfNote + (iBeat%5)-2; // won't be more than 2 tracks away from the existing note int iTrackToAdd = iTrackOfNote + (iBeat%5)-2; // won't be more than 2 tracks away from the existing note
CLAMP( iTrackToAdd, 0, inout.GetNumTracks()-1 ); CLAMP( iTrackToAdd, 0, inout.GetNumTracks()-1 );
+2 -2
View File
@@ -21,7 +21,7 @@ void KSFLoader::RemoveHoles( NoteData &out, const Song &song )
const int ToRow = (int) BeatToNoteRow(song.m_Timing.m_BPMSegments[seg].m_fStartBeat); const int ToRow = (int) BeatToNoteRow(song.m_Timing.m_BPMSegments[seg].m_fStartBeat);
LOG->Trace("from %f (%i) to (%i)", FromBeat, FromRow, ToRow); LOG->Trace("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; // const int Rows = out.GetLastRow() - FromRow + 1;
// int LastRow; // int LastRow;
// if(seg+1 < song.m_Timing.m_BPMSegments().size()) // 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 ) if( tn == TAP_EMPTY )
continue; continue;
const int RealRow = (int) roundf(row * OrigBPM / CurBPM); const int RealRow = lroundf(row * OrigBPM / CurBPM);
if( RealRow == row ) if( RealRow == row )
continue; continue;
LOG->Trace("from %i to %i", row, RealRow); LOG->Trace("from %i to %i", row, RealRow);
+1 -1
View File
@@ -361,7 +361,7 @@ bool NotesWriterDWI::Write( RString sPath, const Song &out )
ASSERT( out.m_Timing.m_BPMSegments[0].m_iStartIndex == 0 ); ASSERT( out.m_Timing.m_BPMSegments[0].m_iStartIndex == 0 );
f.PutLine( ssprintf("#FILE:%s;", DwiEscape(out.m_sMusicFile).c_str()) ); 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("#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("#SAMPLESTART:%.3f;", out.m_fMusicSampleStartSeconds) );
f.PutLine( ssprintf("#SAMPLELENGTH:%.3f;", out.m_fMusicSampleLengthSeconds) ); f.PutLine( ssprintf("#SAMPLELENGTH:%.3f;", out.m_fMusicSampleLengthSeconds) );
if( out.m_sCDTitleFile.size() ) if( out.m_sCDTitleFile.size() )
+3 -3
View File
@@ -704,9 +704,9 @@ void OptionRow::GetWidthXY( PlayerNumber pn, int iChoiceOnRow, int &iWidthOut, i
{ {
const BitmapText &text = GetTextItemForRow( pn, iChoiceOnRow ); const BitmapText &text = GetTextItemForRow( pn, iChoiceOnRow );
iWidthOut = int(roundf( text.GetZoomedWidth() )); iWidthOut = lroundf( text.GetZoomedWidth() );
iXOut = int(roundf( text.GetDestX() )); iXOut = lroundf( text.GetDestX() );
iYOut = int( roundf(m_Frame.GetDestY()) ); iYOut = lroundf( m_Frame.GetDestY() );
} }
+1 -1
View File
@@ -71,7 +71,7 @@ static void AddPart( vector<RString> &AddTo, float level, RString name )
if( level == 0 ) if( level == 0 )
return; 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 ); AddTo.push_back( LevelStr + name );
} }
+2 -2
View File
@@ -528,10 +528,10 @@ static void CheckReversePackedPixels()
void SetupExtensions() void SetupExtensions()
{ {
const float fGLVersion = StringToFloat( (const char *) glGetString(GL_VERSION) ); 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) ); const float fGLUVersion = StringToFloat( (const char *) gluGetString(GLU_VERSION) );
g_gluVersion = int(roundf(fGLUVersion * 10)); g_gluVersion = lroundf( fGLUVersion * 10 );
GLExt.Load( g_pWind ); GLExt.Load( g_pWind );
+1 -1
View File
@@ -208,7 +208,7 @@ void GLExt_t::Load( LowLevelWindow *pWind )
else else
{ {
const float fVersion = StringToFloat( pzVersion ); 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. */ /* The version string may contain extra information beyond the version number. */
LOG->Info( "OpenGL shading language: %s", pzVersion ); LOG->Info( "OpenGL shading language: %s", pzVersion );
} }
+2 -2
View File
@@ -876,13 +876,13 @@ RageSurface *RageSurfaceUtils::PalettizeToGrayscale( const RageSurface *src_surf
if( Ivalues == 1 ) if( Ivalues == 1 )
ScaledI = 255; // if only one intensity value, always fullbright ScaledI = 255; // if only one intensity value, always fullbright
else else
ScaledI = clamp( int(roundf(I * (255.0f / (Ivalues-1)))), 0, 255 ); ScaledI = clamp( lroundf(I * (255.0f / (Ivalues-1))), 0L, 255L );
int ScaledA; int ScaledA;
if( Avalues == 1 ) if( Avalues == 1 )
ScaledA = 255; // if only one alpha value, always opaque ScaledA = 255; // if only one alpha value, always opaque
else else
ScaledA = clamp( int(roundf(A * (255.0f / (Avalues-1)))), 0, 255 ); ScaledA = clamp( lroundf(A * (255.0f / (Avalues-1))), 0L, 255L );
RageSurfaceColor c; RageSurfaceColor c;
c.r = uint8_t(ScaledI); c.r = uint8_t(ScaledI);
+2 -2
View File
@@ -559,8 +559,8 @@ void ScreenEvaluation::Init()
RadarCategory_Jumps, RadarCategory_Holds, RadarCategory_Mines, RadarCategory_Hands, RadarCategory_Rolls RadarCategory_Jumps, RadarCategory_Holds, RadarCategory_Mines, RadarCategory_Hands, RadarCategory_Rolls
}; };
const int ind = indeces[l]; const int ind = indeces[l];
const int iActual = (int) roundf(STATSMAN->m_CurStageStats.m_player[p].m_radarActual[ind]); const int iActual = lroundf(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 iPossible = lroundf(STATSMAN->m_CurStageStats.m_player[p].m_radarPossible[ind]);
m_textStatsText[l][p].SetText( ssprintf("%3d/%3d",iActual,iPossible) ); m_textStatsText[l][p].SetText( ssprintf("%3d/%3d",iActual,iPossible) );
} }
+2 -2
View File
@@ -67,7 +67,7 @@ void ScreenNameEntry::ScrollingText::Init( const RString &sName, const vector<fl
void ScreenNameEntry::ScrollingText::DrawPrimitives() void ScreenNameEntry::ScrollingText::DrawPrimitives()
{ {
const float fFakeBeat = GAMESTATE->m_fSongBeat; const float fFakeBeat = GAMESTATE->m_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 ); const float fClosestYOffset = GetClosestCharYOffset( fFakeBeat );
size_t iCharIndex = ( iClosestIndex - NUM_CHARS_TO_DRAW_BEHIND + g_sNameChars.size() ) % g_sNameChars.size(); 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 char ScreenNameEntry::ScrollingText::GetClosestChar( float fFakeBeat ) const
{ {
ASSERT( fFakeBeat >= 0.f ); 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 // return value is relative to gray arrows
+1 -1
View File
@@ -43,7 +43,7 @@ static void AddPart( vector<RString> &AddTo, float level, RString name )
if( level == 0 ) if( level == 0 )
return; 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 ); AddTo.push_back( LevelStr + name );
} }
+1 -1
View File
@@ -112,7 +112,7 @@ int Trail::GetMeter() const
float fMeter = GetTotalMeter() / (float)m_vEntries.size(); float fMeter = GetTotalMeter() / (float)m_vEntries.size();
return (int)roundf( fMeter ); return lroundf( fMeter );
} }
int Trail::GetTotalMeter() const int Trail::GetTotalMeter() const
+3 -3
View File
@@ -69,7 +69,7 @@ static int CalculateWorkoutProgramMeter( WorkoutProgram wp, int iAverageMeter, i
case WorkoutProgram_FatBurn: case WorkoutProgram_FatBurn:
{ {
float fMeter = SCALE( iSongInBodyIndex % 4, 0.0f, 3.0f, (float)iMinMeter, (float)iMaxMeter ); float fMeter = SCALE( iSongInBodyIndex % 4, 0.0f, 3.0f, (float)iMinMeter, (float)iMaxMeter );
iMeter = (int)roundf( fMeter ); iMeter = lroundf( fMeter );
} }
break; break;
case WorkoutProgram_FitnessTest: case WorkoutProgram_FitnessTest:
@@ -92,7 +92,7 @@ static int CalculateWorkoutProgramMeter( WorkoutProgram wp, int iAverageMeter, i
break; break;
case 4: case 4:
case 5: 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; 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 ); float fMeter = SCALE( iSongInBodyIndex % 4, 0.0f, 3.0f, (float)iMinMeter, (float)iMaxMeter );
if( (iSongInBodyIndex % 8) >= 4 ) if( (iSongInBodyIndex % 8) >= 4 )
fMeter = SCALE( fMeter, (float)iMinMeter, (float)iMaxMeter, (float)iMaxMeter, (float)iMinMeter ); fMeter = SCALE( fMeter, (float)iMinMeter, (float)iMaxMeter, (float)iMaxMeter, (float)iMinMeter );
iMeter = (int)roundf( fMeter ); iMeter = lroundf( fMeter );
} }
break; break;
case WorkoutProgram_Flat: case WorkoutProgram_Flat:
@@ -58,7 +58,7 @@ void SetThreadPrecedence( float prec )
// Real values are between 0 and 63. // Real values are between 0 and 63.
if( CLAMP(prec, 0.0f, 1.0f) ) if( CLAMP(prec, 0.0f, 1.0f) )
LOG->Warn( "Thread precedence clamped to %f.", prec ); 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, kern_return_t ret = thread_policy_set( mach_thread_self(), THREAD_PRECEDENCE_POLICY,
(thread_policy_t)&po, THREAD_PRECEDENCE_POLICY_COUNT ); (thread_policy_t)&po, THREAD_PRECEDENCE_POLICY_COUNT );