-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Circuit sublasses with arguments or verilog modules with parameters #1195
Comments
|
class Xor(m.Circuit):
io = m.IO(
A=m.In(m.Bit),
B=m.In(m.Bit),
C=m.Out(m.Bit)
)
io.C @= io.A ^ io.B
class ShiftRegisterXor(m.Circuit):
io = m.IO(
# This circuit "wraps" some Registers and a Xor instance
# Has one input wired to the first m.Register(m.Bit) and
# another wired to Xor. Output is the output of Xor.
get_io(m.Register(m.Bit), i), # only get inputs of m.Register(m.Bit):
#I=m.In(m.Bit),
get_io(Xor, io, in_prefix='A'), # get IOs but only inputs with prefix:
#A=m.In(m.Bit),
#C=m.Out(m.Bit)
) + m.ClockIO()
O = m.fold([m.Register(m.Bit)() for _ in range(4)], foldargs={"I":"O"})(io.I)
io.C @= Xor()(io.A, O) |
Hi @leonardt, this is a longer question. For the bootcamp, I am trying to show how higher order programming can be used to make the code concise. The log_shifter.py seems like a good candidate (https://github.com/leonardt/magma_examples/blob/master/magma_examples/log_shifter.py).
The idea is to create a new Circuit subclass to define a Register-like circuit that takes a shift_amount argument. The shift_amount determines the left shift which is hard-coded in the original example to 8, 4, 2, and 1. Ex.:
s0.I @= io.I << 8
My attempt:
I suppose this should have been two posts:
Which generates:
A parameterized module could have been:
Do you see this as a worthwhile distinction?
The text was updated successfully, but these errors were encountered: