Skip to content

Commit 9bd536b

Browse files
wanda-phiwhitequark
authored andcommitted
hdl._ir: fix SwitchValue LHS lowering.
1 parent 572d546 commit 9bd536b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

amaranth/hdl/_ir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1076,7 +1076,7 @@ def emit_assign(self, module_idx: int, cd: "_cd.ClockDomain | None", lhs: _ast.V
10761076
conds.append(_nir.Net.from_const(1))
10771077
elems.append(elem)
10781078
conds = _nir.Value(conds)
1079-
cell = _nir.PriorityMatch(module_idx, en=_nir.Net.from_const(1),
1079+
cell = _nir.PriorityMatch(module_idx, en=cond,
10801080
inputs=conds, src_loc=lhs.src_loc)
10811081
conds = self.netlist.add_value_cell(len(conds), cell)
10821082
for subcond, val in zip(conds, elems):

tests/test_hdl_ir.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,41 @@ def test_switchvalue(self):
16621662
)
16631663
""")
16641664

1665+
def test_mux_en(self):
1666+
s1 = Signal(8)
1667+
s2 = Signal(8)
1668+
s3 = Signal(8)
1669+
s4 = Signal(8)
1670+
en = Signal()
1671+
m = Module()
1672+
with m.If(en):
1673+
m.d.comb += Mux(s1, s2, s3).eq(s4)
1674+
nl = build_netlist(Fragment.get(m, None), ports=[s1, s2, s3, s4, en])
1675+
self.assertRepr(nl, """
1676+
(
1677+
(module 0 None ('top')
1678+
(input 's1' 0.2:10)
1679+
(input 's4' 0.10:18)
1680+
(input 'en' 0.18)
1681+
(output 's2' 6.0:8)
1682+
(output 's3' 5.0:8)
1683+
)
1684+
(cell 0 0 (top
1685+
(input 's1' 2:10)
1686+
(input 's4' 10:18)
1687+
(input 'en' 18:19)
1688+
(output 's2' 6.0:8)
1689+
(output 's3' 5.0:8)
1690+
))
1691+
(cell 1 0 (matches 0.18 1))
1692+
(cell 2 0 (priority_match 1 1.0))
1693+
(cell 3 0 (matches 0.2:10 00000000))
1694+
(cell 4 0 (priority_match 2.0 (cat 3.0 1'd1)))
1695+
(cell 5 0 (assignment_list 8'd0 (4.0 0:8 0.10:18)))
1696+
(cell 6 0 (assignment_list 8'd0 (4.1 0:8 0.10:18)))
1697+
)
1698+
""")
1699+
16651700
def test_sliced_slice(self):
16661701
s1 = Signal(12)
16671702
s2 = Signal(4)

0 commit comments

Comments
 (0)