OpenASIP 2.2
Loading...
Searching...
No Matches
Functions
TTASimTandem.cc File Reference
#include <iostream>
#include <algorithm>
#include <boost/format.hpp>
#include "Application.hh"
#include "Machine.hh"
#include "Program.hh"
#include "SimulatorFrontend.hh"
#include "RegisterFile.hh"
#include "SimValue.hh"
#include "POMDisassembler.hh"
#include "DisassemblyFUPort.hh"
#include "Instruction.hh"
#include "Procedure.hh"
Include dependency graph for TTASimTandem.cc:

Go to the source code of this file.

Functions

void tandemSimulate (TTAMachine::Machine &machine, TTAProgram::Program &program)
 
int main (int argc, char *argv[])
 

Detailed Description

Implementation of a simulator that runs both compiled simulation and the interpretive (debugging) simulation in parallel and compares the execution to detect differences in the simulations, which indicate there's a missimulation bug in one or both of the engines.

Author
Pekka Jääskeläinen 2009 (pjaaskel-no.spam-cs.tut.fi)
Note
rating: red

Definition in file TTASimTandem.cc.

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 123 of file TTASimTandem.cc.

123 {
124
126
127 if (argc < 3) {
128 std::cerr << "usage: ttasim-tandem machine.adf program.tpef";
129
130 }
131
132 try {
138
139 delete machine; machine = NULL;
140 delete program; program = NULL;
141 } catch (const Exception& e) {
142 std::cerr << e.errorMessage() << std::endl;
143 return EXIT_FAILURE;
144 }
145 return EXIT_SUCCESS;
146}
TTAMachine::Machine * machine
the architecture definition of the estimated processor
find Finds info of the inner loops in the program
void tandemSimulate(TTAMachine::Machine &machine, TTAProgram::Program &program)
static void initialize()
std::string errorMessage() const
Definition Exception.cc:123
static Machine * loadFromADF(const std::string &adfFileName)
Definition Machine.cc:899
static Program * loadFromTPEF(const std::string &tpefFileName, const TTAMachine::Machine &theMachine)
Definition Program.cc:1112

References Exception::errorMessage(), Application::initialize(), TTAMachine::Machine::loadFromADF(), TTAProgram::Program::loadFromTPEF(), machine, program, and tandemSimulate().

Here is the call graph for this function:

◆ tandemSimulate()

void tandemSimulate ( TTAMachine::Machine machine,
TTAProgram::Program program 
)

Simulates the given program+machine in "tandem" with the two simulation engines.

Definition at line 55 of file TTASimTandem.cc.

57 {
58
59 // initialize both simulation engines
61 interp.loadMachine(machine);
62 interp.loadProgram(program);
63
65
66 // leave the compile simulation engine files at /tmp
67 compiled.setCompiledSimulationLeaveDirty(true);
68
69 compiled.loadMachine(machine);
70 compiled.loadProgram(program);
71 // reduce startup time by using dynamic compilation of the simulation
72 // engine
73 compiled.setStaticCompilation(false);
74
75
76 assert(compiled.isSimulationInitialized());
77 assert(interp.isSimulationInitialized());
78
79 ClockCycleCount simulatedCycles = 0;
80 while (!compiled.hasSimulationEnded()) {
81 ClockCycleCount stepping;
82 try {
83 compiled.step(1);
84
85 // the compiled simulator compiled BB at a time so we need to
86 // ask it how many cycle to advance the cycle level interp. engine
87 // to get to the same position in the simulation
88 stepping =
89 compiled.cycleCount() - simulatedCycles;
90
91 interp.step(stepping);
92 simulatedCycles += stepping;
93 } catch (const Exception& e) {
94 std::cerr << "Simulation error: " << e.errorMessage() << std::endl;
95 return;
96
97 }
98
99 if (!compiled.compareState(interp, &std::cerr))
100 return;
101
102 // print out the cycle count after simulating at least 1M cycles
103 if (simulatedCycles / 1000000 > (simulatedCycles - stepping) / 1000000)
104 std::cout
105 << "simulated " << simulatedCycles << " cycles" << std::endl;
106 }
107
108 std::cout
109 << "stop reasons:" << std::endl
110 << "* compiled engine:" << std::endl;
111 for (unsigned i = 0; i < compiled.stopReasonCount(); ++i) {
112 std::cout << "** " << compiled.stopReason(i) << std::endl;
113 }
114 std::cout
115 << "* interp. engine:" << std::endl;
116 for (unsigned i = 0; i < interp.stopReasonCount(); ++i) {
117 std::cout << "** " << interp.stopReason(i) << std::endl;
118 }
119
120}
#define assert(condition)
CycleCount ClockCycleCount
Alias for ClockCycleCount.
@ SIM_COMPILED
Compiled, faster simulation.
@ SIM_NORMAL
Default, interpreted simulation (debugging engine).

References assert, SimulatorFrontend::compareState(), SimulatorFrontend::cycleCount(), Exception::errorMessage(), SimulatorFrontend::hasSimulationEnded(), SimulatorFrontend::isSimulationInitialized(), SimulatorFrontend::loadMachine(), SimulatorFrontend::loadProgram(), machine, program, SimulatorFrontend::setCompiledSimulationLeaveDirty(), SimulatorFrontend::setStaticCompilation(), SimulatorFrontend::SIM_COMPILED, SimulatorFrontend::SIM_NORMAL, SimulatorFrontend::step(), SimulatorFrontend::stopReason(), and SimulatorFrontend::stopReasonCount().

Referenced by main().

Here is the call graph for this function: