make exec speed configurable

floats
Ondřej Hruška 4 years ago
parent 0cd800653f
commit be1ee66970
Signed by untrusted user: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 7
      crsn/src/runtime/exec.rs
  2. 4
      crsn/src/runtime/run_thread.rs
  3. 4
      crsn_stacks/src/exec.rs
  4. 16
      launcher/src/main.rs

@ -16,11 +16,6 @@ impl RunThread {
trace!("### {:04} : {:?}", state.frame.pc.0, op);
/* Operations can be given different execution times when run in slow mode. */
/* Presently, all that do anything use 1 cycle. */
let rv = op.execute(info, state);
trace!("-> {:?}", rv);
rv
op.execute(info, state)
}
}

@ -63,6 +63,10 @@ impl RunThread {
}
}
pub fn set_speed(&mut self, cycle_time : Duration) {
self.info.cycle_time = cycle_time;
}
pub fn start(self) -> JoinHandle<()> {
std::thread::spawn(move || {
self.run();

@ -48,6 +48,10 @@ impl OpTrait for StackOp {
let obj: &mut Stacks = state.ext_mut();
let val = obj.stacks[stack_num as usize].pop_back();
if obj.stacks[stack_num as usize].is_empty() {
state.frame.status.zero = true;
}
let val = match val {
None => {
state.frame.status.overflow = true;

@ -8,6 +8,7 @@ use crsn::asm::data::literal::Addr;
use crsn::runtime::run_thread::{RunThread, ThreadToken};
use crsn_arith::ArithOps;
use crsn_stacks::StackOps;
use std::time::Duration;
fn main() {
SimpleLogger::new().init().unwrap();
@ -71,12 +72,19 @@ fn main() {
(main
(push 0 10)
(push 0 20)
(call emptystack 0)
(push 0 30)
(pop r0 0)
(pop r0 0)
(pop r0 0)
(halt)
)
(emptystack
(:again)
(pop _ arg0 (z? (ret)))
(j :again)
(ret)
)
)
";
@ -87,12 +95,14 @@ fn main() {
let parsed = crsn::asm::assemble(program, parsers.as_slice()).unwrap();
let thread1 = RunThread::new(ThreadToken(0), parsed.clone(), Addr(0), &[]);
let mut thread1 = RunThread::new(ThreadToken(0), parsed.clone(), Addr(0), &[]);
thread1.set_speed(Duration::from_millis(1000));
let thread2 = RunThread::new(ThreadToken(1), parsed.clone(), Addr(0), &[]);
let a = thread1.start();
let b = thread2.start();
//let b = thread2.start();
a.join().unwrap();
b.join().unwrap();
//b.join().unwrap();
}

Loading…
Cancel
Save