Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pyrtl/corecircuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import itertools
from collections.abc import Iterator, Sequence

from pyrtl.conditional import otherwise
from pyrtl.core import Block, LogicNet, working_block
Expand Down Expand Up @@ -228,7 +229,7 @@ def concat(*args: WireVectorLike) -> WireVector:
return outwire


def concat_list(wire_list: list[WireVectorLike]) -> WireVector:
def concat_list(wire_list: Sequence[WireVectorLike]) -> WireVector:
"""Concatenates a list of :class:`WireVectors<WireVector>` into a single
:class:`WireVector`.

Expand Down Expand Up @@ -706,7 +707,7 @@ def shift_right_logical(
return barrel.barrel_shifter(bits_to_shift, bit_in, dir, shift_amount)


def match_bitwidth(*args: WireVector, signed: bool = False) -> tuple[WireVector]:
def match_bitwidth(*args: WireVector, signed: bool = False) -> Iterator[WireVector]:
"""Matches multiple :class:`WireVector` :attr:`bitwidths<~WireVector.bitwidth>` via
zero- or sign-extension.

Expand Down
2 changes: 1 addition & 1 deletion pyrtl/wire.py
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ def __ior__(self, other: WireVectorLike):
raise PyrtlError(msg)

@next.setter
def next(self, other: WireVectorLike):
def next(self, other: Register._Next):
if not isinstance(other, Register._Next):
msg = 'error, .next should be set with "<<=" or "|=" operators'
raise PyrtlError(msg)
Expand Down
7 changes: 4 additions & 3 deletions www/examples/example-adder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ def adder(
"""n-bit ripple carry adder with carry in and carry out."""
a, b = pyrtl.match_bitwidth(a, b)

sum = [None] * a.bitwidth
sum: list[pyrtl.WireVector] = []
cout = cin
for i in range(a.bitwidth):
sum[i], cout = fa(a[i], b[i], cin)
cin = cout
s, cout = fa(a[i], b[i], cout)
sum.append(s)

full_sum = pyrtl.concat_list(sum)
return full_sum, cout
Expand Down
10 changes: 7 additions & 3 deletions www/examples/example-fir.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pyrtl
import itertools

# # Finite impulse filter example.

Expand All @@ -7,9 +8,12 @@ def fir(x: pyrtl.WireVector, bs: list[int]):
rwidth = x.bitwidth # Bitwidth of the registers.
ntaps = len(bs) # Number of coefficients.

zs = [x] + [pyrtl.Register(rwidth) for _ in range(ntaps - 1)]
for i in range(1, ntaps):
zs[i].next <<= zs[i - 1]
# Create a chain of registers.
regs = [pyrtl.Register(rwidth) for _ in range(ntaps - 1)]
regs[0].next <<= x
for prev, curr in itertools.pairwise(regs):
curr.next <<= prev
zs = [x, *regs]

# Produce the final sum of products.
return sum(z * b for z, b in zip(zs, bs, strict=True))
Expand Down
Loading