Esempio n. 1
0
    def test_two_way_fanout_small_design(self):
        i = pyrtl.Input(1, 'i')
        o, p, q = pyrtl.output_list('o p q')
        o <<= ~i
        p <<= i
        q <<= i & 0

        self.assertEqual(pyrtl.fanout(i), 3)
        pyrtl.two_way_fanout()
        self.check_all_leq_two()
Esempio n. 2
0
    def test_two_way_fanout_large_design(self):
        i, j = pyrtl.input_list('i/1 j/2')
        o, p, q, r = pyrtl.output_list('o p q r')
        o <<= ~i
        p <<= i * j
        q <<= i & 0
        r <<= i - 3

        self.assertEqual(pyrtl.fanout(i), 4)
        pyrtl.two_way_fanout()
        self.check_all_leq_two()
Esempio n. 3
0
    def test_two_way_fanout_medium_design(self):
        i = pyrtl.Input(1, 'i')
        o, p = pyrtl.output_list('o p')
        w = i & 0
        x = (w & w) ^ w
        o <<= x
        p <<= w

        self.assertEqual(pyrtl.fanout(w), 4)
        pyrtl.two_way_fanout()
        self.check_all_leq_two()
Esempio n. 4
0
    def test_two_paths_to_two_outputs(self):
        a = pyrtl.Input(4, 'a')
        o1, o2 = pyrtl.output_list('o1/5 o1/8')
        o1 <<= a + 1
        o2 <<= a * 2

        paths = pyrtl.paths(a)
        paths_from_a = paths[a]
        self.assertEqual(len(paths_from_a), 2)
        path_to_o1 = paths_from_a[o1]
        self.assertEqual(len(path_to_o1), 1)
        path_to_o2 = paths_from_a[o2]
        self.assertEqual(len(path_to_o2), 1)
Esempio n. 5
0
    def test_several_outputs(self):
        i, j = pyrtl.input_list('i/2 j/2')
        o, p, q = pyrtl.output_list('o p q')
        o <<= i * j
        w = i + 2
        p <<= w
        q <<= ~w

        self.assertEqual(len(pyrtl.working_block().logic), 9)
        self.assertEqual(len(pyrtl.working_block().logic_subset(op='w')), 3)
        pyrtl.direct_connect_outputs()
        self.assertEqual(len(pyrtl.working_block().logic), 6)
        self.assertEqual(len(pyrtl.working_block().logic_subset(op='w')), 0)
Esempio n. 6
0
    def test_some_outputs_unaffected(self):
        i = pyrtl.Input(2, 'i')
        o, p, q = pyrtl.output_list('o/4 p/4 q/2')
        w = i * 2
        o <<= w
        p <<= w
        q <<= ~i

        src_nets, _ = pyrtl.working_block().net_connections()
        self.assertEqual(src_nets[o].op, 'w')
        self.assertEqual(src_nets[p].op, 'w')
        self.assertEqual(src_nets[q].op, 'w')
        self.assertEqual(len(pyrtl.working_block().logic), 5)

        pyrtl.direct_connect_outputs()
        src_nets, _ = pyrtl.working_block().net_connections()
        self.assertEqual(src_nets[o].op, 'w')
        self.assertEqual(src_nets[p].op, 'w')
        self.assertEqual(src_nets[q].op, '~')
        self.assertEqual(len(pyrtl.working_block().logic), 4)
Esempio n. 7
0
    def test_all_paths(self):
        a, b, c = pyrtl.input_list('a/2 b/4 c/1')
        o, p = pyrtl.output_list('o/4 p/2')
        o <<= a + (b ^ (b + 1))
        p <<= c * 2 - a

        paths = pyrtl.paths()

        # We have entries for every input, output pair
        for start in (a, b, c):
            self.assertEqual(len(paths[start]), 2)
            self.assertTrue([w.name for w in paths[start].keys()], [o.name, p.name])

        paths_a_to_o = paths[a][o]
        self.assertEqual(len(paths_a_to_o), 1)
        path_a_to_o = paths_a_to_o[0]
        self.assertEqual(path_a_to_o[0].op, 'c')
        self.assertEqual(path_a_to_o[1].op, '+')
        self.assertEqual(path_a_to_o[2].op, 's')

        paths_a_to_p = paths[a][p]
        self.assertEqual(len(paths_a_to_p), 1)
        path_a_to_p = paths_a_to_p[0]
        self.assertEqual(path_a_to_p[0].op, 'c')
        self.assertEqual(path_a_to_p[1].op, '-')
        self.assertEqual(path_a_to_p[2].op, 's')

        paths_b_to_o = paths[b][o]
        self.assertEqual(len(paths_b_to_o), 2)
        paths_b_to_p = paths[b][p]
        self.assertEqual(len(paths_b_to_p), 0)

        paths_c_to_o = paths[c][o]
        self.assertEqual(len(paths_c_to_o), 0)
        paths_c_to_p = paths[c][p]
        self.assertEqual(len(paths_c_to_p), 1)
Esempio n. 8
0
    def test_several_outputs_simulates_correctly(self):
        i, j = pyrtl.input_list('i/2 j/2')
        o, p, q = pyrtl.output_list('o p q')
        o <<= i * j
        w = i + 2
        p <<= w
        q <<= ~w

        inputs = [(0, 1), (1, 0), (2, 3), (3, 0), (1, 3)]
        trace_pre = pyrtl.SimulationTrace()
        sim = pyrtl.Simulation(tracer=trace_pre)
        for x, y in inputs:
            inp_map = {'i': x, 'j': y}
            sim.step(inp_map)

        pyrtl.direct_connect_outputs()

        trace_post = pyrtl.SimulationTrace()
        sim = pyrtl.Simulation(tracer=trace_post)
        for x, y in inputs:
            inp_map = {'i': x, 'j': y}
            sim.step(inp_map)

        self.assertEqual(trace_pre.trace, trace_post.trace)