updated runtiem

This commit is contained in:
2026-06-14 23:39:17 -06:00
parent 869ce0c7bf
commit 708c4ab593
2 changed files with 42 additions and 8 deletions
+36 -6
View File
@@ -1,5 +1,7 @@
#include "Runtime.hpp" #include "Runtime.hpp"
#include <chrono>
namespace spider { namespace spider {
// Constructors & Destructors // // Constructors & Destructors //
@@ -17,14 +19,17 @@ namespace spider {
// Stepping/Running the Machine // // Stepping/Running the Machine //
void Runtime::step() { void Runtime::step() {
// fetchInstr() decodes the opcode, addressing mode and type siz // fetchInstr() decodes the opcode,
// addressing mode and type size
cpu.fetchInstr(); 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(); cpu.execute();
} }
void Runtime::step(u64 n) { void Runtime::step(u64 n) {
while(n >= 4) { while (n >= 4) {
step(); step();
step(); step();
step(); step();
@@ -34,9 +39,34 @@ namespace spider {
while (n--) step(); 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 // // Misc //
@@ -50,7 +80,7 @@ namespace spider {
void Runtime::hookReel(InstrReel* newReel, bool own) { void Runtime::hookReel(InstrReel* newReel, bool own) {
delete this->reel; delete this->reel;
cpu.hookInstrReel(newReel); cpu.hookInstrReel(newReel);
if(own) this->reel = newReel; if (own) this->reel = newReel;
} }
} }
+6 -2
View File
@@ -55,14 +55,18 @@ namespace spider {
* Sets the machine to run continously. * Sets the machine to run continously.
* If interrupts occur, they will be handled * If interrupts occur, they will be handled
* automatically. * automatically.
*
* Returns the amount of cycles ran.
*/ */
void run(); u64 run();
/** /**
* Runs this machine for a set amount of * Runs this machine for a set amount of
* milliseconds. * milliseconds.
*
* Returns the amount of cycles ran.
*/ */
void run(u64 ms); u64 run(u64 ms);
public: public: