-
Notifications
You must be signed in to change notification settings - Fork 58
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
Const Record value? #261
Comments
There's no such functionality currently; |
That sounds useful. As it is now, I'll just make a class that can pack and generate unpack statements during elaborate time. |
Basically something like this: class StepStruct(Object):
def __init__(self, (step, arg1, arg2, next_cycle, next_step)):
self.step = Const(step)
self.arg1 = Const(arg1)
self.arg2 = Const(arg2)
self.next_cycle = Const(next_cycle)
self.next_step = Const(next_step, shape=unsigned(10))
def _as_const(self):
return Cat(self.step, self.arg1, self.arg2, self.next_cycle,
self.next_step)._as_const()
def uncat(self, m, value, (step, arg1, arg2, next_cycle, next_step)):
m.d.comb += Cat(step, arg1, arg2, next_cycle, next_step).eq(value) |
I don't understand what's that supposed to do. Also, |
Can you keep |
Just like any other function starting with |
Also, to be clear—if |
Suppose I have a bunch of structured values that I want to put into a memory. Memories can only store values of a given width. Therefore, I need to convert my structured values into a single value of fixed width. Now, I can do that using something like this: class StepStruct(Object):
def __init__(self, (step, arg1, arg2, next_cycle, next_step)):
self.step = Const(step)
self.arg1 = Const(arg1)
self.arg2 = Const(arg2)
self.next_cycle = Const(next_cycle)
self.next_step = Const(next_step, shape=unsigned(10))
self.parts = [self.step, self.arg1, self.arg2, self.next_cycle, self.next_step]
def value(self):
value = 0
for part in reversed(self.parts):
value <<= len(part)
value |= part.value
return value Ok, a = [(Step.X, Arg.A, Arg.B, Cycle.C, 10),
(Step.Y, Arg.A, Arg.Z, Cycle.D, 20),
...
]
mem_init_val = [StepStruct(v).value() for v in a]
# Now I can finally initialize the memory Next, I need to take a value out of memory and break it up. That would be very convenient with a m.d.comb += Cat(step, a1, a2, nc, ns).eq(mem[addr]) So what should I do instead? |
Isn't |
Hmm, I see where you can get the shape of a |
The fields are sequential and without gaps, so you can just sum the widths while you're iterating through the fields. |
Hmm.... I don't see anything in the code that makes that obvious, so I can't really rely on that. Where in the code is that implemented? |
This is the basic contract of |
OK, just so I make sure I understand: that means the layout of Layout([
("first", unsigned(8)),
("second", unsigned(16))
]) is the same as |
Correct. (In fact, a |
Sounds good, thanks! |
Suppose I have a
Layout
with various fields:Now I'd like to construct a Python integer for a specific setting for the fields in the
Layout
. I know it needs to be 24 bits. How do I construct such a value?The ultimate goal is to initialize a
Memory
with lots of these values, then be able to read the memory and load aRecord
with the value from memory.The text was updated successfully, but these errors were encountered: