示例#1
0
    def test_simple(self):
        sel, sel_vals = gen_in(2)

        x1s, x1_vals = (list(x) for x in zip(*(gen_in(8) for i in range(4))))
        x2s, x2_vals = (list(x) for x in zip(*(gen_in(8) for i in range(4))))
        x3s, x3_vals = (list(x) for x in zip(*(gen_in(8) for i in range(4))))

        i1_out = pyrtl.Output(name="i1_out")
        i2_out = pyrtl.Output(name="i2_out")
        i3_out = pyrtl.Output(name="i3_out")

        with muxes.MultiSelector(sel, i1_out, i2_out, i3_out) as mu:
            for i in range(4):
                mu.option(i, x1s[i], x2s[i], x3s[i])

        wires = [sel] + x1s + x2s + x3s
        vals = [sel_vals] + x1_vals + x2_vals + x3_vals
        actual_outputs = utils.sim_and_ret_outws(wires, vals)

        expected_i1_out = [v[s] for s, v in zip(sel_vals, zip(*x1_vals))]
        expected_i2_out = [v[s] for s, v in zip(sel_vals, zip(*x2_vals))]
        expected_i3_out = [v[s] for s, v in zip(sel_vals, zip(*x3_vals))]

        self.assertEqual(actual_outputs[i1_out], expected_i1_out)
        self.assertEqual(actual_outputs[i2_out], expected_i2_out)
        self.assertEqual(actual_outputs[i3_out], expected_i3_out)
示例#2
0
    def test_really_simple(self):
        sel, sel_vals = gen_in(1)

        i1_0, i1_0_vals = gen_in(8)
        i2_0, i2_0_vals = gen_in(8)
        i1_1, i1_1_vals = gen_in(8)
        i2_1, i2_1_vals = gen_in(8)

        i1_out = pyrtl.Output(name="i1_out")
        i2_out = pyrtl.Output(name="i2_out")

        with muxes.MultiSelector(sel, i1_out, i2_out) as mul_sel:
            mul_sel.option(0, i1_0, i2_0)
            mul_sel.option(1, i1_1, i2_1)

        actual_outputs =\
            utils.sim_and_ret_outws([sel, i1_0, i1_1, i2_0, i2_1],
                                    [sel_vals, i1_0_vals, i1_1_vals, i2_0_vals, i2_1_vals])
        expected_i1_out = [
            v1 if s else v0
            for s, v0, v1 in zip(sel_vals, i1_0_vals, i1_1_vals)
        ]
        expected_i2_out = [
            v1 if s else v0
            for s, v0, v1 in zip(sel_vals, i2_0_vals, i2_1_vals)
        ]

        self.assertEqual(actual_outputs[i1_out.name], expected_i1_out)
        self.assertEqual(actual_outputs[i2_out.name], expected_i2_out)
示例#3
0
 def test_incorrect_number_of_wires_2(self):
     sel = pyrtl.Input(1)
     wire = pyrtl.WireVector(8)
     i1_out = pyrtl.Output(name="i1_out")
     i2_out = pyrtl.Output(name="i2_out")
     i3_out = pyrtl.Output(name="i3_out")
     mul_sel = muxes.MultiSelector(sel, i1_out, i2_out, i3_out)
     with self.assertRaises(pyrtl.PyrtlError):
         mul_sel.option(0, wire, wire)
示例#4
0
 def test_value_already_set(self):
     sel = pyrtl.Input(1)
     wire = pyrtl.WireVector(8)
     i1_out = pyrtl.Output(name="i1_out")
     i2_out = pyrtl.Output(name="i2_out")
     with muxes.MultiSelector(sel, i1_out, i2_out) as mul_sel:
         mul_sel.option(0, wire, wire)
         with self.assertRaises(pyrtl.PyrtlError):
             mul_sel.option(0, wire, wire)