|
|
|
@ -10,7 +10,7 @@ import math
@@ -10,7 +10,7 @@ import math
|
|
|
|
|
|
|
|
|
|
import numpy as np |
|
|
|
|
|
|
|
|
|
from . import logic, hr_bytes |
|
|
|
|
from . import numba, logic, hr_bytes, sim |
|
|
|
|
from .sim import SimOps, SimPrim |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -148,7 +148,7 @@ class LogicSim(SimOps):
@@ -148,7 +148,7 @@ class LogicSim(SimOps):
|
|
|
|
|
|
|
|
|
|
# return responses |
|
|
|
|
|
|
|
|
|
def c_prop(self, inject_cb=None): |
|
|
|
|
def c_prop(self, sims=None, inject_cb=None): |
|
|
|
|
"""Propagate the input values towards the outputs (Perform all logic operations in topological order). |
|
|
|
|
|
|
|
|
|
If the circuit is sequential (it contains flip-flops), one call simulates one clock cycle. |
|
|
|
@ -168,20 +168,24 @@ class LogicSim(SimOps):
@@ -168,20 +168,24 @@ class LogicSim(SimOps):
|
|
|
|
|
resumes with the manipulated values after the callback returns. |
|
|
|
|
:type inject_cb: ``f(Line, ndarray)`` |
|
|
|
|
""" |
|
|
|
|
if sims is None: sims = self.sims |
|
|
|
|
nbytes = (sims - 1) // 8 + 1 |
|
|
|
|
if self.m == 2: |
|
|
|
|
for op, o0, i0, i1, i2, i3 in self.ops: |
|
|
|
|
o0, i0, i1, i2, i3 = [self.vat[x,0] for x in (o0, i0, i1, i2, i3)] |
|
|
|
|
if op == SimPrim.BUF1: self.c[o0]=self.c[i0] |
|
|
|
|
elif op == SimPrim.INV1: self.c[o0] = ~self.c[i0] |
|
|
|
|
elif op == SimPrim.AND2: self.c[o0] = self.c[i0] & self.c[i1] |
|
|
|
|
elif op == SimPrim.NAND2: self.c[o0] = ~(self.c[i0] & self.c[i1]) |
|
|
|
|
elif op == SimPrim.OR2: self.c[o0] = self.c[i0] | self.c[i1] |
|
|
|
|
elif op == SimPrim.NOR2: self.c[o0] = ~(self.c[i0] | self.c[i1]) |
|
|
|
|
elif op == SimPrim.XOR2: self.c[o0] = self.c[i0] ^ self.c[i1] |
|
|
|
|
elif op == SimPrim.XNOR2: self.c[o0] = ~(self.c[i0] ^ self.c[i1]) |
|
|
|
|
else: print(f'unknown SimPrim {op}') |
|
|
|
|
if inject_cb is not None: inject_cb(o0, self.s[o0]) |
|
|
|
|
pass |
|
|
|
|
if inject_cb is None: |
|
|
|
|
_prop_cpu(self.ops, self.vat, self.c[...,:nbytes]) |
|
|
|
|
else: |
|
|
|
|
for op, o0, i0, i1, i2, i3 in self.ops: |
|
|
|
|
o0, i0, i1, i2, i3 = [self.vat[x,0] for x in (o0, i0, i1, i2, i3)] |
|
|
|
|
if op == SimPrim.BUF1: self.c[o0]=self.c[i0] |
|
|
|
|
elif op == SimPrim.INV1: self.c[o0] = ~self.c[i0] |
|
|
|
|
elif op == SimPrim.AND2: self.c[o0] = self.c[i0] & self.c[i1] |
|
|
|
|
elif op == SimPrim.NAND2: self.c[o0] = ~(self.c[i0] & self.c[i1]) |
|
|
|
|
elif op == SimPrim.OR2: self.c[o0] = self.c[i0] | self.c[i1] |
|
|
|
|
elif op == SimPrim.NOR2: self.c[o0] = ~(self.c[i0] | self.c[i1]) |
|
|
|
|
elif op == SimPrim.XOR2: self.c[o0] = self.c[i0] ^ self.c[i1] |
|
|
|
|
elif op == SimPrim.XNOR2: self.c[o0] = ~(self.c[i0] ^ self.c[i1]) |
|
|
|
|
else: print(f'unknown SimPrim {op}') |
|
|
|
|
inject_cb(o0, self.s[o0]) |
|
|
|
|
elif self.m == 4: |
|
|
|
|
pass |
|
|
|
|
else: |
|
|
|
@ -285,4 +289,18 @@ class LogicSim(SimOps):
@@ -285,4 +289,18 @@ class LogicSim(SimOps):
|
|
|
|
|
# def aoi21_fct(self, inputs, outputs): |
|
|
|
|
# logic.bp_and(self.tmp[0], inputs[0], inputs[1]) |
|
|
|
|
# logic.bp_or(outputs[0], self.tmp[0], inputs[2]) |
|
|
|
|
# logic.bp_not(outputs[0], outputs[0]) |
|
|
|
|
# logic.bp_not(outputs[0], outputs[0]) |
|
|
|
|
|
|
|
|
|
@numba.njit() |
|
|
|
|
def _prop_cpu(ops, vat, c): |
|
|
|
|
for op, o0, i0, i1, i2, i3 in ops: |
|
|
|
|
o0, i0, i1, i2, i3 = [vat[x,0] for x in (o0, i0, i1, i2, i3)] |
|
|
|
|
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.NAND2: c[o0] = ~(c[i0] & c[i1]) |
|
|
|
|
elif op == sim.OR2: c[o0] = c[i0] | c[i1] |
|
|
|
|
elif op == sim.NOR2: c[o0] = ~(c[i0] | c[i1]) |
|
|
|
|
elif op == sim.XOR2: c[o0] = c[i0] ^ c[i1] |
|
|
|
|
elif op == sim.XNOR2: c[o0] = ~(c[i0] ^ c[i1]) |
|
|
|
|
else: print(f'unknown SimPrim {op}') |
|
|
|
|