From b6b536727b7e3cb0dc0463ab6a4bdec757ff466b Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Tue, 12 Nov 2013 16:15:59 +0100 Subject: Minor changes. --- tests/clock_emile.mj | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 tests/clock_emile.mj (limited to 'tests') diff --git a/tests/clock_emile.mj b/tests/clock_emile.mj new file mode 100644 index 0000000..9b58d54 --- /dev/null +++ b/tests/clock_emile.mj @@ -0,0 +1,78 @@ +cm_2 (i) = (s,r) where + s = reg (i xor s); + r = i and s +end where + +add (i,a:[n]) = (s:[n],r) where + if n = 1 then + s = a ^ i; + r = a & i + else + (s_a,r) = add(i & a[0], a[1..]); + s = (i ^ a[0]) . s_a + end if +end where + +cb (i) = (s:[n],r) where + if n = 1 then + (s,r) = cm_2 (i) + else + c = reg ( i ^ s[0] ); + (s_a,r) = cb(i & c); + s = c . s_a + end if +end where + +and_n (a : [n]) = o where + if n = 1 then + o = a[0] + else if n = 0 then + o = 1 + else + o = and_n(a[..(n/2)-1]) & and_n(a[n/2..]) + end if end if +end where + +nxor2_n (a : [n], b : [n]) = o : [n] where + if n = 0 then + o = [] + else o = (a[0] ^ not b[0]) . nxor2_n (a[1..], b[1..]) + end if +end where + +eq_m1 (i : [n]) = b where + b = and_n(nxor2_n(i,0b110111)) +end where + +eq_m2 (i : [n]) = b where + b = and_n(nxor2_n(i,0b11101)) +end where + +cm_m_aux (r,i) = s : [n] where + if n = 0 then + s = [] + else + c = reg ( mux(r,c ^ i,0) ); + s = c . cm_m_aux(r,i & c) + end if +end where + +cm_m1 (i) = (s:[n],r) where + c = reg ( mux(r, i ^ c,0) ); + s = c . cm_m_aux(r,i & c); + r = eq_m1(s) & i +end where + +cm_m2 (i) = (s:[n],r) where + c = reg ( mux(r, i ^ c,0) ); + s = c . cm_m_aux(r,i & c); + r = eq_m2(s) & i +end where + +main() = (secs:[6],mins:[6],hours:[5],r_d) where + (secs,r_s) = cm_m1<6>(1); + (mins,r_m) = cm_m1<6>(r_s); + (hours,r_d) = cm_m2<5>(r_m); +end where + + -- cgit v1.2.3