summaryrefslogtreecommitdiff
path: root/cpu/alu.ml
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-02 22:30:11 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-02 22:30:11 +0100
commit85bc61cb7fa8f4b9af78064cb65fbad49a109d5f (patch)
tree5116b1c423864f3cde8f1002b7a4dabb62e88fff /cpu/alu.ml
parent4e1aaf316457f4d4f045fd3ebe500cd70f6bafcc (diff)
downloadSystDigit-Projet-85bc61cb7fa8f4b9af78064cb65fbad49a109d5f.tar.gz
SystDigit-Projet-85bc61cb7fa8f4b9af78064cb65fbad49a109d5f.zip
Started CPU implementation.
Diffstat (limited to 'cpu/alu.ml')
-rw-r--r--cpu/alu.ml17
1 files changed, 17 insertions, 0 deletions
diff --git a/cpu/alu.ml b/cpu/alu.ml
index 0a0c00f..cf33cd2 100644
--- a/cpu/alu.ml
+++ b/cpu/alu.ml
@@ -12,5 +12,22 @@ 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 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_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))