From 1ff268ab13dd299c4cdc1e379df5397bd6a394e3 Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Fri, 3 Jan 2014 19:05:10 +0100 Subject: Added simulator monitor tool. --- cpu/alu.ml | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'cpu/alu.ml') diff --git a/cpu/alu.ml b/cpu/alu.ml index a0115a4..7356fbb 100644 --- a/cpu/alu.ml +++ b/cpu/alu.ml @@ -12,6 +12,18 @@ let rec eq_c n v c = (* v is a value, c is a constant *) else (eq_c 1 (v ** 0) (c mod 2)) ^& (eq_c (n-1) (v % (1, n-1)) (c/2)) +let rec all1 n x = + if n = 1 then + x + else + (x ** 0) ^& (all1 (n-1) (x % (1, n-1))) + +let rec nonnull n a = + if n = 1 then + a + else + (a ** 0) ^| (nonnull (n-1) (a % (1, n-1))) + let rec sign_extend n_a n_dest a = a ++ rep (n_dest - n_a) (a ** (n_a - 1)) @@ -27,23 +39,18 @@ let rec nadder n a b c_in = let s_n1, c_out = nadder (n-1) (a % (1, n-1)) (b % (1, n-1)) c_n1 in s_n ++ s_n1, c_out +let rec npshift_signed n p a b = + a (* TODO *) + let nadder_nocarry n a b = let a, b = nadder n a b (const "0") in ignore b a let rec eq_n n a b = - if n = 1 then - not (a ^^ b) - else - (not ((a ** 0) ^^ (b ** 0))) - ^& (eq_n (n-1) (a % (1, n-1)) (b % (1, n-1))) + all1 n (not (a ^^ b)) let rec ne_n n a b = - if n = 1 then - a ^^ b - else - ((a ** 0) ^^ (b ** 0)) - ^| (ne_n (n-1) (a % (1, n-1)) (b % (1, n-1))) + nonnull n (a ^^ b) let rec lt_n n a b = const "0" (* TODO : less than *) -- cgit v1.2.3