Skip to content

Commit

Permalink
Add mux8way16 gate
Browse files Browse the repository at this point in the history
  • Loading branch information
mlouielu committed Jul 3, 2017
1 parent d61b748 commit b4897d0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nand2vm/gate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
from .not_g import Not, Not16
from .or_g import Or, Or16
from .xor import Xor
from .mux import Mux, Mux16, Mux4Way16
from .mux import Mux, Mux16, Mux4Way16, Mux8Way16
from .adder import fa, ha, add16
9 changes: 8 additions & 1 deletion nand2vm/gate/mux.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,11 @@ def Mux4Way16(a: List[bool], b: List[bool], c: List[bool], d: List[bool],
def Mux8Way16(a: List[bool], b: List[bool], c: List[bool], d: List[bool],
e: List[bool], f: List[bool], g: List[bool], h: List[bool],
select: List[bool]):
pass
ab = gate.Mux16(a, b, select[0])
cd = gate.Mux16(c, d, select[0])
ef = gate.Mux16(e, f, select[0])
gh = gate.Mux16(g, h, select[0])
abcd = gate.Mux16(ab, cd, select[1])
efgh = gate.Mux16(ef, gh, select[1])

return gate.Mux16(abcd, efgh, select[2])
27 changes: 27 additions & 0 deletions test/test_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,33 @@ def test_mux4way16_gate(self):
self.assertEqual(gate.Mux4Way16(a, b, c, d, BitArray([True, False])), c)
self.assertEqual(gate.Mux4Way16(a, b, c, d, BitArray([True, True])), d)

def test_mux8way16_gate(self):
a = BitArray([True, True, True, True] * 4)
b = BitArray([True, True, True, False] * 4)
c = BitArray([True, True, False, True] * 4)
d = BitArray([True, False, True, True] * 4)
e = BitArray([False, True, True, True] * 4)
f = BitArray([False, False, True, False] * 4)
g = BitArray([False, True, False, True] * 4)
h = BitArray([False, False, False, True] * 4)

self.assertEqual(gate.Mux8Way16(a, b, c, d, e, f, g, h,
BitArray([False, False, False])), a)
self.assertEqual(gate.Mux8Way16(a, b, c, d, e, f, g, h,
BitArray([False, False, True])), b)
self.assertEqual(gate.Mux8Way16(a, b, c, d, e, f, g, h,
BitArray([False, True, False])), c)
self.assertEqual(gate.Mux8Way16(a, b, c, d, e, f, g, h,
BitArray([False, True, True])), d)
self.assertEqual(gate.Mux8Way16(a, b, c, d, e, f, g, h,
BitArray([True, False, False])), e)
self.assertEqual(gate.Mux8Way16(a, b, c, d, e, f, g, h,
BitArray([True, False, True])), f)
self.assertEqual(gate.Mux8Way16(a, b, c, d, e, f, g, h,
BitArray([True, True, False])), g)
self.assertEqual(gate.Mux8Way16(a, b, c, d, e, f, g, h,
BitArray([True, True, True])), h)

def test_and_16_gate(self):
t = BitArray([True] * 16)
f = BitArray([False] * 16)
Expand Down

0 comments on commit b4897d0

Please sign in to comment.