@@ -987,21 +987,40 @@ def enum_mux(
987987) -> WireVector :
988988 """Build a mux for the control signals specified by an :class:`enum.IntEnum`.
989989
990- .. WARNING::
990+ .. note::
991+
992+ Consider using :ref:`conditional_assignment` instead.
993+
994+ .. doctest only::
995+
996+ >>> import pyrtl
997+ >>> pyrtl.reset_working_block()
998+
999+ Example::
1000+
1001+ >>> from enum import IntEnum
1002+ >>> class Command(IntEnum):
1003+ ... ADD = 0
1004+ ... SUB = 1
9911005
992- Use :ref:`conditional_assignment` instead.
1006+ >>> command = pyrtl.Input(name="command", bitwidth=1)
1007+ >>> a = pyrtl.Input(name="a", bitwidth=4)
1008+ >>> b = pyrtl.Input(name="b", bitwidth=4)
1009+ >>> output = pyrtl.Output(name="output")
9931010
994- Examples::
1011+ >>> output <<= pyrtl.enum_mux(cntrl=command, table={
1012+ ... Command.ADD: a + b,
1013+ ... Command.SUB: a - b,
1014+ ... })
9951015
996- from enum import IntEnum
1016+ >>> sim = pyrtl.Simulation()
1017+ >>> sim.step(provided_inputs={"command": Command.ADD, "a": 1, "b": 2})
1018+ >>> sim.inspect("output")
1019+ 3
9971020
998- class Command(IntEnum):
999- ADD = 1
1000- SUB = 2
1001- enum_mux(cntrl, {Command.ADD: a + b, Command.SUB: a - b})
1002- enum_mux(cntrl, {Command.ADD: a + b}, strict=False) # SUB case undefined
1003- enum_mux(cntrl, {Command.ADD: a + b, otherwise: a - b})
1004- enum_mux(cntrl, {Command.ADD: a + b}, default=a - b)
1021+ >>> sim.step(provided_inputs={"command": Command.SUB, "a": 5, "b": 3})
1022+ >>> sim.inspect("output")
1023+ 2
10051024
10061025 :param cntrl: Control for the mux.
10071026 :param table: Maps :class:`enum.IntEnum` values to :class:`WireVector`.
0 commit comments