Compare commits

...

169 Commits
main ... devel

Author SHA1 Message Date
Stefan Holst 88a5c79161 dot fix and updated intro nb 3 days ago
Stefan Holst 9ca437fe47 fault injection for 4v sim, wave_sim test fix 3 days ago
Stefan Holst 0cdaf71963 fix for latest lark 3 days ago
Stefan Holst 75972d7bb2 numba config deprecated 3 days ago
Stefan Holst 469dc18aa9 lark dependency update 3 days ago
stefan 33addab141 fix output with newest numpy 5 days ago
Stefan Holst 674f3dea4a Merge branch 'main' into devel 4 months ago
Stefan Holst 187d176cfd partial ternary if support 5 months ago
Stefan Holst ba1de0bea9 support for per-simulation delay factors 9 months ago
Stefan Holst 5769aa3716 deactivate delta sim 9 months ago
Stefan Holst e97c370d39 support stuck-at fault model injection for 2-valued logic sim 11 months ago
Stefan Holst 3b7106be80 fix deferred assignments 12 months ago
Stefan Holst d2357859f6 more robust matching and assign processing 2 years ago
Stefan Holst 53629c5c28 support injection into specific sims 2 years ago
Stefan Holst e64845e8c0 fanout generator 2 years ago
Stefan Holst da98ca2db7 signal flips in compiled code 2 years ago
Stefan Holst deb4599206 fix tests 2 years ago
Stefan Holst c1c9ec9aae pin_name, cleanup legacy code 2 years ago
Stefan Holst 4c55dcec60 delta sim for improving fault sim performance 2 years ago
Stefan Holst a4b7364478 mux21 in 6v logic sim, more test fixtures 2 years ago
Stefan Holst f59e97afa9 remove hashes, add lst, overflow, ebuf 2 years ago
Stefan Holst f6baf9cb5e a fast 6v sim 2 years ago
Stefan Holst fc030c6708 allow interconnect annotations without forks 2 years ago
Stefan Holst 795cac0716 initial and final values from mvarrays 2 years ago
Stefan Holst 3a8777e0a3 none-filtering iterator for GrowingList 2 years ago
Stefan Holst 68e8cb844a pass line id to inject_cb 2 years ago
Stefan Holst 1a3b91c1c0 fix comment 2 years ago
Stefan Holst aa7536b8b0 line use and diff 2 years ago
Stefan Holst fccf5e0d84 fix log limit 2 years ago
Stefan Holst a6d1e4099c alap toposort, improve tests 2 years ago
Stefan Holst 1654915ed6 support for partial re-sim 2 years ago
Stefan Holst d2a2484efa fix fault injection 2 years ago
Stefan Holst de79393dfc fix log limiter, use eng notation 2 years ago
Stefan Holst 4bb3f3424a cond in sdf parser. ignored for now. 2 years ago
Stefan Holst a6243b43f6 keep s_nodes 2 years ago
Stefan Holst baeb759824 types, perf op growing list, keep s_nodes 2 years ago
Stefan Holst 967a232b1c fix pulse threshold selection 2 years ago
Stefan Holst 8096416b0e save test position for each pattern 2 years ago
Stefan Holst a4cce9f8c0 Produce stable value when trans. to/from - 2 years ago
Stefan Holst 4f6b733eb4 fix NanGate variants, version bump 2 years ago
Stefan Holst 371bc906b3 Merge branch 'main' into devel 2 years ago
Stefan Holst 0ade89defa remove old test data, intro check 2 years ago
Stefan Holst 7f4026f504 def-file docs 2 years ago
Stefan Holst e6a0d59d44 def-file docs 2 years ago
Stefan Holst 63e5f32e21 better ignore 2 years ago
Stefan Holst 35e727e714 better docs, new techlib as default, fix tests 2 years ago
Stefan Holst 83445e2bbd support for newer NANGATE lib 2 years ago
Stefan Holst c67148c0ee doc fix 2 years ago
Stefan Holst 280c425486 fix test 2 years ago
Stefan Holst 5be82da49a avoid holes in forks, update intro 2 years ago
Stefan Holst b3dbe9765a fix xor in libs, remove old code 2 years ago
Stefan Holst 5e573b0408 fix substitute for inputs with fo, dot graph 2 years ago
Stefan Holst 08d9f5a9bf one-bit busses 2 years ago
Stefan Holst b098fb219d fix for unconnected named pins, double-declaration 2 years ago
Stefan Holst 97387e962b add GSC180nm 2 years ago
Stefan Holst f4d875f7e5 docs 2 years ago
Stefan Holst cf9a98b5ce del deprecated sdf code, explicit tlib use 2 years ago
Stefan Holst d8f605a47a fix double-free when fo goes to same cell 2 years ago
Stefan Holst ec5626b8ca remove old connections in substitute node reuse 2 years ago
Stefan Holst 5a693f7b9b preserve node order during resolve 2 years ago
Stefan Holst 19bbe2c260 update intro 2 years ago
Stefan Holst d3897246c5 move resolving cells to circuit, more doc 2 years ago
Stefan Holst 9bda7a4c57 capitalize tech libs 2 years ago
Stefan Holst 2270a9eee7 fix fork stripping + fork None values 2 years ago
Stefan Holst ea45a326ec add latch, fix xor delays, improve test 2 years ago
Stefan Holst 1e9fe7707b saed32nm 2 years ago
Stefan Holst 50a5d8a290 one cell inherits name in substitute, sim fix 2 years ago
Stefan Holst d97555e9e9 fix simprim cells, add saed90 2 years ago
Stefan Holst 47ee8d5878 improve substitute, update notebook output 2 years ago
Stefan Holst c32584fc76 1to1 fork optimization, fix substitute 2 years ago
Stefan Holst 39b8c1695b full constants support, fix signal declarations 2 years ago
Stefan Holst 80d26b6f0b Add AO*211 and OA*211, fix MUX21 2 years ago
Stefan Holst f7ef78e58d support for limiting log messages 2 years ago
Stefan Holst 7afb13b33b mv_str for single values, remove undue assert 2 years ago
Stefan Holst 153442a10a def file parser 2 years ago
Stefan Holst afb0a64953 wsa accumulation in wavesim 2 years ago
Stefan Holst c49667edc1 remove old code, verilog positional pins 2 years ago
Stefan Holst d921eb5048 sim support for remaining primitives 2 years ago
Stefan Holst 670fb0b3fc circuit node substitution 2 years ago
Stefan Holst f8bf579be2 support concat, bus select, ISOL cells 2 years ago
Stefan Holst f61e2b42e8 support more cells in logic sim 2 years ago
Stefan Holst 4aec335abb verilog: concat assignments, more comments 2 years ago
Stefan Holst 1a9cb396bf tweak repr, doc 2 years ago
Stefan Holst 3875dc38f9 docs 2 years ago
Stefan Holst ecb7171c37 docs 2 years ago
Stefan Holst 8957db48ab docs 2 years ago
Stefan Holst 0b15f9fa18 doc improvements 2 years ago
Stefan Holst dc76a9f517 new into demo 2 years ago
Stefan Holst 0968cb451e docs, fix stil unassigned, fix io_locs for busses 2 years ago
Stefan Holst 947df89434 add AOI21 to logic sim 2 years ago
Stefan Holst f17e461fdd fix reading directly from file handle 2 years ago
Stefan Holst d6d981a351 support for det vars 3 years ago
Stefan Holst 7a060b1831 support for static variations 3 years ago
Stefan Holst 03802ac9f8 make sims pickleable 3 years ago
Stefan Holst 70caea065e more cleanup 3 years ago
Stefan Holst f04f1b0012 cleanup 3 years ago
Stefan Holst 44b0c887d7 random sampling of delays 3 years ago
Stefan Holst 4e2022291e fix cuda ppo_to_ppi 3 years ago
Stefan Holst 5566b80e52 simprim, vat refactor, batchrange 3 years ago
stefan 63c0b48537 bump 3 years ago
stefan 6520ee23ef cleanup and new intro notebook 3 years ago
stefan 1810d40959 pytest work without cuda 3 years ago
Stefan Holst 7430ebb068 jitted logic sim 3 years ago
stefan 89f317b463 better circuit statsu, 2v logic sim 3 years ago
Stefan Holst 753ce566e4 Timer improvements, log in yaml 3 years ago
stefan 1eb8d87884 faster logic sim, removing MVArray, BPArray 3 years ago
Stefan Holst 02f3a0e1b2 correct timing padding 3 years ago
Stefan Holst fc8e65e788 bit-packing utility 3 years ago
Stefan Holst d80a3ae2b1 timer utility 3 years ago
Stefan Holst 7bfc02e683 more on-gpu code, bump python requirement 3 years ago
Stefan Holst 8da4a62bce switch to new wave_sim, silence occupancy warnings 3 years ago
Stefan Holst 3497bfdc75 first gpu-code, cached test fixtures 3 years ago
Stefan Holst f1ebe1487c new wave sim 3 years ago
Stefan Holst f0dac36ac7 interface -> io_nodes, io_loc fix 3 years ago
Stefan Holst b2953aef25 only dff 3 years ago
Stefan Holst 3774b14286 support ppi/ppo 3 years ago
Stefan Holst 4847ad9c40 locating io ports and busses by name 3 years ago
Stefan Holst 6801606dca new common scheduler for simulators 3 years ago
Stefan Holst faf41f0863 ff transitions switch 3 years ago
Stefan Holst 6430f10f73 HADD pin index fix 3 years ago
Stefan Holst fa19af8c31 4-input gate simulator 3 years ago
Stefan Holst 93a0858d2f oai and aoi pin handling fix 3 years ago
Stefan Holst 1f2808ee31 Merge branch 'main' into devel 3 years ago
Stefan Holst 163b348a0c year bump 3 years ago
Stefan Holst ecfc692edc support reset RN for scan cells 3 years ago
Stefan Holst afb7e745a1 adding aoi to logic sim 3 years ago
Stefan Holst 6a8841c3c6 revert wave_eval4 3 years ago
Stefan Holst c530983afa accept I as a first input 4 years ago
Stefan Holst 775b13c694 fix off-by-1 pin index when loading AOI and OAI cells 4 years ago
Stefan Holst 584445f3b1 wave eval for 4-input gates 4 years ago
Stefan Holst 85dd02d4d7 interpret N as unassigned in STIL 4 years ago
Stefan Holst 7c03271048 improve robustness of sdf annotation and wave sim 4 years ago
Stefan Holst 8bbaaf8fae comment change 4 years ago
Stefan Holst d59d6401c8 fix stil loading and logic sim capture 4 years ago
Stefan Holst 387c436207 fix tests, version bump 4 years ago
Stefan Holst b981b1153c add sdata to control individual sims 4 years ago
Stefan Holst 87d93afb44 fix time in unpickled log objects 5 years ago
Stefan Holst c3e4090f31 make nodes and lines hashable again 5 years ago
Stefan Holst 0251d66d28 make circuit pickable and comparable 5 years ago
Stefan Holst 864230b883 initial letch support, fix capture in logic sim 5 years ago
Stefan Holst d05841a6a2 Merge branch 'main' into devel 5 years ago
Stefan Holst c5be32d7e5 doc and indent fix 5 years ago
Stefan Holst 8434f5e694 fixes for IWLS benchmark netlists 5 years ago
Stefan Holst 9ff2369a55 fix parsing older stil files 5 years ago
Stefan Holst 82a53e0171 improve techlib for gsclib, better constant handling in verilog parser 5 years ago
Stefan Holst a2df0e5682 fix ff annotation 5 years ago
Stefan Holst ec37e11fef Merge branch 'main' into devel 5 years ago
Stefan Holst 3a5a3c128b year bump 5 years ago
Stefan Holst ee30898cef docs for numba and cuda 5 years ago
Stefan Holst 62cf56e98a TechLib class, remove unnecessary .index 5 years ago
Stefan Holst dc003fa624 documentation improvements 5 years ago
Stefan Holst 8b5a71f498 documentation improvements 5 years ago
Stefan Holst 9c8dee31b9 assign and capture return arrays, new cycle method for common use pattern 5 years ago
Stefan Holst 2bbdf3ee5d fix logic sim of DFF.QN output 5 years ago
Stefan Holst 35cf63cf38 Make Node and Line indexable, documentation. 5 years ago
Stefan Holst ff4de6d782 de-lint and repr improvements 5 years ago
Stefan Holst c12a30328c better hr_time 5 years ago
Stefan Holst 7e6660002b support ibuff in WaveSim 5 years ago
Stefan Holst dfbc35eeb9 logging range fixes 5 years ago
Stefan Holst 4f531fe4cb implement logging range 5 years ago
Stefan Holst 18c17b5f76 more docs and reprs 5 years ago
Stefan Holst 0bad95e94e LogicSim clean-up and new fault injection facility. version bump. 5 years ago
Stefan Holst 7501613951 remove comments 5 years ago
Stefan Holst 5084f1dd8c demo nb run with cuda 5 years ago
Stefan Holst 7f035c1ac5 Migration to new logic value representation 5 years ago
Stefan Holst 7bcfbf502b Documentation, cleanup, multi-valued logic 5 years ago
Stefan Holst 5830608527 Documenting circuit module 5 years ago
Stefan Holst cff18e0915 start documentation 5 years ago
Stefan Holst a77ac4a397 start designing new data structures for m-valued logic 5 years ago
  1. 2
      LICENSE.txt
  2. 4
      docs/conf.py
  3. 1720
      examples/Introduction.ipynb
  4. 4
      pyproject.toml
  5. 2
      src/kyupy/__init__.py
  6. 2
      src/kyupy/bench.py
  7. 9
      src/kyupy/circuit.py
  8. 2
      src/kyupy/logic.py
  9. 27
      src/kyupy/logic_sim.py
  10. 40
      tests/test_logic_sim.py
  11. 6
      tests/test_wave_sim.py

2
LICENSE.txt

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2020-2023 Stefan Holst Copyright (c) 2020-2025 Stefan Holst
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

4
docs/conf.py

@ -20,11 +20,11 @@ sys.path.insert(0, os.path.abspath('../src'))
# -- Project information ----------------------------------------------------- # -- Project information -----------------------------------------------------
project = 'KyuPy' project = 'KyuPy'
copyright = '2020-2023, Stefan Holst' copyright = '2020-2025, Stefan Holst'
author = 'Stefan Holst' author = 'Stefan Holst'
# The full version, including alpha/beta/rc tags # The full version, including alpha/beta/rc tags
release = '0.0.5' release = '0.0.6'
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------

1720
examples/Introduction.ipynb

File diff suppressed because it is too large Load Diff

4
pyproject.toml

@ -1,6 +1,6 @@
[project] [project]
name = "kyupy" name = "kyupy"
version = "0.0.5" version = "0.0.6"
authors = [ authors = [
{ name="Stefan Holst", email="mail@s-holst.de" }, { name="Stefan Holst", email="mail@s-holst.de" },
] ]
@ -9,7 +9,7 @@ readme = "README.rst"
requires_python = ">=3.8" requires_python = ">=3.8"
dependencies = [ dependencies = [
"numpy>=1.17.0", "numpy>=1.17.0",
"lark-parser>=0.8.0", "lark>=1.3.0",
] ]
classifiers = [ classifiers = [
"Development Status :: 3 - Alpha", "Development Status :: 3 - Alpha",

2
src/kyupy/__init__.py

@ -293,8 +293,6 @@ if importlib.util.find_spec('numba') is not None:
try: try:
list(numba.cuda.gpus) list(numba.cuda.gpus)
from numba import cuda from numba import cuda
from numba.core import config
config.CUDA_LOW_OCCUPANCY_WARNINGS = False
except CudaSupportError: except CudaSupportError:
log.warn('Cuda unavailable. Falling back to pure Python.') log.warn('Cuda unavailable. Falling back to pure Python.')
cuda = MockCuda() cuda = MockCuda()

2
src/kyupy/bench.py

@ -21,7 +21,7 @@ class BenchTransformer(Transformer):
def start(self, _): return self.c def start(self, _): return self.c
def parameters(self, args): return [self.c.get_or_add_fork(str(name)) for name in args] def parameters(self, args): return [self.c.get_or_add_fork(str(name)) for name in args if name is not None]
def interface(self, args): self.c.io_nodes.extend(args[0]) def interface(self, args): self.c.io_nodes.extend(args[0])

9
src/kyupy/circuit.py

@ -669,13 +669,16 @@ class Circuit:
ins = '|'.join([f'<i{i}>{i}' for i in range(len(n.ins))]) ins = '|'.join([f'<i{i}>{i}' for i in range(len(n.ins))])
outs = '|'.join([f'<o{i}>{i}' for i in range(len(n.outs))]) outs = '|'.join([f'<o{i}>{i}' for i in range(len(n.outs))])
io = f' [{s_dict[n]}]' if n in s_dict else '' io = f' [{s_dict[n]}]' if n in s_dict else ''
s.node(name=str(n.index), label = f'{{{{{ins}}}|{n.index}{io}\n{n.kind}\n{n.name}|{{{outs}}}}}', shape='record') s.node(name=str(n.index), label = fr'{{{{{ins}}}|{n.index}{io}\n{n.kind}\n{n.name}|{{{outs}}}}}', shape='record')
for l in self.lines: for l in self.lines:
driver, reader = f'{l.driver.index}:o{l.driver_pin}', f'{l.reader.index}:i{l.reader_pin}' driver, reader = f'{l.driver.index}:o{l.driver_pin}', f'{l.reader.index}:i{l.reader_pin}'
if node_level[l.driver] >= node_level[l.reader]: if node_level[l.driver] == node_level[l.reader]:
s.node(f'_{l.index}_')
dot.edge(driver, f'_{l.index}_', style='dotted', label=str(l.index))
dot.edge(f'_{l.index}_', reader, style='dotted', label=str(l.index))
elif node_level[l.driver] > node_level[l.reader]:
dot.edge(driver, reader, style='dotted', label=str(l.index)) dot.edge(driver, reader, style='dotted', label=str(l.index))
pass
else: else:
dot.edge(driver, reader, label=str(l.index)) dot.edge(driver, reader, label=str(l.index))

2
src/kyupy/logic.py

@ -114,7 +114,7 @@ def mvarray(*a):
def mv_str(mva, delim='\n'): def mv_str(mva, delim='\n'):
"""Renders a given multi-valued array into a string. """Renders a given multi-valued array into a string.
""" """
sa = np.choose(mva, np.array([*'0X-1PRFN'], dtype=np.unicode_)) sa = np.choose(mva, np.array([*'0X-1PRFN'], dtype=np.str_))
if not hasattr(mva, 'ndim') or mva.ndim == 0: return sa if not hasattr(mva, 'ndim') or mva.ndim == 0: return sa
if mva.ndim == 1: return ''.join(sa) if mva.ndim == 1: return ''.join(sa)
return delim.join([''.join(c) for c in sa.swapaxes(-1,-2)]) return delim.join([''.join(c) for c in sa.swapaxes(-1,-2)])

27
src/kyupy/logic_sim.py

@ -43,6 +43,7 @@ class LogicSim(sim.SimOps):
Access this array to assign new values to the (P)PIs or read values from the (P)POs. Access this array to assign new values to the (P)PIs or read values from the (P)POs.
""" """
self.s[:,:,1,:] = 255 # unassigned self.s[:,:,1,:] = 255 # unassigned
self._full_mask = np.full(self.c.shape[-1], 255, dtype=np.uint8)
def __repr__(self): def __repr__(self):
return f'{{name: "{self.circuit.name}", sims: {self.sims}, m: {self.m}, c_bytes: {eng(self.c.nbytes)}}}' return f'{{name: "{self.circuit.name}", sims: {self.sims}, m: {self.m}, c_bytes: {eng(self.c.nbytes)}}}'
@ -61,20 +62,22 @@ class LogicSim(sim.SimOps):
:param inject_cb: A callback function for manipulating intermediate signal values. :param inject_cb: A callback function for manipulating intermediate signal values.
This function is called with a line and its new logic values (in bit-parallel format) after This function is called with a line and its new logic values (in bit-parallel format) after
evaluation of a node. The callback may manipulate the given values in-place, the simulation evaluation of a node. The callback may manipulate the given values in-place, the simulation
resumes with the manipulated values after the callback returns. resumes with the manipulated values after the callback returns. Specifying this callback
may reduce performance as it disables jit compilation.
:type inject_cb: ``f(Line, ndarray)`` :type inject_cb: ``f(Line, ndarray)``
""" """
t0 = self.c_locs[self.tmp_idx] fault_line = int(fault_line)
t1 = self.c_locs[self.tmp2_idx]
if self.m == 2:
if inject_cb is None:
if fault_mask is None: if fault_mask is None:
fault_mask = np.full(self.c.shape[-1], 255, dtype=np.uint8) fault_mask = self._full_mask # default: full mask
else: else:
if len(fault_mask) < self.c.shape[-1]: if len(fault_mask) < self.c.shape[-1]: # pad mask with 0's if necessary
fault_mask2 = np.full(self.c.shape[-1], 0, dtype=np.uint8) fault_mask2 = np.full(self.c.shape[-1], 0, dtype=np.uint8)
fault_mask2[:len(fault_mask)] = fault_mask fault_mask2[:len(fault_mask)] = fault_mask
fault_mask = fault_mask2 fault_mask = fault_mask2
t0 = self.c_locs[self.tmp_idx]
t1 = self.c_locs[self.tmp2_idx]
if self.m == 2:
if inject_cb is None:
_prop_cpu(self.ops, self.c_locs, self.c, int(fault_line), fault_mask, int(fault_model)) _prop_cpu(self.ops, self.c_locs, self.c, int(fault_line), fault_mask, int(fault_model))
else: else:
for op, o0l, i0l, i1l, i2l, i3l in self.ops[:,:6]: for op, o0l, i0l, i1l, i2l, i3l in self.ops[:,:6]:
@ -190,6 +193,15 @@ class LogicSim(sim.SimOps):
logic.bp4v_or(self.c[o0], self.c[t0], self.c[t1]) logic.bp4v_or(self.c[o0], self.c[t0], self.c[t1])
else: print(f'unknown op {op}') else: print(f'unknown op {op}')
if inject_cb is not None: inject_cb(o0l, self.c[o0]) if inject_cb is not None: inject_cb(o0l, self.c[o0])
if fault_line >= 0 and o0l == fault_line:
if fault_model == 0:
self.c[o0] = self.c[o0] & ~fault_mask[np.newaxis]
elif fault_model == 1:
self.c[o0] = self.c[o0] | fault_mask[np.newaxis]
else:
self.c[t0, 0] = ~(self.c[o0, 0] & self.c[o0, 1] & fault_mask)
self.c[o0, 1] = ~self.c[o0, 0] & ~self.c[o0, 1] & fault_mask
self.c[o0, 0] = self.c[t0, 0]
else: else:
for op, o0l, i0l, i1l, i2l, i3l in self.ops[:,:6]: for op, o0l, i0l, i1l, i2l, i3l in self.ops[:,:6]:
o0, i0, i1, i2, i3 = [self.c_locs[x] for x in (o0l, i0l, i1l, i2l, i3l)] o0, i0, i1, i2, i3 = [self.c_locs[x] for x in (o0l, i0l, i1l, i2l, i3l)]
@ -343,7 +355,6 @@ def _prop_cpu(ops, c_locs, c, fault_line, fault_mask, fault_model):
elif op == sim.MUX21: c[o0] = (c[i0] & ~c[i2]) | (c[i1] & c[i2]) elif op == sim.MUX21: c[o0] = (c[i0] & ~c[i2]) | (c[i1] & c[i2])
else: print(f'unknown op {op}') else: print(f'unknown op {op}')
if fault_line >= 0 and o0l == fault_line: if fault_line >= 0 and o0l == fault_line:
#n = len(fault_mask)
if fault_model == 0: if fault_model == 0:
c[o0] = c[o0] & ~fault_mask c[o0] = c[o0] & ~fault_mask
elif fault_model == 1: elif fault_model == 1:

40
tests/test_logic_sim.py

@ -75,7 +75,7 @@ def test_2v():
def test_4v(): def test_4v():
c = bench.parse('input(x, y) output(a, o, n) a=and(x,y) o=or(x,y) n=not(x)') c = bench.parse('input(x, y) output(a, o, n) a=and(x,y) o=or(x,y) n=not(x)')
s = LogicSim(c, 16, m=8) # FIXME: m=4 s = LogicSim(c, 16, m=4)
assert s.s_len == 5 assert s.s_len == 5
bpa = bparray( bpa = bparray(
'00---', '01---', '0----', '0X---', '00---', '01---', '0----', '0X---',
@ -93,6 +93,44 @@ def test_4v():
'--0XX', '--X1X', '--XXX', '--XXX', '--0XX', '--X1X', '--XXX', '--XXX',
'--0XX', '--X1X', '--XXX', '--XXX')) '--0XX', '--X1X', '--XXX', '--XXX'))
def test_4v_fault():
c = bench.parse('input(x, y) output(a) a=and(x,y)')
s = LogicSim(c, 16, m=4)
assert s.s_len == 3
bpa = bparray(
'00-', '01-', '0--', '0X-',
'10-', '11-', '1--', '1X-',
'-0-', '-1-', '---', '-X-',
'X0-', 'X1-', 'X--', 'XX-')
s.s[0] = bpa
s.s_to_c()
s.c_prop()
s.c_to_s()
mva = bp_to_mv(s.s[1])
assert_equal_shape_and_contents(mva, mvarray(
'--0', '--0', '--0', '--0',
'--0', '--1', '--X', '--X',
'--0', '--X', '--X', '--X',
'--0', '--X', '--X', '--X'))
fault_line = s.circuit.cells['a'].ins[0]
s.s_to_c()
s.c_prop(fault_line=fault_line, fault_model=1)
s.c_to_s()
mva = bp_to_mv(s.s[1])
assert_equal_shape_and_contents(mva, mvarray(
'--0', '--1', '--X', '--X',
'--0', '--1', '--X', '--X',
'--0', '--1', '--X', '--X',
'--0', '--1', '--X', '--X'))
s.s_to_c()
s.c_prop(fault_line=fault_line, fault_model=0)
s.c_to_s()
mva = bp_to_mv(s.s[1])
assert_equal_shape_and_contents(mva, mvarray(
'--0', '--0', '--0', '--0',
'--0', '--0', '--0', '--0',
'--0', '--0', '--0', '--0',
'--0', '--0', '--0', '--0'))
def test_6v(): def test_6v():
c = bench.parse('input(x, y) output(a, o, n, xo, no) a=AND2(x,y) o=OR2(x,y) n=INV1(x) xo=XOR2(x,y) no=NOR2(x,y)') c = bench.parse('input(x, y) output(a, o, n, xo, no) a=AND2(x,y) o=OR2(x,y) n=INV1(x) xo=XOR2(x,y) no=NOR2(x,y)')

6
tests/test_wave_sim.py

@ -25,10 +25,11 @@ def test_xnor2_delays():
delays[0, 1, 1, 1] = 0.036 # B fall -> Z fall delays[0, 1, 1, 1] = 0.036 # B fall -> Z fall
simctl_int = np.asarray([0], dtype=np.int32) simctl_int = np.asarray([0], dtype=np.int32)
simctl_float = np.asarray([1], dtype=np.float32)
def wave_assert(inputs, output): def wave_assert(inputs, output):
for i, a in zip(inputs, c.reshape(-1,16)): a[:len(i)] = i for i, a in zip(inputs, c.reshape(-1,16)): a[:len(i)] = i
wave_eval_cpu(op, c, c_locs, c_caps, ebuf, 0, delays, simctl_int, 0, 0) wave_eval_cpu(op, c, c_locs, c_caps, ebuf, 0, delays, simctl_int, simctl_float, 0, 0)
for i, v in enumerate(output): np.testing.assert_allclose(c.reshape(-1,16)[2,i], v) for i, v in enumerate(output): np.testing.assert_allclose(c.reshape(-1,16)[2,i], v)
wave_assert([[TMIN,TMAX],[TMIN,TMAX]], [TMIN,TMAX]) # XNOR(1,1) => 1 wave_assert([[TMIN,TMAX],[TMIN,TMAX]], [TMIN,TMAX]) # XNOR(1,1) => 1
@ -63,10 +64,11 @@ def test_nand_delays():
delays[0, 3, :, 1] = 0.8 delays[0, 3, :, 1] = 0.8
simctl_int = np.asarray([0], dtype=np.int32) simctl_int = np.asarray([0], dtype=np.int32)
simctl_float = np.asarray([1], dtype=np.float32)
def wave_assert(inputs, output): def wave_assert(inputs, output):
for i, a in zip(inputs, c.reshape(-1,16)): a[:len(i)] = i for i, a in zip(inputs, c.reshape(-1,16)): a[:len(i)] = i
wave_eval_cpu(op, c, c_locs, c_caps, ebuf, 0, delays, simctl_int, 0, 0) wave_eval_cpu(op, c, c_locs, c_caps, ebuf, 0, delays, simctl_int, simctl_float, 0, 0)
for i, v in enumerate(output): np.testing.assert_allclose(c.reshape(-1,16)[4,i], v) for i, v in enumerate(output): np.testing.assert_allclose(c.reshape(-1,16)[4,i], v)
wave_assert([[TMAX,TMAX],[TMAX,TMAX],[TMIN,TMAX],[TMIN,TMAX]], [TMIN,TMAX]) # NAND(0,0,1,1) => 1 wave_assert([[TMAX,TMAX],[TMAX,TMAX],[TMIN,TMAX],[TMIN,TMAX]], [TMIN,TMAX]) # NAND(0,0,1,1) => 1

Loading…
Cancel
Save