Optimization Question

Gunnar Braun <braung@ert.rwth-aachen.de>
27 Jul 2000 21:37:04 -0400

          From comp.compilers

Related articles
Optimization Question braung@ert.rwth-aachen.de (Gunnar Braun) (2000-07-27)
Re: Optimization Question gunnar@moria.net.dhis.org (Gunnar Braun) (2000-07-30)
Re: Optimization Question rkrayhawk@aol.com (2000-07-31)
Re: Optimization Question chase@naturalbridge.com (David Chase) (2000-08-04)
| List of all articles for this month |

From: Gunnar Braun <braung@ert.rwth-aachen.de>
Newsgroups: comp.compilers
Date: 27 Jul 2000 21:37:04 -0400
Organization: ISS, RWTH Aachen
Keywords: optimize, performance, question

Hi all.


I wrote a program that should simulate the behavior of a microprocessor.
To achieve this, there is one function, which is executed for every
simulated cycle of the target processor. Within this function a pretty
large simulation table is accessed, which contains quite a lot of
function
pointers. Pretty much simplified, it looks like this:


void execute_cycle()
{
        (*big_simulation_table[cycle])();
        cycle++;
}


Since that function (execute_cycle) is executed every simulated cycle of
the simulated processor, it is executed millions of times and therefore
it is reasonable to optimize this function. Unfortunately, I'm not very
experienced in which actions have a positive and which have a negative
impact in terms of performance. Is it the access to (kind of) a 4
dimensional array or the fact that I'm accessing pointers to member
functions?! I would be glad if somebody had an idea about that. I
attached my 'real' execute_cycle function to this posting.


Thanks in advance,


Gunnar
--------------


void execute_cycle()
{
    static C54x_insntabl_T * itab = 0;
    long StageNr = 0;
    long SavedLine = 0;
    char SavedTableNr = 0;
    register int i = 0;


    // IF THERE IS A TARGET TABLE, WE HAVE TO CHECK IF WE MUST BRANCH
    // TO ANOTHER ADDRESS/TABLE 0 --> THIS ROUTINE IS NECESSARY!


    if (m_pStaticTable[m_TableNr][m_CurrentLine].TargetTableNo > 0)
        {
            SavedLine = m_CurrentLine;
            SavedTableNr = m_TableNr;


            if (m_pStaticTable[SavedTableNr][SavedLine].TargetTableIndex != -1)
{
if (! Evaluate_Condition(SavedTableNr, SavedLine))
{
m_TableNr = m_pStaticTable[SavedTableNr][SavedLine].TargetTableNo;
m_CurrentLine = m_pStaticTable[SavedTableNr][SavedLine].TargetTableIndex;
}
}
            else
{
cout << "**Error: target table defined but no index defined!" << endl;
}
        }


    // EXECUTION OF ALL FUNCTIONS POINTERS IN ALL 6 PIPELINE STAGES


    for (StageNr = 5; StageNr >= 0; StageNr--)
        {
            i = 0;
            while (m_pStaticTable[m_TableNr][m_CurrentLine].pStage[StageNr][i].OpFuncPtr)
{
itab = m_pStaticTable[m_TableNr][m_CurrentLine].pStage[StageNr][i].pInsnTableLine;
(this->*m_pStaticTable[m_TableNr][m_CurrentLine].pStage[StageNr][i++].OpFuncPtr)(itab);
}
        }


    // IF TARGET TABLE == 0 AND TARGET INDEX != -1, WE HAVE TO BRANCH AFTER
    // EXECUTION OF THE PIPELINE --> THIS ROUTINE IS NECESSARY!


    if (m_pStaticTable[m_TableNr][m_CurrentLine].TargetTableNo == 0)
        {
            SavedLine = m_CurrentLine;
            SavedTableNr = m_TableNr;


            if (m_pStaticTable[SavedTableNr][SavedLine].TargetTableIndex != -1)
{
m_TableNr = m_pStaticTable[SavedTableNr][SavedLine].TargetTableNo;
m_CurrentLine = m_pStaticTable[SavedTableNr][SavedLine].TargetTableIndex;
}
            else
{
cout << "**Error: target table defined but no index defined!" << endl;
}
        }
    else
        {
            m_CurrentLine++;
        }


    /* Increment cycle counter */
    cycle++;
}


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.