summaryrefslogtreecommitdiff
path: root/cpu/alu.ml
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-02 23:20:01 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-02 23:20:01 +0100
commitf2b28b4124015718dc4b392e00f4aade4eedc11c (patch)
tree23fd7fe368be899bd17daecfcbde81b0214ed03e /cpu/alu.ml
parentb93b112a57fec10ac9c78058749be1ee27b13d4a (diff)
downloadSystDigit-Projet-f2b28b4124015718dc4b392e00f4aade4eedc11c.tar.gz
SystDigit-Projet-f2b28b4124015718dc4b392e00f4aade4eedc11c.zip
Implement jr/jalr/jer/jner/jltr/jler/jltru/jleru ; add simplification to sched.
Diffstat (limited to 'cpu/alu.ml')
-rw-r--r--cpu/alu.ml68
1 files changed, 56 insertions, 12 deletions
diff --git a/cpu/alu.ml b/cpu/alu.ml
index cf33cd2..a0115a4 100644
--- a/cpu/alu.ml
+++ b/cpu/alu.ml
@@ -1,5 +1,20 @@
open Netlist_gen
+let rec rep n k =
+ if n = 1 then k
+ else
+ let s = rep (n/2) k in
+ if n mod 2 = 0 then s ++ s else s ++ s ++ k
+
+let rec eq_c n v c = (* v is a value, c is a constant *)
+ if n = 1 then
+ if c = 1 then v else not v
+ else
+ (eq_c 1 (v ** 0) (c mod 2)) ^& (eq_c (n-1) (v % (1, n-1)) (c/2))
+
+let rec sign_extend n_a n_dest a =
+ a ++ rep (n_dest - n_a) (a ** (n_a - 1))
+
let fulladder a b c =
let s = a ^^ b ^^ c in
let r = (a ^& b) ^| ((a ^^ b) ^& c) in
@@ -16,18 +31,47 @@ let nadder_nocarry n a b =
let a, b = nadder n a b (const "0") in
ignore b a
-let rec rep n k =
- if n = 1 then k
- else
- let s = rep (n/2) k in
- if n mod 2 = 0 then s ++ s else s ++ s ++ k
-
-let rec sign_extend n_a n_dest a =
- a ++ rep (n_dest - n_a) (a ** (n_a - 1))
+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)))
-let rec eq_c n v c = (* v is a value, c is a constant *)
+let rec ne_n n a b =
if n = 1 then
- if c = 1 then v else not v
- else
- (eq_c 1 (v ** 0) (c mod 2)) ^& (eq_c (n-1) (v % (1, n-1)) (c/2))
+ a ^^ b
+ else
+ ((a ** 0) ^^ (b ** 0))
+ ^| (ne_n (n-1) (a % (1, n-1)) (b % (1, n-1)))
+
+let rec lt_n n a b =
+ const "0" (* TODO : less than *)
+
+let rec ult_n n a b =
+ const "0" (* TODO : less than, unsigned *)
+
+let rec le_n n a b =
+ const "0" (* TODO : less than or equal *)
+
+let rec ule_n n a b =
+ const "0" (* TODO : less than or equal, unsigned *)
+let alu_comparer n f0 f a b =
+ (*
+ f0 f action
+ -- - ------
+ 0 0 equal
+ 0 1 not equal
+ 0 2 equal
+ 0 3 not equal
+ 1 0 lt
+ 1 1 le
+ 1 2 lt unsigned
+ 1 3 le unsigned
+ *)
+ let eq_ne = mux (f ** 0) (eq_n n a b) (ne_n n a b) in
+ let lte_signed = mux (f ** 0) (lt_n n a b) (le_n n a b) in
+ let lte_unsigned = mux (f ** 0) (ult_n n a b) (ule_n n a b) in
+ let lte = mux (f ** 1) lte_signed lte_unsigned in
+ mux f0 eq_ne lte