Skip to content

Commit e5227a9

Browse files
committed
Merge branch 'feature_stream_generator' into develop
2 parents 6a8af2a + d232c33 commit e5227a9

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed

veriloggen/thread/stream.py

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,9 @@ def sink(self, data, name=None, when=None, when_name=None):
408408
def terminate(self, data):
409409
_id = self.var_id_count
410410
name = terminate_prefix % _id
411-
412411
self.terminates.append(data)
413-
414412
self.sink(data, name)
413+
return data
415414

416415
def parameter(self, name=None, datawidth=None, point=0, signed=True):
417416
if self.stream_synthesized:
@@ -1673,76 +1672,88 @@ def _synthesize_run(self):
16731672
key=lambda x: x[0]):
16741673
done_cond = make_condition(done_cond, source_idle)
16751674

1676-
end_cond = make_condition(done_cond, self.fsm.here)
1675+
source_end_cond = make_condition(done_cond, self.fsm.here)
16771676

16781677
# infinite execution (stream does stop even if all sources are halted.)
16791678
if self.infinite:
1680-
end_cond = vtypes.Int(0, width=1)
1679+
source_end_cond = vtypes.Int(0, width=1)
16811680

16821681
# terminate
1683-
term_cond = None
1682+
source_term_cond = None
16841683
for term in self.terminates:
1685-
v = term.read()
1686-
if term_cond is None:
1687-
term_cond = v
1688-
else:
1689-
term_cond = vtypes.Ors(term_cond, v)
1690-
1691-
if term_cond is not None:
1692-
term_cond = make_condition(term_cond, self.fsm.here, self.valid_list[-1])
1693-
end_cond = vtypes.Ors(end_cond, term_cond)
1684+
stage = term.end_stage
1685+
v = make_condition(term.raw_data, self.valid_list[stage])
16941686

16951687
# force flush
1696-
for valid in self.valid_list:
1697-
self.seq.If(self.oready, term_cond)(
1688+
for valid in self.valid_list[:stage + 1]:
1689+
self.seq.If(self.oready, v)(
16981690
valid(0)
16991691
)
17001692

1693+
if source_term_cond is None:
1694+
source_term_cond = v
1695+
else:
1696+
source_term_cond = vtypes.Ors(source_term_cond, v)
1697+
1698+
if source_term_cond is not None:
1699+
source_end_cond = vtypes.Ors(source_end_cond, source_term_cond)
1700+
1701+
sink_term_cond = None
1702+
for term in self.terminates:
1703+
v = term.read()
1704+
if sink_term_cond is None:
1705+
sink_term_cond = v
1706+
else:
1707+
sink_term_cond = vtypes.Ors(sink_term_cond, v)
1708+
1709+
if sink_term_cond is not None:
1710+
sink_term_cond = make_condition(sink_term_cond, self.valid_list[-1])
1711+
17011712
# source_stop and source_busy
1702-
self.source_stop.assign(vtypes.Ands(self.oready, end_cond))
1713+
self.source_stop.assign(vtypes.Ands(self.oready, source_end_cond))
17031714

1704-
self.fsm.If(self.oready, end_cond)(
1715+
self.fsm.If(self.oready, source_end_cond)(
17051716
self.source_busy(0)
17061717
)
17071718

1708-
self.fsm.If(self.oready, end_cond).goto_init()
1719+
self.fsm.If(self.oready, source_end_cond).goto_init()
17091720

17101721
# restart
1711-
self.fsm.If(self.oready, end_cond, self.run_flag)(
1722+
self.fsm.If(self.oready, source_end_cond, self.run_flag)(
17121723
self.source_start(1)
17131724
)
1714-
self.fsm.If(self.oready, end_cond, self.run_flag).goto(fsm_restart_state)
1725+
self.fsm.If(self.oready, source_end_cond, self.run_flag).goto(fsm_restart_state)
17151726

17161727
# deassert
1717-
self.fsm.seq.If(self.oready, self._delay_from_start_to_ivalid_off(end_cond))(
1728+
self.fsm.seq.If(self.oready, self._delay_from_start_to_ivalid_off(source_end_cond))(
17181729
self.ivalid(0)
17191730
)
17201731

17211732
# reset accumulate pipelines
17221733
if self.reduce_reset is not None:
17231734
cond = vtypes.Ands(self.oready,
1724-
self._delay_from_start_to_reduce_reset_on(end_cond))
1735+
self._delay_from_start_to_reduce_reset_on(source_end_cond))
17251736
self.reduce_reset.write(1, cond=cond)
17261737

17271738
if self.dump:
17281739
dump_delay = self.ram_delay
17291740
self.seq.If(self.oready,
1730-
self._delay_from_start_to_ivalid_off(end_cond))(
1741+
self._delay_from_start_to_ivalid_off(source_end_cond))(
17311742
self.dump_enable(0)
17321743
)
17331744

17341745
self.sink_start.assign(self._delay_from_start_to_sink(self.source_start))
17351746

17361747
# force flush
1737-
if term_cond is not None:
1738-
not_term_cond = vtypes.Not(term_cond)
1739-
masked_source_stop = vtypes.Ands(self.source_stop, not_term_cond)
1740-
sink_stop_value = vtypes.Ors(term_cond,
1748+
if sink_term_cond is not None:
1749+
not_sink_term_cond = vtypes.Not(sink_term_cond)
1750+
masked_source_stop = vtypes.Ands(self.source_stop, not_sink_term_cond)
1751+
sink_stop_value = vtypes.Ors(sink_term_cond,
17411752
self._delay_from_start_to_sink_stop(masked_source_stop))
17421753
self.sink_stop.assign(sink_stop_value)
17431754
self.sink_busy.assign(
17441755
self._delay_from_start_to_sink_busy(self.source_busy,
1745-
self.seq.Prev(term_cond, 1, cond=self.oready)))
1756+
self.seq.Prev(sink_term_cond, 1, cond=self.oready)))
17461757
else:
17471758
sink_stop_value = self._delay_from_start_to_sink_stop(self.source_stop)
17481759
self.sink_stop.assign(sink_stop_value)
@@ -1756,8 +1767,8 @@ def _synthesize_run(self):
17561767
self.busy_reg(1)
17571768
)
17581769

1759-
if term_cond is not None:
1760-
self.seq.If(self.oready, term_cond)(
1770+
if sink_term_cond is not None:
1771+
self.seq.If(self.oready, sink_term_cond)(
17611772
self.busy_reg(0)
17621773
)
17631774

0 commit comments

Comments
 (0)