def test_loopback(): circ = aigbv.rebundle_aig(aiger.identity(['x[0]', 'x[1]', 'y[0]', 'y[1]'])) circ2 = circ.loopback({'input': 'x', 'output': 'y'}) assert circ2.inputs == {'y'} circ = aigbv.rebundle_aig(aiger.identity(['x[0]', 'x[1]', 'y[0]', 'y[1]'])) circ2 = circ.loopback({'input': 'x', 'output': 'y', 'init': (True, False)}) assert circ2.latch2init['x'] == (True, False)
def test_feedback(): circ = aigbv.rebundle_aig(aiger.identity(['x[0]', 'x[1]', 'y[0]', 'y[1]'])) circ2 = circ.feedback(inputs=['x'], outputs=['y']) assert circ2.inputs == {'y'} circ = aigbv.rebundle_aig(aiger.identity(['x[0]', 'x[1]', 'y[0]', 'y[1]'])) circ2 = circ.feedback(inputs=['x'], outputs=['y'], initials=[(True, False)]) assert circ2.latch2init['x'] == (True, False)
def test_unroll(): circ = aigbv.rebundle_aig(aiger.identity(['x[0]', 'x[1]', 'y[0]', 'y[1]'])) circ2 = circ.feedback(inputs=['x'], outputs=['y']) circ3 = circ2.unroll(3) assert circ3.inputs == {'y##time_0', 'y##time_1', 'y##time_2'} assert circ3.outputs == {'x##time_1', 'x##time_2', 'x##time_3'}
def test_cutlatches(): circ = aigbv.rebundle_aig(aiger.identity(['x[0]', 'x[1]', 'y[0]', 'y[1]'])) circ2 = circ.feedback(inputs=['x'], outputs=['y']) circ3, lmap = circ2.cutlatches(renamer=lambda x: f"{x}##time_0") assert circ3.inputs >= circ2.inputs assert circ3.outputs >= circ2.outputs assert len(lmap) == 1
def identity_gate(wordlen, input='x', output=None): if output is None: output = input imap, omap = BundleMap({input: wordlen}), BundleMap({output: wordlen}) return aigbv.AIGBV( imap=imap, omap=omap, aig=aiger.identity(inputs=imap[input], outputs=omap[output]), )
def index_gate(wordlen, idx, input, output=None): assert 0 <= idx < wordlen if output is None: output = input imap, omap = BundleMap({input: wordlen}), BundleMap({output: 1}) inputs, outputs = imap[input], (imap[input][idx], ) aig = aiger.sink(set(inputs) - set(outputs)) | aiger.identity(outputs) relabels = {outputs[0]: omap[output][0]} return aigbv.AIGBV(imap=imap, omap=omap, aig=aig['o', relabels])
def identity_gate(wordlen, input='x', output=None): if output is None: output = input inputs = named_indexes(wordlen, input) outputs = named_indexes(wordlen, output) return aigbv.AIGBV( aig=aiger.identity(inputs=inputs, outputs=outputs), input_map=frozenset([(input, inputs)]), output_map=frozenset([(output, outputs)]), )
def index_gate(wordlen, idx, input, output=None): assert 0 <= idx < wordlen if output is None: output = input inputs = named_indexes(wordlen, input) outputs = (inputs[idx], ) aig = aiger.sink(set(inputs) - set(outputs)) \ | aiger.identity(outputs) return aigbv.AIGBV( aig=aig, input_map=frozenset([(input, inputs)]), output_map=frozenset([(output, outputs)]), )