Skip to content

Commit 634ce50

Browse files
committed
Update SraRound circuit
1 parent 0566609 commit 634ce50

File tree

3 files changed

+1200
-179
lines changed

3 files changed

+1200
-179
lines changed

tests/extension/stream_/sra_round/stream_sra_round.py

Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from veriloggen import *
1111
import veriloggen.stream as stream
1212

13+
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
14+
#from pprint import pprint
1315

1416
def mkMain():
1517
# input variiable
@@ -25,14 +27,14 @@ def mkMain():
2527
st = stream.Stream(z)
2628
m = st.to_module('main')
2729

28-
return m
30+
return m, st.pipeline_depth()
2931

3032

3133
def mkTest(numports=8):
3234
m = Module('test')
3335

3436
# target instance
35-
main = mkMain()
37+
main, latency = mkMain()
3638

3739
params = m.copy_params(main)
3840
ports = m.copy_sim_ports(main)
@@ -43,6 +45,8 @@ def mkTest(numports=8):
4345
xdata = ports['xdata']
4446
ydata = ports['ydata']
4547
zdata = ports['zdata']
48+
xdata.signed = True
49+
zdata.signed = True
4650

4751
uut = m.Instance(main, 'uut',
4852
params=m.connect_params(main),
@@ -51,8 +55,10 @@ def mkTest(numports=8):
5155
reset_done = m.Reg('reset_done', initval=0)
5256
reset_stmt = []
5357
reset_stmt.append(reset_done(0))
54-
reset_stmt.append(xdata(-128))
55-
reset_stmt.append(ydata(1))
58+
reset_stmt.append(xdata(0))
59+
reset_stmt.append(ydata(0))
60+
61+
end_of_sim = m.Reg('end_of_sim', initval=0)
5662

5763
simulation.setup_waveform(m, uut)
5864
simulation.setup_clock(m, clk, hperiod=5)
@@ -64,44 +70,69 @@ def mkTest(numports=8):
6470
Delay(1000),
6571
reset_done(1),
6672
nclk(clk),
67-
Delay(100000),
73+
Delay(10),
74+
Event(Posedge(end_of_sim)),
75+
Delay(100),
6876
Systask('finish'),
6977
)
7078

7179
send_fsm = FSM(m, 'send_fsm', clk, rst)
72-
send_count = m.Reg('send_count', 32, initval=-128)
80+
send_count = m.Reg('send_count', 32, initval=0)
7381
send_fsm.If(reset_done).goto_next()
7482

75-
for i in range(8):
76-
send_fsm(
77-
xdata(-128),
78-
ydata(i),
79-
send_count(-128),
80-
)
81-
send_fsm.goto_next()
82-
send_fsm(
83+
test_val_boader = [-2147483648,-10, 1, 2147483637]
84+
test_window = 9
85+
test_shift = [0,1,2,3,15,16,17,30,31,32]
86+
87+
for i in test_shift:
88+
for j in test_val_boader:
89+
send_fsm(
90+
xdata(j),
91+
ydata(i),
92+
send_count(0),
93+
)
94+
send_fsm.goto_next()
95+
96+
send_fsm(
8397
xdata(xdata + 1),
84-
Display('xdata=%d', xdata),
85-
Display('ydata=%d', ydata),
86-
send_count.inc()
87-
)
88-
send_fsm.If(send_count == 127).goto_next()
98+
send_count.inc(),
99+
Display('xdata=%d', xdata),
100+
Display('ydata=%d', ydata)
101+
)
102+
send_fsm.goto_next(cond=send_count==test_window)
89103

90104
recv_fsm = FSM(m, 'recv_fsm', clk, rst)
91105
recv_count = m.Reg('recv_count', 32, initval=0)
92106
recv_fsm.If(reset_done).goto_next()
93107

94-
for i in range(8):
95-
recv_fsm(
96-
recv_count(-128)
97-
)
98-
recv_fsm.goto_next()
108+
recv_fsm(
109+
recv_count(0),
110+
)
111+
recv_fsm.goto_next()
99112

100-
recv_fsm(
101-
Display('zdata=%d', zdata),
102-
recv_count.inc()
103-
)
104-
recv_fsm.If(recv_count == 127 + 10).goto_next()
113+
recv_fsm.If(recv_count < latency-2)(
114+
recv_count.inc()
115+
).Else(
116+
recv_count(0)
117+
)
118+
recv_fsm.goto_next(cond=recv_count>=latency-2)
119+
120+
for i in test_shift:
121+
for j in test_val_boader:
122+
recv_fsm(
123+
recv_count(0),
124+
)
125+
recv_fsm.goto_next()
126+
127+
recv_fsm(
128+
Display('zdata=%d', zdata),
129+
recv_count.inc()
130+
)
131+
recv_fsm.goto_next(cond=recv_count==test_window)
132+
133+
recv_fsm(
134+
end_of_sim(1)
135+
)
105136

106137
return m
107138

@@ -117,6 +148,14 @@ def mkTest(numports=8):
117148
#rslt = sim.run(display=True)
118149
print(rslt)
119150

151+
vx = list(map(lambda x: int(str.split(x,"=")[1]), filter(lambda x: "xdata" in x , str.split(rslt, "\n"))))
152+
vy = list(map(lambda x: int(str.split(x,"=")[1]), filter(lambda x: "ydata" in x , str.split(rslt, "\n"))))
153+
vz = list(map(lambda x: int(str.split(x,"=")[1]), filter(lambda x: "zdata" in x , str.split(rslt, "\n"))))
154+
ez = list(map(lambda x,y: int( Decimal(str(x/(2.0**y))).quantize(Decimal('0'), rounding=ROUND_HALF_UP)), vx,vy))
155+
156+
#pprint(list(zip(lx,ly,lz,ez)))
157+
assert(all(map(lambda v, e: v==e, vz, ez)))
158+
120159
# launch waveform viewer (GTKwave)
121160
# sim.view_waveform() # background=False
122161
# sim.view_waveform(background=True)

0 commit comments

Comments
 (0)