From faf41f086338bf2d0611d355c3c1fb883fef2024 Mon Sep 17 00:00:00 2001 From: Stefan Holst Date: Mon, 6 Feb 2023 09:53:44 +0900 Subject: [PATCH] ff transitions switch --- src/kyupy/logic_sim.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/kyupy/logic_sim.py b/src/kyupy/logic_sim.py index 29be2b6..b9f7eed 100644 --- a/src/kyupy/logic_sim.py +++ b/src/kyupy/logic_sim.py @@ -91,13 +91,16 @@ class LogicSim: if line is not None: self.state_epoch[line.reader] = self.epoch return stimuli - def capture(self, responses): + def capture(self, responses, ff_transitions=False): """Capture the current values at the primary outputs and in the state-elements (flip-flops). For primary outputs, the logic value is stored unmodified in the given target array. - For flip-flops, the logic value is constructed from the previous state and the new state. + For flip-flops, the logic value is either stored unmodified (`ff_transitions=False`) + or constructed from the previous state and the new state (`ff_transitions=True`). :param responses: A bit-parallel storage target for the responses in a compatible shape. :type responses: :py:class:`~kyupy.logic.BPArray` + :param ff_transitions: If true, calculate and store the transitions between the previous state + (the currently assigned pattern) and the new state. :returns: The given responses object. """ for node, resp in zip(self.interface, responses.data if hasattr(responses, 'data') else responses): @@ -106,15 +109,16 @@ class LogicSim: resp[...] = self.state[node.outs[0]] else: resp[...] = self.state[node.ins[0]] - # FIXME: unclear why we should use outs for DFFs - #if self.m > 2 and 'dff' in node.kind.lower() and len(node.outs) > 0: - # if node.outs[0] is None: - # resp[1, :] = ~self.state[node.outs[1], 0, :] # assume QN is connected, take inverse of that. - # else: - # resp[1, :] = self.state[node.outs[0], 0, :] - # if self.m > 4: - # resp[..., 2, :] = resp[..., 0, :] ^ resp[..., 1, :] - # # We don't handle X or - correctly. + if not ff_transitions: continue + # outs of DFFs contain the previously assigned value (previous state) + if self.m > 2 and 'dff' in node.kind.lower() and len(node.outs) > 0: + if node.outs[0] is None: + resp[1, :] = ~self.state[node.outs[1], 0, :] # assume QN is connected, take inverse of that. + else: + resp[1, :] = self.state[node.outs[0], 0, :] + if self.m > 4: + resp[..., 2, :] = resp[..., 0, :] ^ resp[..., 1, :] + # FIXME: We don't handle X or - correctly. return responses