HDLRuby 3.7.8 → 3.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,390 @@
1
+ require 'std/sequencer.rb'
2
+
3
+ include HDLRuby::High::Std
4
+
5
+ # Checking the usage of hardware enumerable capabilities.
6
+ # - The first check is for hall?
7
+ # - The second check is for hany?
8
+ # - The third check is for hchain
9
+ # - The forth check is for hmap
10
+ # - The fifth check is for hmap with hwith_index
11
+ # - The sixth check is for hcompact
12
+ # - The seventh checks is for hcount
13
+ # - The eighth check is for hcycle
14
+ # - The nineth check is for hfind
15
+ # - The tenth check is for hdrop and hdrop_while
16
+ # - The eleventh check is for heach_cons
17
+ # - The twelveth check is for heach_slice
18
+ # - The thirteenth check is for hto_a
19
+ # - The forteenth check is for hselect
20
+ # - The fifteenth check is for hfind_index
21
+ # - The sixteenth check is for hfirst
22
+ # - The seventeenth check is for hinject
23
+ # - The eighteenth check is for hmax
24
+ # - The nineteenth check is for hmax_by
25
+ # - The twentieth check is for hmax_by
26
+ # - The twenty firth check is for hmin
27
+ # - The twenty second check is for hmin_by
28
+ # - The twenty third check is for hminmax and hminmax_by
29
+ # - The twenty fourth check is for hnone?
30
+ # - The twenty fifth check is for hone?
31
+ # - The twenty sixth check is for hreverse_each
32
+ # - The twenty seventh check is for hsort and hsort_by
33
+ # - The twenty eighth check is for hsum
34
+ # - The twenty nineth check is for htake and htake_while
35
+ # - The thirtieth check is for suniq
36
+ # - The thirty first check is for hzip
37
+ #
38
+ # - The remaing checks the enumerators apply on values directly.
39
+ #
40
+
41
+ system :henmerable_checks do
42
+
43
+ inner :clk,:rst
44
+
45
+ bit[8][-8].inner vals: [ _h00, _h10, _hA5, _h0B, _hFE, _h34, _h5C, _h44 ]
46
+ rvals = 8.times.to_a.reverse
47
+
48
+ [16].inner :res0, :res1, :res2, :res3
49
+
50
+ res0 <= vals.hall? { |val| val != _h11 }
51
+ res1 <= vals.hall? { |val| val != _h5C }
52
+
53
+ par(clk.posedge) do
54
+ # hprint("#0\n")
55
+ res2 <= rvals.hall? { |val| val.to_expr != 11 }
56
+ res3 <= rvals.hall? { |val| val.to_expr != 4 }
57
+ # hprint("#1 res0=",res0," res1=",res1," res2=",res2," res3=",res3,"\n")
58
+ end
59
+
60
+ [16].inner :res4, :res5, :res6, :res7
61
+
62
+ res4 <= vals.hany? { |val| val == _h11 }
63
+ res5 <= vals.hany? { |val| val == _h5C }
64
+
65
+ par(clk.posedge) do
66
+ # hprint("$0\n")
67
+ res6 <= rvals.hany? { |val| val == 11 }
68
+ res7 <= rvals.hany? { |val| val == 4 }
69
+ # hprint("#1 res4=",res4," res5=",res5," res6=",res6," res7=",res7,"\n")
70
+ end
71
+
72
+ [16].inner :res8, :res9, :res10, :res11
73
+
74
+ res8 <= vals.hchain(0..10).hany? { |val| val.as(bit[8]) == _h11 }
75
+ res9 <= vals.hchain(0..10).hany? { |val| val.as(bit[8]) == _h05 }
76
+
77
+ par(clk.posedge) do
78
+ # hprint("!0\n")
79
+ res10 <= rvals.hchain(vals).hany? { |val| val.as(bit[8]) == _h11 }
80
+ res11 <= rvals.hchain(vals).hany? { |val| val.as(bit[8]) == _h04 }
81
+ end
82
+
83
+ bit[8][-8].inner :res12, :res13
84
+
85
+ res12 <= vals.hmap { |val| val + 1 }
86
+
87
+ par(clk.posedge) do
88
+ # hprint("%0\n");
89
+ res13 <= vals.hmap { |val| val + 1 }
90
+ end
91
+
92
+ bit[8][-8].inner :res14, :res15
93
+
94
+ res14 <= vals.hmap.hwith_index { |val,i| val + i }
95
+
96
+ par(clk.posedge) do
97
+ # hprint("&0\n");
98
+ res15 <= vals.hmap.hwith_index { |val,i| val + i }
99
+ end
100
+
101
+ bit[8][-8].inner vals2: [ _h00, _h10, _h00, _h0B, _hFE, _h00, _h5C, _h00 ]
102
+ # bit[8][-8].inner :res16, :res17
103
+
104
+ # res16 <= vals2.hcompact
105
+
106
+ # sequencer(clk.posedge,rst) do
107
+ # # hprint("|0\n");
108
+ # res17 <= vals2.hcompact
109
+ # end
110
+
111
+ [8].inner :res18, :res19, :res20
112
+
113
+ res18 <= vals2.hcount
114
+ res19 <= vals2.hcount(_h00)
115
+
116
+ par(clk.posedge) do
117
+ # hprint("(0\n");
118
+ res20 <= vals2.hcount {|elem| elem > _h10 }
119
+ end
120
+
121
+ # [8].inner :res21, :res22
122
+
123
+ # vals.hcycle(2) { |elem| res21 <= elem }
124
+
125
+ # par(clk.posedge) do
126
+ # # hprint(")0\n")
127
+ # vals2.hcycle { |elem| res22 <= elem }
128
+ # end
129
+
130
+ [8].inner :res23, :res24
131
+
132
+ res23 <= vals.hfind(proc {-1}) { |elem| elem > _h00 }
133
+
134
+ par(clk.posedge) do
135
+ # hprint("=0\n")
136
+ res24 <= vals.hfind(proc {-1}) { |elem| elem == _hAA }
137
+ end
138
+
139
+ bit[8][-8].inner :res25 #, :res26
140
+
141
+ res25 <= vals.hdrop(3)
142
+
143
+ # par(clk.posedge) do
144
+ # # hprint("+0\n")
145
+ # res26 <= vals.hdrop_while { |elem| elem < _hAA }
146
+ # end
147
+
148
+ bit[8][-8].inner :res27
149
+
150
+ par(clk.posedge) do
151
+ # hprint("*0\n")
152
+ vals.heach_cons(3).hwith_index { |(a,b,c),i| res27[i] <= a+b+c }
153
+ end
154
+
155
+ bit[8][-8].inner :res28
156
+
157
+ par(clk.posedge) do
158
+ # hprint("/0\n")
159
+ vals.heach_slice(3).hwith_index do |(a,b,c),i|
160
+ if c then
161
+ res28[i] <= a+b+c
162
+ elsif b then
163
+ res28[i] <= a+b
164
+ else
165
+ res28[i] <= a
166
+ end
167
+ end
168
+ end
169
+
170
+ bit[32][-4].inner :res29
171
+
172
+ par(clk.posedge) do
173
+ # hprint("~0\n")
174
+ res29 <= (_h00000001.._h00000004).heach.hto_a
175
+ end
176
+
177
+ [8].inner :res30, :res31, :res31x
178
+
179
+ res30 <= vals.hfind_index(_h0B)
180
+
181
+ par(clk.posedge) do
182
+ # hprint(">0\n")
183
+ res31 <= vals.hfind_index { |elem| elem < _hAA }
184
+ res31x <= vals.hfind_index { |elem| elem == _hAA }
185
+ end
186
+
187
+ bit[8][-4].inner :res32
188
+
189
+ par(clk.posedge) do
190
+ # hprint("<0\n")
191
+ res32 <= vals.hfirst(4)
192
+ end
193
+
194
+ inner :res33, :res34
195
+
196
+ res33 <= vals.hinclude?(_h0B)
197
+
198
+ par(clk.posedge) do
199
+ # hprint("!0\n")
200
+ res34 <= vals.hinclude?(_hAA)
201
+ end
202
+
203
+ [8].inner :res35, :res36
204
+
205
+ res35 <= vals.hinject(_h01) { |a,b| a+b }
206
+
207
+ par(clk.posedge) do
208
+ # hprint(":0\n")
209
+ res36 <= vals.(:+)
210
+ end
211
+
212
+ [8].inner :res37
213
+ bit[8][-3].inner :res38
214
+
215
+ res37 <= vals.hmax
216
+
217
+ par(clk.posedge) do
218
+ # hprint(";0\n")
219
+ # res38 <= vals.hmax(3)
220
+ res38 <= vals.hmax(1)
221
+ end
222
+
223
+ [8].inner :res39
224
+ # bit[8][-3].inner :res40
225
+ [8].inner :res40
226
+
227
+ res39 <= vals.hmax_by {|e| e.to_signed }
228
+
229
+ par(clk.posedge) do
230
+ # hprint(",0\n")
231
+ # res40 <= vals.hmax_by(3) {|e| e.to_signed }
232
+ res40 <= vals.hmax_by(1) {|e| e.to_signed }
233
+ end
234
+
235
+ [8].inner :res41
236
+ bit[8][-3].inner :res42
237
+
238
+ res41 <= vals.hmin
239
+
240
+ par(clk.posedge) do
241
+ # hprint(".0\n")
242
+ # res42 <= vals.hmin(3)
243
+ res42 <= vals.hmin(1)
244
+ end
245
+
246
+ [8].inner :res43
247
+ bit[8][-3].inner :res44
248
+
249
+ res43 <= vals.hmin_by {|e| e.to_signed }
250
+
251
+ par(clk.posedge) do
252
+ # hprint(":0\n")
253
+ # res44 <= vals.hmin_by(3) {|e| e.to_signed }
254
+ res44 <= vals.hmin_by(1) {|e| e.to_signed }
255
+ end
256
+
257
+ [16].inner :res45, :res46
258
+
259
+ res45 <= vals.hminmax
260
+
261
+ par(clk.posedge) do
262
+ # hprint("]0\n")
263
+ res46 <= vals.hminmax_by {|e| e.to_signed }
264
+ end
265
+
266
+ [8].inner :res47, :res48
267
+
268
+ res47 <= vals.hnone? { |val| val == _h11 }
269
+
270
+ par(clk.posedge) do
271
+ # hprint("[0\n")
272
+ res48 <= vals.hnone?(_h5C)
273
+ end
274
+
275
+ [8].inner :res49, :res50, :res51
276
+
277
+ res49 <= vals.hone?(_h5C)
278
+
279
+ par(clk.posedge) do
280
+ # hprint("[0\n")
281
+ res50 <= vals.hone? { |val| val == _h11 }
282
+ res51 <= vals2.hone? { |val| val == _h00 }
283
+ end
284
+
285
+ bit[8][-6].inner :res52
286
+
287
+ par(clk.posedge) do
288
+ # hprint("_0\n")
289
+ (5..10).hreverse_each.hwith_index { |val,i| res52[i] <= val }
290
+ end
291
+
292
+ bit[8][-10].inner :res53X, :res54X
293
+ bit[8][-8].inner :res53, :res54
294
+ bit[8][-10].inner valsX: [ _h00, _h10, _hA5, _h0B, _hFE, _h34, _h5C, _h44, _h01, _h82 ]
295
+
296
+ res53 <= vals.hsort
297
+ res54 <= vals.hsort_by { |val| val.to_signed }
298
+
299
+ seq(clk.posedge) do
300
+ # hprint("@0\n")
301
+ res53X <= valsX.hsort
302
+ res54X <= valsX.hsort_by(_h7F) { |val| val.to_signed }
303
+ end
304
+
305
+ [8].inner :res55, :res56
306
+
307
+ res55 <= vals.hsum
308
+
309
+ par(clk.posedge) do
310
+ # hprint("`0\n")
311
+ res56 <= vals.hsum { |val| val & _h0F }
312
+ end
313
+
314
+ bit[8][-3].inner :res57
315
+ # bit[8][-8].inner :res58
316
+
317
+ res57 <= vals.htake(3)
318
+
319
+ # par(clk.posedge) do
320
+ # # hprint("`0\n")
321
+ # res58 <= vals.htake_while { |val| val < _hAA }
322
+ # end
323
+
324
+ bit[8][-8].inner vals3: [ _hFE, _h10, _hA5, _h10, _hFE, _h34, _h5C, _h10 ]
325
+
326
+ # bit[8][-8].inner :res59,:res60
327
+
328
+ # res59 <= vals3.huniq
329
+
330
+ # # par(clk.posedge) do
331
+ # # # hprint("~0\n")
332
+ # # res60 <= vals.huniq { |val| val & _h0F }
333
+ # # end
334
+
335
+ bit[8][-8].inner :res61
336
+ bit[8][-8].inner :res62
337
+
338
+ res61 <= vals.hzip((1..6).to_a.map {|i| i.to_expr.as(bit[8]) })
339
+
340
+ par(clk.posedge) do
341
+ # hprint("}0\n")
342
+ vals.hzip([_h12]*8).each_with_index { |(a,b),i| res62[i] <= a+b }
343
+ end
344
+
345
+ # Test enumerators of values.
346
+ inner :res63, :res64, :res65
347
+
348
+ res63 <= _b0101011.(:|)
349
+ res64 <= _b0101011.(:^)
350
+ res65 <= _b0101011.(:&)
351
+
352
+ [8].inner :res66
353
+
354
+ res66 <= [_h01, _h02, _h03, _h04].(:+)
355
+
356
+
357
+ # Test signal declarations within iterator block.
358
+ vals.heach do |v,i|
359
+ inner :sig
360
+ sig <= v[0]
361
+ end
362
+
363
+ [_h0001, _h0002, _h0003].heach.hwith_index do |v,i|
364
+ [16].inner :sig
365
+ sig <= v + i
366
+ end
367
+
368
+
369
+
370
+ timed do
371
+ clk <= 0
372
+ rst <= 0
373
+ !10.ns
374
+ clk <= 1
375
+ !10.ns
376
+ clk <= 0
377
+ rst <= 1
378
+ !10.ns
379
+ clk <= 1
380
+ !10.ns
381
+ clk <= 0
382
+ rst <= 0
383
+ !10.ns
384
+ clk <= 1
385
+ repeat(500) do
386
+ !10.ns
387
+ clk <= ~clk
388
+ end
389
+ end
390
+ end
@@ -0,0 +1,107 @@
1
+
2
+
3
+ # A benchmark for testing hif with value condition: the sould produce
4
+ # meta programming.
5
+ system :with_seq_if_bench do
6
+ inner :clk
7
+ [2].inner :s
8
+ [8].inner :x,:y, :z
9
+ [8].inner :u,:v, :w
10
+ [8].inner :a, :b
11
+
12
+ hif(9) do
13
+ puts "hif(9)"
14
+ [8].inner q: 6
15
+ seq do
16
+ hif(s==2) { x <= 1 }
17
+ end
18
+ end
19
+ helse do
20
+ [8].inner r: 6
21
+ puts "hif(9) helse"
22
+ seq do
23
+ hif(s==1) { x <= 2 }
24
+ end
25
+ end
26
+
27
+ hif(0) do
28
+ puts "hif(0)"
29
+ [8].inner q: 7
30
+ seq do
31
+ hif(s==2) { y <= 1 }
32
+ end
33
+ end
34
+ helse do
35
+ [8].inner r: 7
36
+ puts "hif(0) helse"
37
+ seq do
38
+ hif(s==1) { y <= 2 }
39
+ end
40
+ end
41
+
42
+ hif(0) do
43
+ puts "hif(0)"
44
+ [8].inner q: 9
45
+ z <= 0
46
+ end
47
+ helsif(2) do
48
+ puts "hif(0) helsif(2)"
49
+ [8].inner r: 9
50
+ z <= 4
51
+ end
52
+ helse do
53
+ puts "hif(0) helsif(2) helse"
54
+ [8].inner t: 9
55
+ z <= 5
56
+ end
57
+
58
+ hcase(2)
59
+ hwhen(0) { puts "hcase(2) hwhen(0)"; [8].inner(q: 13); u <= 0 }
60
+ hwhen(1) { puts "hcase(2) hwhen(1)"; [8].inner(q: 14); u <= 1 }
61
+ hwhen(2) { puts "hcase(2) hwhen(2)"; [8].inner(q: 15); u <= 2 }
62
+ helse { puts "hcase(2) helse" ; [8].inner(q: 16); u <= 3 }
63
+
64
+ hcase(4)
65
+ hwhen(0) { puts "hcase(4) hwhen(0)"; [8].inner(r: 13); v <= 0 }
66
+ hwhen(1) { puts "hcase(4) hwhen(1)"; [8].inner(r: 14); v <= 1 }
67
+ hwhen(2) { puts "hcase(4) hwhen(2)"; [8].inner(r: 15); v <= 2 }
68
+ helse { puts "hcase(4) helse" ; [8].inner(r: 16); v <= 3 }
69
+
70
+ seq(clk.posedge) do
71
+ hif(6) do
72
+ [8].inner q: 20
73
+ puts "hif(6)"
74
+ w <= w + 1
75
+ end
76
+ end
77
+
78
+ seq(mux(1,s,clk.posedge)) do
79
+ a <= a + 1
80
+ end
81
+
82
+ seq(mux(0,s,clk.posedge)) do
83
+ b <= b + 1
84
+ end
85
+
86
+
87
+
88
+ timed do
89
+ clk <= 0
90
+ w <= 0
91
+ a <= 0
92
+ b <= 0
93
+ !10.ns
94
+ clk <= ~clk
95
+ s <= 0
96
+ !10.ns
97
+ clk <= ~clk
98
+ s <= 1
99
+ !10.ns
100
+ clk <= ~clk
101
+ s <= 2
102
+ !10.ns
103
+ clk <= ~clk
104
+ s <= 3
105
+ !10.ns
106
+ end
107
+ end
data/lib/HDLRuby/hdrcc.rb CHANGED
@@ -549,12 +549,23 @@ $optparse = OptionParser.new do |opts|
549
549
  end
550
550
  $optparse.parse!
551
551
 
552
- # show? "options=#{$options}"
552
+ # puts "options=#{$options}"
553
553
 
554
554
  # Check the compatibility of the options
555
- if $options.count {|op| [:yaml,:hdr,:verilog,:vhdl,:svg].include?(op) } > 1 then
556
- warn("Please choose either YAML, HDLRuby, Verilog HDL, VHDL, SVG (visualize) output.")
557
- puts $optparse.help()
555
+ if $options.count {|op,val| [:yaml,:hdr,:verilog,:vhdl,:svg].include?(op) } > 1 then
556
+ warn("**Warning**: please choose either YAML, HDLRuby, Verilog HDL, VHDL, SVG (visualize) output.")
557
+ # puts $optparse.help()
558
+ exit
559
+ end
560
+ if $options.count {|op,val| [:rcsim, :csim, :rsim].include?(op) } > 1 then
561
+ warn("**Warning**: please choose either RCSIM, CSIM or RSIM simulator.")
562
+ # puts $optparse.help()
563
+ exit
564
+ end
565
+ if $options.count {|op,val| [:yaml,:hdr,:verilog,:vhdl,:svg,:rcsim,:csim,:rsim].include?(op) } > 1 then
566
+ warn("**Warning**: please choose either simulation or code generation.")
567
+ # puts $optparse.help()
568
+ exit
558
569
  end
559
570
 
560
571
  # Get the the input and the output files.