summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-05 13:47:12 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2013-11-05 13:47:12 +0100
commit07b7563e0748b1aff6f4d28b0172095b2fdcdfcc (patch)
treea5e390cfad822d87e6874f4e719edda445a32585 /tests
parent94e88e887cf2ee4c6b445924d26e134a90bcbd50 (diff)
downloadSystDigit-Projet-07b7563e0748b1aff6f4d28b0172095b2fdcdfcc.tar.gz
SystDigit-Projet-07b7563e0748b1aff6f4d28b0172095b2fdcdfcc.zip
Added netlist simplification passes (not yet quite complete !)
Diffstat (limited to 'tests')
-rw-r--r--tests/clockHMS.mj69
-rw-r--r--tests/nadder.mj12
2 files changed, 75 insertions, 6 deletions
diff --git a/tests/clockHMS.mj b/tests/clockHMS.mj
new file mode 100644
index 0000000..27f96ea
--- /dev/null
+++ b/tests/clockHMS.mj
@@ -0,0 +1,69 @@
+repeat<n>(a) = (x:[n]) where
+ if n = 1 then
+ x = a
+ else
+ if n - (2 * (n / 2)) = 1 then
+ u = repeat<n/2>(a);
+ x = a . u . u
+ else
+ u = repeat<n/2>(a);
+ x = u . u
+ end if
+ end if
+end where
+
+fulladder(a,b,c) = (s, r) where
+ s = (a ^ b) ^ c;
+ r = (a & b) + ((a ^ b) & c);
+end where
+
+adder<n>(a:[n], b:[n], c_in) = (o:[n], c_out) where
+ if n = 0 then
+ o = [];
+ c_out = 0
+ else
+ (s_n, c_n1) = fulladder(a[0], b[0], c_in);
+ (s_n1, c_out) = adder<n-1>(a[1..], b[1..], c_n1);
+ o = s_n . s_n1
+ end if
+end where
+
+equal<n, m>(a:[n]) = (eq) where
+ if n = 0 then
+ eq = 1
+ else
+ if m - (2 * (m / 2)) = 1 then
+ eq = a[0] & equal<n-1, m/2>(a[1..]);
+ else
+ eq = (not a[0]) & equal<n-1, m/2>(a[1..]);
+ end if
+ end if
+end where
+
+reg_n<n>(a:[n]) = (r:[n]) where
+ if n = 0 then
+ r = []
+ else
+ r = (reg a[0]) . (reg_n<n-1>(r[1..]))
+ end if
+end where
+
+and_each<n>(a, b:[n]) = (o:[n]) where
+ if n = 0 then
+ o = []
+ else
+ o = (b[0] and a) . and_each<n-1>(a, b[1..])
+ end if
+end where
+
+count_mod<n, m>(in:[n]) = (out:[n]) where
+ neq = not (equal<n, m>(in));
+ (incr, carry) = adder<n>(in, 1 . repeat<n-1>(0), 0);
+ out = and_each<n>(neq, incr)
+end where
+
+main() = (ret:[2],out:[2]) where
+ out = count_mod<2, 3>(ret);
+ ret = reg_n<2>(out)
+end where
+
diff --git a/tests/nadder.mj b/tests/nadder.mj
index 0c95386..b75a83c 100644
--- a/tests/nadder.mj
+++ b/tests/nadder.mj
@@ -6,14 +6,14 @@ end where
adder<n>(a:[n], b:[n], c_in) = (o:[n], c_out) where
if n = 0 then
o = [];
- c_out = 0
+ c_out = c_in
else
- (s_n1, c_n1) = adder<n-1>(a[1..], b[1..], c_in);
- (s_n, c_out) = fulladder(a[0], b[0], c_n1);
+ (s_n, c_n1) = fulladder(a[0], b[0], c_in);
+ (s_n1, c_out) = adder<n-1>(a[1..], b[1..], c_n1);
o = s_n . s_n1
end if
end where
-main(a, b) = (o, c) where
- (o, c) = adder<1>(a,b,0)
-end where \ No newline at end of file
+main(a:[4], b:[4]) = (o:[4], c) where
+ (o, c) = adder<4>(a,b,0)
+end where