From 818f81108fa30cd5a90c99df955f811fed043993 Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Wed, 6 Nov 2013 19:22:00 +0100 Subject: Documented the C simulator in the README file ; added a test file. --- tests/shifters.mj | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/shifters.mj (limited to 'tests') diff --git a/tests/shifters.mj b/tests/shifters.mj new file mode 100644 index 0000000..2fbe498 --- /dev/null +++ b/tests/shifters.mj @@ -0,0 +1,62 @@ +const word_size = 4 + +(* Transforme un fil en une nappe de n fils avec la meme valeur *) +power(i) = (o:[n]) where + if n = 0 then + o = [] + else + o = power(i) . i + end if +end where + +mux_n(c, a:[n], b:[n]) = (o:[n]) where + if n = 0 then + o = [] + else + o_n1 = mux_n(c, a[1..n-1], b[1..n-1]); + o_n = mux(c, a[0], b[0]); + o = o_n . o_n1 + end if +end where + +lshifter_n(sh:[n], a:[p]) = (o:[p]) where + if n = 0 then + o = a + else + u = mux_n

(sh[n-1], a, power<2^(n-1)>(false) . a[0..p-2^(n-1)-1]); + o = lshifter_n(sh[0..n-2], u) + end if +end where + +rshifter_n(sh:[n], arith, a:[p]) = (o:[p]) where + if n = 1 then + added_bit = mux(arith, false, a[p-1]); + o = mux_n

(sh[0], a, a[1..p-1] . added_bit) + else + added_bit = mux(arith, false, a[p - 1]); + u = mux_n

(sh[n-1], a, a[2^(n-1)..p-1] . power<2^(n-1)>(added_bit)); + o = rshifter_n(sh[0..n-2], arith, u) + end if +end where + +or_n(a:[n],b:[n]) = (o:[n]) where + if n = 0 then + o = [] + else + o = (a[0] or b[0]) . or_n(a[1..], b[1..]) + end if +end where + +and_each(a,b:[n]) = (o:[n]) where + if n = 0 then + o = [] + else + o = (a and b[0]) . and_each(a, b[1..]) + end if +end where + +main(sh:[2], arith, left, a:[word_size]) = (o:[word_size]) where + x = rshifter_n<2, word_size>(sh, arith, a); + xx = and_each(not left, x); + o = xx +end where -- cgit v1.2.3