HDLRuby 2.3.7 → 2.4.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb0dfd0d3f5fd062cd7e31f46eab82f0090e58eb8690a50a74106cfa32b5b9c2
4
- data.tar.gz: 46f437035c02b4c8de14fb5033361b2d65cb6a7916887ca16a1dea67adadc8b9
3
+ metadata.gz: cd62e24fab42fee5c7a9e3cefda920cab67ec3a739e7ec0e66e6e637e890b959
4
+ data.tar.gz: d294cb0479e6388dea6e318c458f26ddabf71fd9281fa25f6ee69d6039bd1526
5
5
  SHA512:
6
- metadata.gz: f6db11e75542e9b1f3e9064c32b3d8979ff3815ff661bfe8defc80f9625b671851a341366ad021a120305071e5f2099f95193e8a2332366460b967c6755a041f
7
- data.tar.gz: 44a91392735fa86edc102ae6d20aa54dd85628e2efac5f4112731d2733bf7b555e4dce9bc39a086efbb5c3a1f1f0d2a4bb0e420be1f6251d26a505599bff526d
6
+ metadata.gz: d2039cd7158a2e2296005639474f9076f4f72f667777c97a94d7581975e92242e2be31fe3b7fb1cadf722b4f9fa6d8f8287252ec9944077512ffcd7d036ad28f
7
+ data.tar.gz: 8107f68c9c15f2f5e33a6f1a94c3454d46b9d4493ed00868c660d084b0e94e64747da3b984f7812254c31f3595988833de1df6e71253648ed1f85042cd45b534
data/README.md CHANGED
@@ -50,6 +50,7 @@ Where:
50
50
  | `-s, --syntax` | Output the Ruby syntax tree |
51
51
  | `-C, --clang` | Output the C code of the simulator |
52
52
  | `-S, --sim` | Output the executable simulator and execute it |
53
+ | `--vcd` | Make the simulator generate a vcd file |
53
54
  | `-d, --directory` | Specify the base directory for loading the HDLRuby files |
54
55
  | `-D, --debug` | Set the HDLRuby debug mode |
55
56
  | `-t, --top system`| Specify the top system describing the circuit to compile |
@@ -0,0 +1,14 @@
1
+
2
+ # A benchmark for the bit string generation in case of signed values.
3
+ system :bstr_bench do
4
+ signed[7..0].inner :val
5
+
6
+ timed do
7
+ val <= 0
8
+ !10.ns
9
+ val <= 26
10
+ !10.ns
11
+ val <= -25
12
+ !10.ns
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+
2
+ # A benchmark for testing the arithmetic with signed values.
3
+ system :neg_arith_bench do
4
+ signed[11..0].inner :x,:y,:z
5
+
6
+ timed do
7
+ x <= 10
8
+ y <= 10
9
+ z <= 0
10
+ !10.ns
11
+ z <= 10 * 10
12
+ !10.ns
13
+ z <= x * y
14
+ !10.ns
15
+ x <= 10
16
+ y <= -10
17
+ !10.ns
18
+ z <= 10 * (-10)
19
+ !10.ns
20
+ z <= x * y
21
+ !10.ns
22
+ x <= -10
23
+ y <= 10
24
+ !10.ns
25
+ z <= (-10) * 10
26
+ !10.ns
27
+ z <= x * y
28
+ !10.ns
29
+ x <= -10
30
+ y <= -10
31
+ !10.ns
32
+ z <= (-10) * (-10)
33
+ !10.ns
34
+ z <= x * y
35
+ !10.ns
36
+ x <= _000000011010
37
+ y <= _000011111010
38
+ z <= 0
39
+ !10.ns
40
+ z <= x * y
41
+ !10.ns
42
+ x <= _000000011010
43
+ y <= _111111111010
44
+ z <= 0
45
+ !10.ns
46
+ z <= x * y
47
+ !10.ns
48
+ end
49
+ end
@@ -9,6 +9,8 @@ system :fix_test do
9
9
 
10
10
  # Declare three 4-bit integer part 4-bit fractional part
11
11
  bit[3..0,3..0].inner :x,:y,:z
12
+ # Declare three 8-bit integer part 8-bit fractional part
13
+ signed[3..0,3..0].inner :a,:b,:c,:d
12
14
 
13
15
  # Performs calculation between then
14
16
  timed do
@@ -22,5 +24,30 @@ system :fix_test do
22
24
  !10.ns
23
25
  z <= z / x
24
26
  !10.ns
27
+ a <= _00010000
28
+ b <= _00001111
29
+ !10.ns
30
+ c <= a * b
31
+ d <= 0
32
+ !10.ns
33
+ d <= d + c
34
+ !10.ns
35
+ a <= -0.375.to_fix(4)
36
+ b <= 1.625.to_fix(4)
37
+ !10.ns
38
+ c <= a * b
39
+ !10.ns
40
+ # a <= _00010000
41
+ # b <= _00010101
42
+ a <= _0000111x
43
+ b <= _1110011x
44
+ !10.ns
45
+ # a <= a & _11111110
46
+ # b <= b | _00000001
47
+ a <= a | _00000001
48
+ b <= b | _00000001
49
+ !10.ns
50
+ c <= a * b
51
+ !10.ns
25
52
  end
26
53
  end
@@ -0,0 +1,300 @@
1
+ require "std/channel.rb"
2
+
3
+ include HDLRuby::High::Std
4
+
5
+ # Channel describing a buffered queue storing data of +typ+ type of +depth+,
6
+ # synchronized through clk and reset on +rst+.
7
+ channel(:queue) do |typ,depth,clk,rst|
8
+ # The inner buffer of the queue.
9
+ typ[-depth].inner :buffer
10
+ # The read and write pointers.
11
+ [depth.width].inner :rptr, :wptr
12
+ # The read and write command signals.
13
+ inner :rcmd, :wcmd
14
+ # The read and write ack signals.
15
+ inner :rack, :wack
16
+ # The ack check deactivator (for synchron accesses).
17
+ inner :hrack, :hwack
18
+ # The read/write data registers.
19
+ typ.inner :rdata, :wdata
20
+
21
+ # The process handling the decoupled access to the buffer.
22
+ par(clk.posedge) do
23
+ # rack <= 0
24
+ # wack <= 0
25
+ hif (~rcmd) { rack <= 0 }
26
+ hif (~wcmd) { wack <= 0 }
27
+ hif(rst) { rptr <= 0; wptr <= 0 }
28
+ hif(rcmd & (hrack|~rack) & (rptr != wptr)) do
29
+ rptr <= (rptr + 1) % depth
30
+ rack <= 1
31
+ end
32
+ hif(wcmd & (hwack|~wack) & (((wptr+1) % depth) != rptr)) do
33
+ buffer[wptr] <= wdata
34
+ # buffer[1] <= wdata
35
+ wptr <= (wptr + 1) % depth
36
+ wack <= 1
37
+ end
38
+ end
39
+ par { rdata <= buffer[rptr] }
40
+
41
+ reader_output :rcmd, :rptr, :hrack
42
+ reader_input :rdata, :rack
43
+
44
+ # The read primitive.
45
+ reader do |blk,target|
46
+ if (cur_behavior.on_event?(clk.posedge,clk.negedge)) then
47
+ # Same clk event, synchrone case: perform a direct access.
48
+ # Now perform the access.
49
+ top_block.unshift do
50
+ rcmd <= 0
51
+ hrack <= 1
52
+ end
53
+ seq do
54
+ rptr <= (rptr + 1) % depth
55
+ target <= rdata
56
+ blk.call if blk
57
+ end
58
+ else
59
+ # Different clk event, perform a decoupled access.
60
+ top_block.unshift do
61
+ rcmd <= 0
62
+ hrack <= 0
63
+ end
64
+ seq do
65
+ hif(rack) do
66
+ blk.call if blk
67
+ end
68
+ helse do
69
+ rcmd <= 1
70
+ target <= rdata
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ writer_output :wcmd, :wdata, :hwack
77
+ writer_input :wack
78
+
79
+ # The write primitive.
80
+ writer do |blk,target|
81
+ if (cur_behavior.on_event?(clk.negedge,clk.posedge)) then
82
+ # Same clk event, synchrone case: perform a direct access.
83
+ top_block.unshift do
84
+ wcmd <= 0
85
+ hwack <= 1
86
+ end
87
+ wcmd <= 1
88
+ wdata <= target
89
+ blk.call if blk
90
+ else
91
+ # Different clk event, asynchrone case: perform a decoupled access.
92
+ top_block.unshift do
93
+ wcmd <= 0
94
+ hwack <= 0
95
+ end
96
+ seq do
97
+ hif(wack) do
98
+ blk.call if blk
99
+ end
100
+ helse { wcmd <= 1 }
101
+ wdata <= target
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+
108
+ # Channel describing a register of +typ+ type.
109
+ channel(:register) do |typ|
110
+ # The register.
111
+ typ.inner :buffer
112
+
113
+ reader_input :buffer
114
+
115
+ # The read primitive.
116
+ reader do |blk,target|
117
+ target <= buffer
118
+ blk.call if blk
119
+ end
120
+
121
+ writer_output :buffer
122
+
123
+ # The read primitive.
124
+ writer do |blk,target|
125
+ buffer <= target
126
+ blk.call if blk
127
+ end
128
+ end
129
+
130
+
131
+
132
+ # Channel describing a handshake for transmitting data of +typ+ type, reset
133
+ # by +rst+
134
+ channel(:handshake) do |typ|
135
+ # The data signal.
136
+ typ.inner :data
137
+ # The request and acknowledge.
138
+ typ.inner :req, :ack
139
+
140
+ reader_input :ack, :data
141
+ reader_output :req
142
+
143
+ # The read primitive.
144
+ reader do |blk,target|
145
+ top_block.unshift do
146
+ req <= 0
147
+ end
148
+ hif(ack == 0) do
149
+ req <= 1
150
+ end
151
+ helsif(req) do
152
+ target <= data
153
+ req <= 0
154
+ blk.call if blk
155
+ end
156
+ end
157
+
158
+ writer_input :req
159
+ writer_output :ack, :data
160
+
161
+ # The read primitive.
162
+ writer do |blk,target|
163
+ top_block.unshift do
164
+ ack <= 0
165
+ end
166
+ hif(req) do
167
+ hif(~ack) do
168
+ data <= target
169
+ blk.call if blk
170
+ end
171
+ ack <= 1
172
+ end
173
+ end
174
+ end
175
+
176
+
177
+ # $mode = :sync
178
+ # $mode = :nsync
179
+ # $mode = :async
180
+ # $mode = :proco # Producter / Consummer
181
+ # $channel = :register
182
+ # $channel = :handshake
183
+ # $channel = :queue
184
+
185
+ # The configuration scenarii
186
+ $scenarii = [ [:sync, :register], [:sync, :handshake], [:sync, :queue],
187
+ [:nsync, :register], [:nsync, :handshake], [:nsync, :queue],
188
+ [:async, :register], [:async, :handshake], [:async, :queue],
189
+ [:proco, :register], [:proco, :handshake], [:proco, :queue] ]
190
+
191
+ # The configuration
192
+ $mode, $channel = $scenarii[11]
193
+
194
+ # Testing the queue channel.
195
+ system :test_queue do
196
+ inner :clk, :rst, :clk2, :clk3
197
+ [8].inner :idata, :odata
198
+ [4].inner :counter
199
+
200
+ if $channel == :register then
201
+ register(bit[8]).(:my_ch)
202
+ elsif $channel == :handshake then
203
+ handshake(bit[8],rst).(:my_ch)
204
+ elsif $channel == :queue then
205
+ queue(bit[8],5,clk,rst).(:my_ch)
206
+ end
207
+
208
+ ev = $mode == :sync ? clk.posedge :
209
+ $mode == :nsync ? clk.negedge : clk2.posedge
210
+
211
+ if $mode != :proco then
212
+ # Sync/Neg sync and async tests mode
213
+ par(ev) do
214
+ hif(rst) do
215
+ counter <= 0
216
+ idata <= 0
217
+ odata <= 0
218
+ end
219
+ helse do
220
+ hif (counter < 4) do
221
+ my_ch.write(idata) do
222
+ idata <= idata + 1
223
+ counter <= counter + 1
224
+ end
225
+ end
226
+ helsif ((counter > 10) & (counter < 15)) do
227
+ my_ch.read(odata) do
228
+ idata <= idata - odata
229
+ counter <= counter + 1
230
+ end
231
+ end
232
+ helse do
233
+ counter <= counter + 1
234
+ end
235
+ end
236
+ end
237
+ else
238
+ # Producter/consumer mode
239
+ # Producer
240
+ par(clk2.posedge) do
241
+ hif(rst) do
242
+ idata <= 0
243
+ end
244
+ helse do
245
+ my_ch.write(idata) do
246
+ idata <= idata + 1
247
+ end
248
+ end
249
+ end
250
+ # Consumer
251
+ par(clk3.posedge) do
252
+ hif(rst) do
253
+ counter <= 0
254
+ end
255
+ helse do
256
+ my_ch.read(odata) do
257
+ counter <= counter + 1
258
+ end
259
+ end
260
+ end
261
+ end
262
+
263
+ timed do
264
+ clk <= 0
265
+ clk2 <= 0
266
+ clk3 <= 0
267
+ rst <= 0
268
+ !10.ns
269
+ clk <= 1
270
+ !10.ns
271
+ clk <= 0
272
+ rst <= 1
273
+ !3.ns
274
+ clk2 <= 1
275
+ !3.ns
276
+ clk3 <= 0
277
+ !4.ns
278
+ clk <= 1
279
+ !10.ns
280
+ clk <= 0
281
+ !3.ns
282
+ clk2 <= 0
283
+ !3.ns
284
+ clk3 <= 1
285
+ !2.ns
286
+ rst <= 0
287
+ !2.ns
288
+ 64.times do
289
+ clk <= 1
290
+ !10.ns
291
+ clk <= 0
292
+ !3.ns
293
+ clk2 <= ~clk2
294
+ !3.ns
295
+ hif (clk2 == 0) { clk3 <= ~ clk3 }
296
+ !4.ns
297
+ end
298
+ end
299
+ end
300
+
@@ -269,6 +269,9 @@ $optparse = OptionParser.new do |opts|
269
269
  $options[:multiple] = v
270
270
  $options[:sim] = v
271
271
  end
272
+ opts.on("--vcd", "The simulator will generate a vcd file") do |v|
273
+ $options[:vcd] = v
274
+ end
272
275
  opts.on("-v", "--verilog","Output in Verlog HDL format") do |v|
273
276
  $options[:verilog] = v
274
277
  $options[:multiple] = v
@@ -515,9 +518,15 @@ elsif $options[:clang] then
515
518
  # Generate the code for it.
516
519
  $main = File.open($name,"w")
517
520
 
521
+ # Select the vizualizer depending on the options.
522
+ init_visualizer = $options[:vcd] ? "init_vcd_visualizer" :
523
+ "init_default_visualizer"
524
+
518
525
  # Generate the code of the main function.
519
526
  # HDLRuby start code
520
- $main << HDLRuby::Low::Low2C.main($top_system,
527
+ $main << HDLRuby::Low::Low2C.main("hruby_simulator",
528
+ init_visualizer,
529
+ $top_system,
521
530
  $top_system.each_systemT_deep.to_a.reverse,$hnames)
522
531
  $main.close
523
532