+ # Generate and check expected values for all possible partition sizes.
+ for w in range(1, mwidth+1):
+ with m.If(p_width == w):
+ # calculate the expected output, for the given bit width
+ bit_width = w * step
+ expected = Signal(bit_width, name=f"expected_{w}")
+ for b in range(w):
+ # lower nibble is the position
+ comb += expected[b*8:b*8+4].eq(b+1)
+ # upper nibble is the partition width
+ comb += expected[b*8+4:b*8+8].eq(w)
+ # truncate the output, compare and assert
+ comb += Assert(p_output[:bit_width] == expected)