1313from decimal import Decimal , ROUND_HALF_UP , ROUND_HALF_EVEN
1414from pprint import pprint
1515
16+
1617def mkMain ():
1718 # input variiable
1819 x = stream .Variable ('xdata' )
@@ -27,7 +28,7 @@ def mkMain():
2728 st = stream .Stream (z )
2829 m = st .to_module ('main' )
2930
30- #st.draw_graph()
31+ # st.draw_graph()
3132
3233 return m , st .pipeline_depth ()
3334
@@ -82,9 +83,9 @@ def mkTest(numports=8):
8283 send_count = m .Reg ('send_count' , 32 , initval = 0 )
8384 send_fsm .If (reset_done ).goto_next ()
8485
85- test_val_boader = [- 2147483648 ,- 10 , 1 , 2147483637 ]
86+ test_val_boader = [- 2147483648 , - 10 , 1 , 2147483637 ]
8687 test_window = 9
87- test_shift = [0 ,1 , 2 , 3 , 15 ,16 ,17 ,30 ,31 ,32 ]
88+ test_shift = [0 , 1 , 2 , 3 , 15 , 16 , 17 , 30 , 31 , 32 ]
8889
8990 for i in test_shift :
9091 for j in test_val_boader :
@@ -101,23 +102,25 @@ def mkTest(numports=8):
101102 Display ('xdata=%d' , xdata ),
102103 Display ('ydata=%d' , ydata )
103104 )
104- send_fsm .goto_next (cond = send_count == test_window )
105+ send_fsm .goto_next (cond = send_count == test_window )
105106
106107 recv_fsm = FSM (m , 'recv_fsm' , clk , rst )
107108 recv_count = m .Reg ('recv_count' , 32 , initval = 0 )
108109 recv_fsm .If (reset_done ).goto_next ()
109110
110- recv_fsm (
111- recv_count (0 ),
112- )
113- recv_fsm .goto_next ()
111+ if latency >= 1 :
112+ recv_fsm (
113+ recv_count (0 ),
114+ )
115+ recv_fsm .goto_next ()
114116
115- recv_fsm .If (recv_count < latency - 2 )(
116- recv_count .inc ()
117- ).Else (
118- recv_count (0 )
119- )
120- recv_fsm .goto_next (cond = recv_count >= latency - 2 )
117+ if latency >= 2 :
118+ recv_fsm .If (recv_count < latency - 2 )(
119+ recv_count .inc ()
120+ ).Else (
121+ recv_count (0 )
122+ )
123+ recv_fsm .goto_next (cond = recv_count >= latency - 2 )
121124
122125 for i in test_shift :
123126 for j in test_val_boader :
@@ -130,7 +133,7 @@ def mkTest(numports=8):
130133 Display ('zdata=%d' , zdata ),
131134 recv_count .inc ()
132135 )
133- recv_fsm .goto_next (cond = recv_count == test_window )
136+ recv_fsm .goto_next (cond = recv_count == test_window )
134137
135138 recv_fsm (
136139 end_of_sim (1 )
@@ -148,15 +151,20 @@ def mkTest(numports=8):
148151 sim = simulation .Simulator (test )
149152 rslt = sim .run () # display=False
150153 #rslt = sim.run(display=True)
151- #print(rslt)
152-
153- vx = list (map (lambda x : int (str .split (x ,"=" )[1 ]), filter (lambda x : "xdata" in x , str .split (rslt , "\n " ))))
154- vy = list (map (lambda x : int (str .split (x ,"=" )[1 ]), filter (lambda x : "ydata" in x , str .split (rslt , "\n " ))))
155- vz = list (map (lambda x : int (str .split (x ,"=" )[1 ]), filter (lambda x : "zdata" in x , str .split (rslt , "\n " ))))
156- ez = list (map (lambda x ,y : int ( Decimal (str (x / (2.0 ** y ))).quantize (Decimal ('0' ), rounding = ROUND_HALF_UP )), vx ,vy ))
157-
158- pprint (list (zip (vx ,vy ,vz ,ez )))
159- assert (all (map (lambda v , e : v == e , vz , ez )))
154+ # print(rslt)
155+
156+ vx = list (map (lambda x : int (str .split (x , "=" )[1 ]), filter (
157+ lambda x : "xdata" in x , str .split (rslt , "\n " ))))
158+ vy = list (map (lambda x : int (str .split (x , "=" )[1 ]), filter (
159+ lambda x : "ydata" in x , str .split (rslt , "\n " ))))
160+ vz = list (map (lambda x : int (str .split (x , "=" )[1 ]), filter (
161+ lambda x : "zdata" in x , str .split (rslt , "\n " ))))
162+ ez = list (map (lambda x , y :
163+ int (Decimal (str (x / (2.0 ** y ))).quantize (
164+ Decimal ('0' ), rounding = ROUND_HALF_UP )), vx , vy ))
165+
166+ pprint (list (zip (vx , vy , vz , ez )))
167+ assert (all (map (lambda v , e : v == e , vz , ez )))
160168
161169 # launch waveform viewer (GTKwave)
162170 # sim.view_waveform() # background=False
0 commit comments