def test_4v(): 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=4) assert len(s.interface) == 5 mva = MVArray(['00000', '01000', '0-000', '0X000', '10000', '11000', '1-000', '1X000', '-0000', '-1000', '--000', '-X000', 'X0000', 'X1000', 'X-000', 'XX000'], m=4) bpa = BPArray(mva) s.assign(bpa) s.propagate() s.capture(bpa) mva = MVArray(bpa) assert mva[0] == '00001' assert mva[1] == '01011' assert mva[2] == '0-0X1' assert mva[3] == '0X0X1' assert mva[4] == '10010' assert mva[5] == '11110' assert mva[6] == '1-X10' assert mva[7] == '1XX10' assert mva[8] == '-00XX' assert mva[9] == '-1X1X' assert mva[10] == '--XXX' assert mva[11] == '-XXXX' assert mva[12] == 'X00XX' assert mva[13] == 'X1X1X' assert mva[14] == 'X-XXX' assert mva[15] == 'XXXXX'
def test_2v(): c = bench.parse('input(x, y) output(a, o, n) a=and(x,y) o=or(x,y) n=not(x)') s = LogicSim(c, 4, m=2) assert len(s.interface) == 5 mva = MVArray(['00000', '01000', '10000', '11000'], m=2) bpa = BPArray(mva) s.assign(bpa) s.propagate() s.capture(bpa) mva = MVArray(bpa) assert mva[0] == '00001' assert mva[1] == '01011' assert mva[2] == '10010' assert mva[3] == '11110'
def test_vd1(): c = bench.parse('input(x, y) output(a, o, n) a=and(x,y) o=or(x,y) n=not(x)') s = LogicSim(c, 4) assert len(s.interface) == 5 p = PackedVectors(4, len(s.interface)) p[0] = '00000' p[1] = '01000' p[2] = '10000' p[3] = '11000' s.assign(p) s.propagate() s.capture(p) assert p[0] == '00001' assert p[1] == '01011' assert p[2] == '10010' assert p[3] == '11110'
def test_b01(mydir): c = bench.parse(mydir / 'b01.bench') # 2-valued s = LogicSim(c, 8) assert len(s.interface) == 9 t = PackedVectors(8, len(s.interface)) t.randomize() s.assign(t) s.propagate() s.capture(t) # 8-valued s = LogicSim(c, 8, 3) t = PackedVectors(8, len(s.interface), 3) t.randomize() s.assign(t) s.propagate() s.capture(t)
def test_8v(): c = bench.parse('input(x, y) output(a, o, n, xo) a=and(x,y) o=or(x,y) n=not(x) xo=xor(x,y)') s = LogicSim(c, 64, m=8) assert len(s.interface) == 6 mva = MVArray(['000010', '010111', '0-0X1X', '0X0X1X', '0R0R1R', '0F0F1F', '0P0P1P', '0N0N1N', '100101', '111100', '1-X10X', '1XX10X', '1RR10F', '1FF10R', '1PP10N', '1NN10P', '-00XXX', '-1X1XX', '--XXXX', '-XXXXX', '-RXXXX', '-FXXXX', '-PXXXX', '-NXXXX', 'X00XXX', 'X1X1XX', 'X-XXXX', 'XXXXXX', 'XRXXXX', 'XFXXXX', 'XPXXXX', 'XNXXXX', 'R00RFR', 'R1R1FF', 'R-XXFX', 'RXXXFX', 'RRRRFP', 'RFPNFN', 'RPPRFR', 'RNRNFF', 'F00FRF', 'F1F1RR', 'F-XXRX', 'FXXXRX', 'FRPNRN', 'FFFFRP', 'FPPFRF', 'FNFNRR', 'P00PNP', 'P1P1NN', 'P-XXNX', 'PXXXNX', 'PRPRNR', 'PFPFNF', 'PPPPNP', 'PNPNNN', 'N00NPN', 'N1N1PP', 'N-XXPX', 'NXXXPX', 'NRRNPF', 'NFFNPR', 'NPPNPN', 'NNNNPP'], m=8) bpa = BPArray(mva) s.assign(bpa) s.propagate() resp_bp = BPArray(bpa) s.capture(resp_bp) resp = MVArray(resp_bp) for i in range(64): assert resp[i] == mva[i]
def test_vd2(): 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, 2) assert len(s.interface) == 5 p = PackedVectors(16, len(s.interface), 2) p[0] = '00000' p[1] = '01000' p[2] = '0-000' p[3] = '0X000' p[4] = '10000' p[5] = '11000' p[6] = '1-000' p[7] = '1X000' p[8] = '-0000' p[9] = '-1000' p[10] = '--000' p[11] = '-X000' p[12] = 'X0000' p[13] = 'X1000' p[14] = 'X-000' p[15] = 'XX000' s.assign(p) s.propagate() s.capture(p) assert p[0] == '00001' assert p[1] == '01011' assert p[2] == '0-0X1' assert p[3] == '0X0X1' assert p[4] == '10010' assert p[5] == '11110' assert p[6] == '1-X10' assert p[7] == '1XX10' assert p[8] == '-00XX' assert p[9] == '-1X1X' assert p[10] == '--XXX' assert p[11] == '-XXXX' assert p[12] == 'X00XX' assert p[13] == 'X1X1X' assert p[14] == 'X-XXX' assert p[15] == 'XXXXX'
def test_b01(mydir): with open(mydir / 'b01.bench', 'r') as f: c = bench.parse(f.read()) assert 92 == len(c.nodes) c = bench.parse(mydir / 'b01.bench') assert 92 == len(c.nodes)
def test_simple(): c = bench.parse('input(a, b) output(z) z=and(a,b)') assert len(c.nodes) == 4 assert len(c.interface) == 3
def test_vd3(): c = bench.parse('input(x, y) output(a, o, n, xo) a=and(x,y) o=or(x,y) n=not(x) xo=xor(x,y)') s = LogicSim(c, 64, 3) assert len(s.interface) == 6 p = PackedVectors(64, len(s.interface), 3) p[0] = '000010' p[1] = '010111' p[2] = '0-0X1X' p[3] = '0X0X1X' p[4] = '0R0R1R' p[5] = '0F0F1F' p[6] = '0P0P1P' p[7] = '0N0N1N' p[8] = '100101' p[9] = '111100' p[10] = '1-X10X' p[11] = '1XX10X' p[12] = '1RR10F' p[13] = '1FF10R' p[14] = '1PP10N' p[15] = '1NN10P' p[16] = '-00XXX' p[17] = '-1X1XX' p[18] = '--XXXX' p[19] = '-XXXXX' p[20] = '-RXXXX' p[21] = '-FXXXX' p[22] = '-PXXXX' p[23] = '-NXXXX' p[24] = 'X00XXX' p[25] = 'X1X1XX' p[26] = 'X-XXXX' p[27] = 'XXXXXX' p[28] = 'XRXXXX' p[29] = 'XFXXXX' p[30] = 'XPXXXX' p[31] = 'XNXXXX' p[32] = 'R00RFR' p[33] = 'R1R1FF' p[34] = 'R-XXFX' p[35] = 'RXXXFX' p[36] = 'RRRRFP' p[37] = 'RFPNFN' p[38] = 'RPPRFR' p[39] = 'RNRNFF' p[40] = 'F00FRF' p[41] = 'F1F1RR' p[42] = 'F-XXRX' p[43] = 'FXXXRX' p[44] = 'FRPNRN' p[45] = 'FFFFRP' p[46] = 'FPPFRF' p[47] = 'FNFNRR' p[48] = 'P00PNP' p[49] = 'P1P1NN' p[50] = 'P-XXNX' p[51] = 'PXXXNX' p[52] = 'PRPRNR' p[53] = 'PFPFNF' p[54] = 'PPPPNP' p[55] = 'PNPNNN' p[56] = 'N00NPN' p[57] = 'N1N1PP' p[58] = 'N-XXPX' p[59] = 'NXXXPX' p[60] = 'NRRNPF' p[61] = 'NFFNPR' p[62] = 'NPPNPN' p[63] = 'NNNNPP' expect = p.copy() s.assign(p) s.propagate() s.capture(p) for i in range(64): assert p[i] == expect[i]
def test_b01(mydir): with open(mydir / 'b01.bench', 'r') as f: c = bench.parse(f.read()) assert len(c.nodes) == 92 c = bench.load(mydir / 'b01.bench') assert len(c.nodes) == 92