[libre-riscv-dev] buffered pipeline
Luke Kenneth Casson Leighton
lkcl at lkcl.net
Tue Mar 19 06:53:28 GMT 2019
this is tolerable / readable:
class ExampleAddRecordStage:
record_spec = [('src1', 16), ('src2', 16)]
def ispec(self):
return Record(self.record_spec)
def ospec(self):
return Record(self.record_spec)
def process(self, i):
return {'src1': i.src1 + 1,
'src2': i.src2 + 1}
the modifications to the eq() function... not so happy: they need
internal knowledge of the Record class:
for (ao, ai) in zip(o, i):
- res.append(ao.eq(ai))
+ #print ("eq", ao, ai)
+ if isinstance(ao, Record):
+ for idx, (field_name, field_shape, _) in enumerate(ao.layout):
+ if isinstance(field_shape, Layout):
+ rres = eq(ao.fields[field_name], ai.fields[field_name])
+ else:
+ rres = eq(ao.fields[field_name], ai[field_name])
+ res += rres
+ else:
+ res.append(ao.eq(ai))
return res
and the unit test is... hmmm...
- o_data = yield self.dut.n.o_data
+ if isinstance(self.dut.n.o_data, Record):
+ o_data = {}
+ dod = self.dut.n.o_data
+ for k, v in dod.fields.items():
+ o_data[k] = yield v
+ else:
+ o_data = yield self.dut.n.o_data
overall, i feel that it's... tolerable.
it should also work recursively (Records as member fields of Records).
the dictionary from process() would need to return a dictionary
containing a dictionary.
i also see no reason why it should not work when the Record is part of
a module. it turns out that you need to explicitly name the Record
fields anyway. yield, interestingly, concatenates all of the bits of
the Record, which turned out to be a pain, hence that identification
in the unit test, to separate them all out (accessing dod.fields
manually).
l.
l.
More information about the libre-riscv-dev
mailing list