File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,28 @@ def barrel_shifter(
3232) -> WireVector :
3333 """Create a barrel shifter.
3434
35+ .. doctest only::
36+
37+ >>> import pyrtl
38+ >>> pyrtl.reset_working_block()
39+
40+ Example::
41+
42+ >>> bits_to_shift = pyrtl.Input(name="input", bitwidth=8)
43+ >>> shift_dist = pyrtl.Input(name="shift_dist", bitwidth=3)
44+ >>> output = pyrtl.Output(name="output")
45+
46+ >>> output <<= pyrtl.rtllib.barrel.barrel_shifter(
47+ ... bits_to_shift,
48+ ... bit_in=1,
49+ ... direction=pyrtl.rtllib.barrel.Direction.RIGHT,
50+ ... shift_dist=shift_dist)
51+
52+ >>> sim = pyrtl.Simulation()
53+ >>> sim.step(provided_inputs={"input": 0x55, "shift_dist": 4})
54+ >>> hex(sim.inspect("output"))
55+ '0xf5'
56+
3557 :param bits_to_shift: :class:`.WireVector` with the value to shift.
3658 :param bit_in: A 1-bit :class:`.WireVector` representing the value to shift in.
3759 :param direction: A one bit :class:`.WireVector` representing the shift direction
Original file line number Diff line number Diff line change 1+ import doctest
12import random
23import unittest
34
45import pyrtl
56from pyrtl .rtllib .barrel import Direction , barrel_shifter
67
78
9+ class TestDocTests (unittest .TestCase ):
10+ """Test documentation examples."""
11+
12+ def test_doctests (self ):
13+ failures , tests = doctest .testmod (m = pyrtl .rtllib .barrel )
14+ self .assertGreater (tests , 0 )
15+ self .assertEqual (failures , 0 )
16+
17+
818class TestBarrel (unittest .TestCase ):
919 def setUp (self ):
1020 pyrtl .reset_working_block ()
You can’t perform that action at this time.
0 commit comments