|
|
|
@ -78,26 +78,81 @@ class LogicSim(sim.SimOps):
@@ -78,26 +78,81 @@ class LogicSim(sim.SimOps):
|
|
|
|
|
if op == sim.BUF1: self.c[o0]=self.c[i0] |
|
|
|
|
elif op == sim.INV1: self.c[o0] = ~self.c[i0] |
|
|
|
|
elif op == sim.AND2: self.c[o0] = self.c[i0] & self.c[i1] |
|
|
|
|
elif op == sim.AND3: self.c[o0] = self.c[i0] & self.c[i1] & self.c[i2] |
|
|
|
|
elif op == sim.AND4: self.c[o0] = self.c[i0] & self.c[i1] & self.c[i2] & self.c[i3] |
|
|
|
|
elif op == sim.NAND2: self.c[o0] = ~(self.c[i0] & self.c[i1]) |
|
|
|
|
elif op == sim.NAND3: self.c[o0] = ~(self.c[i0] & self.c[i1] & self.c[i2]) |
|
|
|
|
elif op == sim.NAND4: self.c[o0] = ~(self.c[i0] & self.c[i1] & self.c[i2] & self.c[i3]) |
|
|
|
|
elif op == sim.OR2: self.c[o0] = self.c[i0] | self.c[i1] |
|
|
|
|
elif op == sim.OR3: self.c[o0] = self.c[i0] | self.c[i1] | self.c[i2] |
|
|
|
|
elif op == sim.OR4: self.c[o0] = self.c[i0] | self.c[i1] | self.c[i2] | self.c[i3] |
|
|
|
|
elif op == sim.NOR2: self.c[o0] = ~(self.c[i0] | self.c[i1]) |
|
|
|
|
elif op == sim.NOR3: self.c[o0] = ~(self.c[i0] | self.c[i1] | self.c[i2]) |
|
|
|
|
elif op == sim.NOR4: self.c[o0] = ~(self.c[i0] | self.c[i1] | self.c[i2] | self.c[i3]) |
|
|
|
|
elif op == sim.XOR2: self.c[o0] = self.c[i0] ^ self.c[i1] |
|
|
|
|
elif op == sim.XOR3: self.c[o0] = self.c[i0] ^ self.c[i1] ^ self.c[i2] |
|
|
|
|
elif op == sim.XOR4: self.c[o0] = self.c[i0] ^ self.c[i1] ^ self.c[i2] ^ self.c[i3] |
|
|
|
|
elif op == sim.XNOR2: self.c[o0] = ~(self.c[i0] ^ self.c[i1]) |
|
|
|
|
elif op == sim.XNOR3: self.c[o0] = ~(self.c[i0] ^ self.c[i1] ^ self.c[i2]) |
|
|
|
|
elif op == sim.XNOR4: self.c[o0] = ~(self.c[i0] ^ self.c[i1] ^ self.c[i2] ^ self.c[i3]) |
|
|
|
|
elif op == sim.AOI21: self.c[o0] = ~((self.c[i0] & self.c[i1]) | self.c[i2]) |
|
|
|
|
else: print(f'unknown op {op}') |
|
|
|
|
inject_cb(o0, self.s[o0]) |
|
|
|
|
elif self.m == 4: |
|
|
|
|
for op, o0, i0, i1, i2, i3 in self.ops: |
|
|
|
|
o0, i0, i1, i2, i3 = [self.c_locs[x] for x in (o0, i0, i1, i2, i3)] |
|
|
|
|
if op == sim.BUF1: self.c[o0]=self.c[i0] |
|
|
|
|
elif op == sim.INV1: logic.bp4v_not(self.c[o0], self.c[i0]) |
|
|
|
|
elif op == sim.AND2: logic.bp4v_and(self.c[o0], self.c[i0], self.c[i1]) |
|
|
|
|
elif op == sim.AND3: logic.bp4v_and(self.c[o0], self.c[i0], self.c[i1], self.c[i2]) |
|
|
|
|
elif op == sim.AND4: logic.bp4v_and(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]) |
|
|
|
|
elif op == sim.NAND2: logic.bp4v_and(self.c[o0], self.c[i0], self.c[i1]); logic.bp4v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.NAND3: logic.bp4v_and(self.c[o0], self.c[i0], self.c[i1], self.c[i2]); logic.bp4v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.NAND4: logic.bp4v_and(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]); logic.bp4v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.OR2: logic.bp4v_or(self.c[o0], self.c[i0], self.c[i1]) |
|
|
|
|
elif op == sim.OR3: logic.bp4v_or(self.c[o0], self.c[i0], self.c[i1], self.c[i2]) |
|
|
|
|
elif op == sim.OR4: logic.bp4v_or(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]) |
|
|
|
|
elif op == sim.NOR2: logic.bp4v_or(self.c[o0], self.c[i0], self.c[i1]); logic.bp4v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.NOR3: logic.bp4v_or(self.c[o0], self.c[i0], self.c[i1], self.c[i2]); logic.bp4v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.NOR4: logic.bp4v_or(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]); logic.bp4v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.XOR2: logic.bp4v_xor(self.c[o0], self.c[i0], self.c[i1]) |
|
|
|
|
elif op == sim.XOR3: logic.bp4v_xor(self.c[o0], self.c[i0], self.c[i1], self.c[i2]) |
|
|
|
|
elif op == sim.XOR4: logic.bp4v_xor(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]) |
|
|
|
|
elif op == sim.XNOR2: logic.bp4v_xor(self.c[o0], self.c[i0], self.c[i1]); logic.bp4v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.XNOR3: logic.bp4v_xor(self.c[o0], self.c[i0], self.c[i1], self.c[i2]); logic.bp4v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.XNOR4: logic.bp4v_xor(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]); logic.bp4v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.AOI21: |
|
|
|
|
logic.bp4v_and(self.c[self.c_locs[self.tmp_idx]], self.c[i0], self.c[i1]) |
|
|
|
|
logic.bp4v_or(self.c[o0], self.c[self.c_locs[self.tmp_idx]], self.c[i2]) |
|
|
|
|
logic.bp4v_not(self.c[o0], self.c[o0]) |
|
|
|
|
else: print(f'unknown op {op}') |
|
|
|
|
else: |
|
|
|
|
for op, o0, i0, i1, i2, i3 in self.ops: |
|
|
|
|
o0, i0, i1, i2, i3 = [self.c_locs[x] for x in (o0, i0, i1, i2, i3)] |
|
|
|
|
if op == sim.BUF1: self.c[o0]=self.c[i0] |
|
|
|
|
elif op == sim.INV1: logic.bp_not(self.c[o0], self.c[i0]) |
|
|
|
|
elif op == sim.AND2: logic.bp_and(self.c[o0], self.c[i0], self.c[i1]) |
|
|
|
|
elif op == sim.NAND2: logic.bp_and(self.c[o0], self.c[i0], self.c[i1]); logic.bp_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.OR2: logic.bp_or(self.c[o0], self.c[i0], self.c[i1]) |
|
|
|
|
elif op == sim.NOR2: logic.bp_or(self.c[o0], self.c[i0], self.c[i1]); logic.bp_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.XOR2: logic.bp_xor(self.c[o0], self.c[i0], self.c[i1]) |
|
|
|
|
elif op == sim.XNOR2: logic.bp_xor(self.c[o0], self.c[i0], self.c[i1]); logic.bp_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.AOI21: logic.bp_and(self.c[self.tmp_idx], self.c[i0], self.c[i1]); logic.bp_or(self.c[o0], self.c[self.tmp_idx], self.c[i2]); logic.bp_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.INV1: logic.bp8v_not(self.c[o0], self.c[i0]) |
|
|
|
|
elif op == sim.AND2: logic.bp8v_and(self.c[o0], self.c[i0], self.c[i1]) |
|
|
|
|
elif op == sim.AND3: logic.bp8v_and(self.c[o0], self.c[i0], self.c[i1], self.c[i2]) |
|
|
|
|
elif op == sim.AND4: logic.bp8v_and(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]) |
|
|
|
|
elif op == sim.NAND2: logic.bp8v_and(self.c[o0], self.c[i0], self.c[i1]); logic.bp8v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.NAND3: logic.bp8v_and(self.c[o0], self.c[i0], self.c[i1], self.c[i2]); logic.bp8v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.NAND4: logic.bp8v_and(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]); logic.bp8v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.OR2: logic.bp8v_or(self.c[o0], self.c[i0], self.c[i1]) |
|
|
|
|
elif op == sim.OR3: logic.bp8v_or(self.c[o0], self.c[i0], self.c[i1], self.c[i2]) |
|
|
|
|
elif op == sim.OR4: logic.bp8v_or(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]) |
|
|
|
|
elif op == sim.NOR2: logic.bp8v_or(self.c[o0], self.c[i0], self.c[i1]); logic.bp8v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.NOR3: logic.bp8v_or(self.c[o0], self.c[i0], self.c[i1], self.c[i2]); logic.bp8v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.NOR4: logic.bp8v_or(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]); logic.bp8v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.XOR2: logic.bp8v_xor(self.c[o0], self.c[i0], self.c[i1]) |
|
|
|
|
elif op == sim.XOR3: logic.bp8v_xor(self.c[o0], self.c[i0], self.c[i1], self.c[i2]) |
|
|
|
|
elif op == sim.XOR4: logic.bp8v_xor(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]) |
|
|
|
|
elif op == sim.XNOR2: logic.bp8v_xor(self.c[o0], self.c[i0], self.c[i1]); logic.bp8v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.XNOR3: logic.bp8v_xor(self.c[o0], self.c[i0], self.c[i1], self.c[i2]); logic.bp8v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.XNOR4: logic.bp8v_xor(self.c[o0], self.c[i0], self.c[i1], self.c[i2], self.c[i3]); logic.bp8v_not(self.c[o0], self.c[o0]) |
|
|
|
|
elif op == sim.AOI21: |
|
|
|
|
logic.bp8v_and(self.c[self.c_locs[self.tmp_idx]], self.c[i0], self.c[i1]) |
|
|
|
|
logic.bp8v_or(self.c[o0], self.c[self.c_locs[self.tmp_idx]], self.c[i2]) |
|
|
|
|
logic.bp8v_not(self.c[o0], self.c[o0]) |
|
|
|
|
else: print(f'unknown op {op}') |
|
|
|
|
if inject_cb is not None: inject_cb(o0, self.s[o0]) |
|
|
|
|
|
|
|
|
@ -139,10 +194,22 @@ def _prop_cpu(ops, c_locs, c):
@@ -139,10 +194,22 @@ def _prop_cpu(ops, c_locs, c):
|
|
|
|
|
if op == sim.BUF1: c[o0]=c[i0] |
|
|
|
|
elif op == sim.INV1: c[o0] = ~c[i0] |
|
|
|
|
elif op == sim.AND2: c[o0] = c[i0] & c[i1] |
|
|
|
|
elif op == sim.AND3: c[o0] = c[i0] & c[i1] & c[i2] |
|
|
|
|
elif op == sim.AND4: c[o0] = c[i0] & c[i1] & c[i2] & c[i3] |
|
|
|
|
elif op == sim.NAND2: c[o0] = ~(c[i0] & c[i1]) |
|
|
|
|
elif op == sim.NAND3: c[o0] = ~(c[i0] & c[i1] & c[i2]) |
|
|
|
|
elif op == sim.NAND4: c[o0] = ~(c[i0] & c[i1] & c[i2] & c[i3]) |
|
|
|
|
elif op == sim.OR2: c[o0] = c[i0] | c[i1] |
|
|
|
|
elif op == sim.OR3: c[o0] = c[i0] | c[i1] | c[i2] |
|
|
|
|
elif op == sim.OR4: c[o0] = c[i0] | c[i1] | c[i2] | c[i3] |
|
|
|
|
elif op == sim.NOR2: c[o0] = ~(c[i0] | c[i1]) |
|
|
|
|
elif op == sim.NOR3: c[o0] = ~(c[i0] | c[i1] | c[i2]) |
|
|
|
|
elif op == sim.NOR4: c[o0] = ~(c[i0] | c[i1] | c[i2] | c[i3]) |
|
|
|
|
elif op == sim.XOR2: c[o0] = c[i0] ^ c[i1] |
|
|
|
|
elif op == sim.XOR3: c[o0] = c[i0] ^ c[i1] ^ c[i2] |
|
|
|
|
elif op == sim.XOR4: c[o0] = c[i0] ^ c[i1] ^ c[i2] ^ c[i3] |
|
|
|
|
elif op == sim.XNOR2: c[o0] = ~(c[i0] ^ c[i1]) |
|
|
|
|
elif op == sim.XNOR3: c[o0] = ~(c[i0] ^ c[i1] ^ c[i2]) |
|
|
|
|
elif op == sim.XNOR4: c[o0] = ~(c[i0] ^ c[i1] ^ c[i2] ^ c[i3]) |
|
|
|
|
elif op == sim.AOI21: c[o0] = ~((c[i0] & c[i1]) | c[i2]) |
|
|
|
|
else: print(f'unknown op {op}') |
|
|
|
|