updated runtiem
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "Runtime.hpp"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace spider {
|
||||
|
||||
// Constructors & Destructors //
|
||||
@@ -17,14 +19,17 @@ namespace spider {
|
||||
// Stepping/Running the Machine //
|
||||
|
||||
void Runtime::step() {
|
||||
// fetchInstr() decodes the opcode, addressing mode and type siz
|
||||
// fetchInstr() decodes the opcode,
|
||||
// addressing mode and type size
|
||||
cpu.fetchInstr();
|
||||
// execute() completes the fetch-decode-execute cycle by calling the correct instruction method based on the opcode.
|
||||
// execute() completes the fetch-decode-execute
|
||||
// cycle by calling the correct instruction
|
||||
// method based on the opcode.
|
||||
cpu.execute();
|
||||
}
|
||||
|
||||
void Runtime::step(u64 n) {
|
||||
while(n >= 4) {
|
||||
while (n >= 4) {
|
||||
step();
|
||||
step();
|
||||
step();
|
||||
@@ -34,9 +39,34 @@ namespace spider {
|
||||
while (n--) step();
|
||||
}
|
||||
|
||||
void Runtime::run() {}
|
||||
u64 Runtime::run() {
|
||||
// TODO: Must use the flag register
|
||||
// for the enabled bit.
|
||||
return 0;
|
||||
}
|
||||
|
||||
//void Runtime::run(u64 n) {}
|
||||
u64 Runtime::run(u64 n) {
|
||||
using namespace std::chrono;
|
||||
u64 total_steps = 0;
|
||||
auto start_time = high_resolution_clock::now();
|
||||
|
||||
// TODO: Must use the flag register
|
||||
// for the enabled bit.
|
||||
while (true) {
|
||||
step();
|
||||
step();
|
||||
step();
|
||||
step();
|
||||
total_steps += 4;
|
||||
|
||||
// measure time!
|
||||
auto current_time = high_resolution_clock::now();
|
||||
auto elapsed = duration_cast<milliseconds>(current_time - start_time).count();
|
||||
if (static_cast<u64>(elapsed) >= n) break;
|
||||
}
|
||||
|
||||
return total_steps;
|
||||
}
|
||||
|
||||
// Misc //
|
||||
|
||||
@@ -50,7 +80,7 @@ namespace spider {
|
||||
void Runtime::hookReel(InstrReel* newReel, bool own) {
|
||||
delete this->reel;
|
||||
cpu.hookInstrReel(newReel);
|
||||
if(own) this->reel = newReel;
|
||||
if (own) this->reel = newReel;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,14 +55,18 @@ namespace spider {
|
||||
* Sets the machine to run continously.
|
||||
* If interrupts occur, they will be handled
|
||||
* automatically.
|
||||
*
|
||||
* Returns the amount of cycles ran.
|
||||
*/
|
||||
void run();
|
||||
u64 run();
|
||||
|
||||
/**
|
||||
* Runs this machine for a set amount of
|
||||
* milliseconds.
|
||||
*
|
||||
* Returns the amount of cycles ran.
|
||||
*/
|
||||
void run(u64 ms);
|
||||
u64 run(u64 ms);
|
||||
|
||||
public:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user