Skip to content

Commit 7d37670

Browse files
authored
Merge pull request #30 from lp6m/issues/54-define_new_counter
Issues/54 add interval option to stypes.Counter
2 parents d5c3030 + b9f19bc commit 7d37670

File tree

13 files changed

+120
-79
lines changed

13 files changed

+120
-79
lines changed

tests/extension/thread_/stream_counter/thread_stream_counter.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ def mkLed():
2525
ram_c = vthread.RAM(m, 'ram_c', clk, rst, datawidth, addrwidth)
2626

2727
strm = vthread.Stream(m, 'mystream', clk, rst)
28-
cnt = strm.Counter()
28+
cnt1 = strm.Counter()
29+
cnt2 = strm.Counter(initval=1)
30+
cnt3 = strm.Counter(initval=2, size=3)
31+
cnt4 = strm.Counter(initval=3, interval=3)
32+
cnt5 = strm.Counter(initval=4, interval=3, size=4)
33+
cnt6 = strm.Counter(initval=4, step=2, interval=2)
2934
a = strm.source('a')
3035
b = strm.source('b')
31-
c = a + b + cnt
36+
c = a + b - a - b + cnt1 + cnt2 + cnt3 + cnt4 + cnt5 + cnt6
3237
strm.sink(c, 'c')
3338

3439
def comp_stream(size, offset):
@@ -39,14 +44,19 @@ def comp_stream(size, offset):
3944
strm.join()
4045

4146
def comp_sequential(size, offset):
42-
sum = 0
4347
cnt = 0
4448
for i in range(size):
49+
cnt1 = cnt
50+
cnt2 = 1 + cnt
51+
cnt3 = cnt%3 + 2
52+
cnt4 = (cnt//3) + 3
53+
cnt5 = (cnt//3)%4 + 4
54+
cnt6 = (cnt//2)*2 + 4
4555
a = ram_a.read(i + offset)
4656
b = ram_b.read(i + offset)
47-
cnt += 1
48-
sum = a + b + cnt
57+
sum = a + b - a - b + cnt1 + cnt2 + cnt3 + cnt4 + cnt5 + cnt6
4958
ram_c.write(i + offset, sum)
59+
cnt += 1
5060

5161
def check(size, offset_stream, offset_seq):
5262
all_ok = True

tests/extension/thread_/stream_graph_ringbuffer_multi/thread_stream_graph_ringbuffer_multi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def mkLed():
4646
#b = a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
4747
b = strm.AddN(a0, a1, a2, a3, a4, a5, a6, a7, a8)
4848

49-
strm.sink(b, 'b', when=counter > img_width + img_width + 2)
49+
strm.sink(b, 'b', when=counter >= img_width + img_width + 2)
5050

5151
def comp_stream(size, offset):
5252
strm.set_source('a', ram_a, offset, size * 3)

tests/extension/thread_/stream_graph_scratchpad_multi/thread_stream_graph_scratchpad_multi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def mkLed():
2929
counter = strm.Counter()
3030

3131
a = strm.source('a')
32-
a_addr = strm.Counter() - 1
32+
a_addr = strm.Counter()
3333
sp = strm.Scratchpad(a, a_addr, length=128)
3434

3535
a0 = a
@@ -49,7 +49,7 @@ def mkLed():
4949
#b = a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
5050
b = strm.AddN(a0, a1, a2, a3, a4, a5, a6, a7, a8)
5151

52-
strm.sink(b, 'b', when=counter > img_width + img_width + 2)
52+
strm.sink(b, 'b', when=counter >= img_width + img_width + 2)
5353

5454
def comp_stream(size, offset):
5555
strm.set_source('a', ram_a, offset, size * 3)

tests/extension/thread_/stream_read_ram_counter/thread_stream_read_ram_counter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def mkLed():
2828
strm = vthread.Stream(m, 'mystream', clk, rst)
2929

3030
a = strm.source('a')
31-
r_addr = strm.Counter() - 1
31+
r_addr = strm.Counter()
3232
r_addr = strm.Mux(r_addr < 3, 3, r_addr)
3333

3434
r = strm.read_RAM('ext', r_addr)

tests/extension/thread_/stream_ringbuffer/thread_stream_ringbuffer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def mkLed():
3535

3636
b = a + a_old
3737

38-
strm.sink(b, 'b', when=counter > img_width)
38+
strm.sink(b, 'b', when=counter >= img_width)
3939

4040
def comp_stream(size, offset):
4141
strm.set_source('a', ram_a, offset, size * 2)

tests/extension/thread_/stream_ringbuffer_multi/thread_stream_ringbuffer_multi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def mkLed():
4646
#b = a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
4747
b = strm.AddN(a0, a1, a2, a3, a4, a5, a6, a7, a8)
4848

49-
strm.sink(b, 'b', when=counter > img_width + img_width + 2)
49+
strm.sink(b, 'b', when=counter >= img_width + img_width + 2)
5050

5151
def comp_stream(size, offset):
5252
strm.set_source('a', ram_a, offset, size * 3)

tests/extension/thread_/stream_ringbuffer_reuse/thread_stream_ringbuffer_reuse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def mkLed():
3636

3737
b = a + a_old
3838

39-
strm.sink(b, 'b', when=counter > wait_num)
39+
strm.sink(b, 'b', when=counter >= wait_num)
4040

4141
def comp_stream(size, offset):
4242
strm.set_source('a', ram_a, offset, size * 2)

tests/extension/thread_/stream_scratchpad/thread_stream_scratchpad.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ def mkLed():
2929
counter = strm.Counter()
3030

3131
a = strm.source('a')
32-
a_addr = strm.Counter() - 1
32+
a_addr = strm.Counter()
3333

3434
sp = strm.Scratchpad(a, a_addr, length=128)
3535

36-
a_old_addr = strm.Counter() - img_width - 1
36+
a_old_addr = strm.Counter() - img_width
3737
a_old = sp.read(a_old_addr)
3838

3939
b = a + a_old
4040

41-
strm.sink(b, 'b', when=counter > img_width)
41+
strm.sink(b, 'b', when=counter >= img_width)
4242

4343
def comp_stream(size, offset):
4444
strm.set_source('a', ram_a, offset, size * 2)

tests/extension/thread_/stream_scratchpad_multi/thread_stream_scratchpad_multi.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def mkLed():
2929
counter = strm.Counter()
3030

3131
a = strm.source('a')
32-
a_addr = strm.Counter() - 1
32+
a_addr = strm.Counter()
3333
sp = strm.Scratchpad(a, a_addr, length=128)
3434

3535
a0 = a
@@ -49,7 +49,7 @@ def mkLed():
4949
#b = a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8
5050
b = strm.AddN(a0, a1, a2, a3, a4, a5, a6, a7, a8)
5151

52-
strm.sink(b, 'b', when=counter > img_width + img_width + 2)
52+
strm.sink(b, 'b', when=counter >= img_width + img_width + 2)
5353

5454
def comp_stream(size, offset):
5555
strm.set_source('a', ram_a, offset, size * 3)

tests/extension/thread_/stream_scratchpad_when/thread_stream_scratchpad_when.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ def mkLed():
2929
counter = strm.Counter()
3030

3131
a = strm.source('a')
32-
a_addr = strm.Counter() - 1
32+
a_addr = strm.Counter()
3333

3434
sp = strm.Scratchpad(a, a_addr, when=counter <= img_width, length=128)
3535

36-
a_old_addr = strm.Counter() - img_width - 1
36+
a_old_addr = strm.Counter() - img_width
3737
a_old = sp.read(a_old_addr)
3838

3939
b = a + a_old
4040

41-
strm.sink(b, 'b', when=counter > img_width)
41+
strm.sink(b, 'b', when=counter >= img_width)
4242

4343
def comp_stream(size, offset):
4444
strm.set_source('a', ram_a, offset, size * 2)

0 commit comments

Comments
 (0)