From f7e0998696cf5d1be50847f37dc5eec972509640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Fri, 25 Sep 2020 00:08:47 +0200 Subject: [PATCH] add mul, disable slow mode --- crsn/src/main.rs | 21 ++++++++++++++++++++- runtime/src/exec/mod.rs | 13 +++++++++++-- runtime/src/run_thread.rs | 3 ++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/crsn/src/main.rs b/crsn/src/main.rs index 3612ca3..4293ee5 100644 --- a/crsn/src/main.rs +++ b/crsn/src/main.rs @@ -21,7 +21,7 @@ fn main() { ) ) ";*/ - +/* let program = " ( (main @@ -38,6 +38,25 @@ fn main() { (ret r0) ) ) + ";*/ + + let program = " + ( + (main + (call fibo 5) + (ld r0 res0) + ) + (fibo + (cmp arg0 2 + (eq? (ret 2))) + (ld r0 arg0) + (dec r0) + (call fibo r0) + (ld r0 arg0) + (mul r0 res0) + (ret r0) + ) + ) "; let parsed = asm::assemble(program).unwrap(); diff --git a/runtime/src/exec/mod.rs b/runtime/src/exec/mod.rs index f68881d..f529286 100644 --- a/runtime/src/exec/mod.rs +++ b/runtime/src/exec/mod.rs @@ -166,8 +166,17 @@ impl RunThread { // TODO carry? frame.write(*dst, val)?; } - Op::Mul(_, _) => { - unimplemented!() + Op::Mul(dst, src) => { + frame.status.clear(); + let mut a = frame.read(dst.as_rd())?; + let mut b = frame.read(*src)?; + + let val = a.wrapping_mul(b); + frame.status.zero = (val == 0); + frame.status.positive = is_positive(val); + frame.status.negative = is_negative(val); + //frame.status.overflow = b > a; // TODO detect overflow + frame.write(*dst, val)?; } Op::Div(_, _) => { unimplemented!() diff --git a/runtime/src/run_thread.rs b/runtime/src/run_thread.rs index c770c73..5af6851 100644 --- a/runtime/src/run_thread.rs +++ b/runtime/src/run_thread.rs @@ -10,7 +10,8 @@ use crate::frame::StackFrame; use crate::program::Program; use crate::exec::EvalRes; -const CYCLE_TIME : Duration = Duration::from_millis(100); +const CYCLE_TIME : Duration = Duration::from_millis(0); +//const CYCLE_TIME : Duration = Duration::from_millis(100); #[derive(Clone, Copy, Eq, PartialEq, Debug, Ord, PartialOrd)] pub struct ThreadToken(pub u32);