HDLRuby 2.2.13 → 2.3.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.
@@ -4,8 +4,8 @@ system :rom4_8 do
4
4
  [2..0].input :addr
5
5
  [7..0].output :data0,:data1,:data2
6
6
 
7
- bit[7..0][0..7].constant content0: [1,2,3,4,5,6,7]
8
- bit[7..0][-8].constant content1: [1,2,3,4,5,6,7]
7
+ bit[7..0][0..7].constant content0: [0,1,2,3,4,5,6,7]
8
+ bit[7..0][-8].constant content1: [0,1,2,3,4,5,6,7]
9
9
  bit[7..0][-8].constant content2: (8).times.to_a
10
10
 
11
11
  data0 <= content0[addr]
@@ -0,0 +1,96 @@
1
+ require 'std/memory.rb'
2
+ require 'std/linear.rb'
3
+ # require 'std/timing.rb'
4
+
5
+ include HDLRuby::High::Std
6
+
7
+
8
+ system :fir do |typ,iChannel,oChannel,coefs|
9
+ input :clk, :rst, :req
10
+ output :ack
11
+ # Declare the input port.
12
+ iChannel.input :iPort
13
+ # Declare the output port.
14
+ oChannel.output :oPort
15
+
16
+ # Declares the data registers.
17
+ datas = coefs.map.with_index do |coef,id|
18
+ coef.type.inner :"data_#{id}"
19
+ end
20
+
21
+ inner :req2
22
+
23
+
24
+ # Generate the mac pipeline.
25
+ mac_np(typ,clk.posedge,req2,ack,
26
+ datas.map{|data| channel_port(data) },
27
+ coefs.map{|coef| channel_port(coef) }, oPort)
28
+
29
+ # Generate the data transfer through the pipeline.
30
+ par(clk.posedge) do
31
+ req2 <= 0
32
+ hif(rst) { datas.each { |d| d <= 0 } }
33
+ hif(req) do
34
+ iPort.read(datas[0]) do
35
+ # datas.each_cons(2) { |d0,d1| d1 <= d0 }
36
+ datas[1..-1] <= datas[0..-2]
37
+ end
38
+ req2 <= 1
39
+ end
40
+ end
41
+ end
42
+
43
+
44
+
45
+
46
+
47
+ system :work do
48
+
49
+ inner :clk,:rst,:req,:ack
50
+
51
+ # The input memory.
52
+ mem_rom([8],8,clk,rst,
53
+ [_00000001,_00000010,_00000011,_00000100,
54
+ _00000101,_00000110,_00000111,_00001000]).(:iMem)
55
+ # The output memory.
56
+ mem_dual([8],8,clk,rst).(:oMem)
57
+ # The coefficients.
58
+ coefs = [_11001100,_00110011,_10101010,_01010101,
59
+ _11110000,_00001111,_11100011,_00011100]
60
+
61
+ # The filter
62
+ fir([8],iMem.branch(:rinc),oMem.branch(:winc),coefs).(:my_fir).(clk,rst,req,ack)
63
+
64
+ # iMem.branch(:rinc).inner :port
65
+ # [8].inner :a
66
+ # par(clk.posedge) do
67
+ # hif(req) { port.read(a) }
68
+ # end
69
+
70
+ timed do
71
+ req <= 0
72
+ clk <= 0
73
+ rst <= 0
74
+ !10.ns
75
+ clk <= 1
76
+ !10.ns
77
+ clk <= 0
78
+ rst <= 1
79
+ !10.ns
80
+ clk <= 1
81
+ !10.ns
82
+ clk <= 0
83
+ rst <= 0
84
+ !10.ns
85
+ clk <= 1
86
+ !10.ns
87
+ req <= 1
88
+ clk <= 0
89
+ 64.times do
90
+ !10.ns
91
+ clk <= 1
92
+ !10.ns
93
+ clk <= 0
94
+ end
95
+ end
96
+ end
@@ -12,8 +12,9 @@ system :fix_test do
12
12
 
13
13
  # Performs calculation between then
14
14
  timed do
15
- x <= _00110011
16
- y <= _01000000
15
+ # x <= _00110011 # 3.1875
16
+ x <= 3.1875.to_fix(4)
17
+ y <= _01000000 # 4
17
18
  !10.ns
18
19
  z <= x + y
19
20
  !10.ns
@@ -0,0 +1,166 @@
1
+ require 'std/memory.rb'
2
+ require 'std/linear.rb'
3
+
4
+ include HDLRuby::High::Std
5
+
6
+ # Tries for matrix-vector product.
7
+
8
+
9
+
10
+
11
+
12
+ # Testing.
13
+ system :testmat do
14
+
15
+ inner :clk,:rst, :req
16
+
17
+ # Input memories
18
+ # mem_dual([8],256,clk,rst, rinc: :rst,winc: :rst).(:memL0)
19
+ # The first memory is 4-bank for testing purpose.
20
+ mem_bank([8],4,256/4,clk,rst, rinc: :rst,winc: :rst).(:memL0)
21
+ # The others are standard dual-edge memories.
22
+ mem_dual([8],256,clk,rst, rinc: :rst,winc: :rst).(:memL1)
23
+ mem_dual([8],256,clk,rst, rinc: :rst,winc: :rst).(:memR)
24
+ # Access ports.
25
+ memL0.branch(:rinc).inner :readL0
26
+ memL1.branch(:rinc).inner :readL1
27
+ memR.branch(:rinc).inner :readR
28
+
29
+ # Prepares the left and acc arrays.
30
+ lefts = [readL0, readL1]
31
+
32
+ # Accumulators memory.
33
+ mem_file([8],2,clk,rst,rinc: :rst).(:memAcc)
34
+ memAcc.branch(:anum).inner :accs
35
+ accs_out = [accs.wrap(0), accs.wrap(1)]
36
+
37
+ # Layer 0 ack.
38
+ inner :ack0
39
+
40
+ # Instantiate the matrix product.
41
+ mac_n1([8],clk,req,ack0,lefts,readR,accs_out)
42
+
43
+ # Translation.
44
+ # Translation memory.
45
+ mem_file([8],2,clk,rst,winc: :rst).(:memT)
46
+ # Tarnslation result
47
+ mem_file([8],2,clk,rst,rinc: :rst).(:memF)
48
+ # Access ports.
49
+ memT.branch(:anum).inner :readT
50
+ memF.branch(:anum).inner :writeF
51
+ regRs = [ readT.wrap(0), readT.wrap(1) ]
52
+ regLs = [ accs.wrap(0), accs.wrap(1) ]
53
+ regs = [ writeF.wrap(0), writeF.wrap(1) ]
54
+
55
+ # Translater ack.
56
+ inner :ackT
57
+
58
+ # Instantiate the translater.
59
+ add_n([8],clk,ack0,ackT,regLs,regRs,regs)
60
+
61
+
62
+
63
+ # Second layer.
64
+ # Input memories.
65
+ mem_dual([8],2,clk,rst, rinc: :rst,winc: :rst).(:mem2L0)
66
+ # Access ports.
67
+ mem2L0.branch(:rinc).inner :read2L0
68
+ # memAcc.branch(:rinc).inner :accsR
69
+ memF.branch(:rinc).inner :readF
70
+
71
+ # Second layer ack.
72
+ inner :ack1
73
+
74
+ # Result.
75
+ [8].inner :res
76
+
77
+ sub do
78
+ # Instantiate the second matrix product.
79
+ # mac([8],clk,req,read2L0,accsR,res)
80
+ mac([8],clk,ackT,ack1,read2L0,readF,channel_port(res))
81
+ end
82
+
83
+
84
+
85
+ # The memory initializer.
86
+ memL0.branch(:winc).inner :writeL0
87
+ memL1.branch(:winc).inner :writeL1
88
+ memR.branch(:winc).inner :writeR
89
+ memT.branch(:winc).inner :writeT
90
+ mem2L0.branch(:winc).inner :write2L0
91
+ inner :fill, :fill2
92
+ [8].inner :val
93
+ par(clk.posedge) do
94
+ hif(fill) do
95
+ writeL0.write(val)
96
+ writeL1.write(val+1)
97
+ writeR.write(val+1)
98
+ end
99
+ hif(fill2) do
100
+ write2L0.write(val+2)
101
+ writeT.write(val+2)
102
+ end
103
+ end
104
+
105
+ timed do
106
+ req <= 0
107
+ clk <= 0
108
+ rst <= 0
109
+ fill <= 0
110
+ fill2 <= 0
111
+ val <= 0
112
+ !10.ns
113
+ # Reset the memories.
114
+ rst <= 1
115
+ !10.ns
116
+ clk <= 1
117
+ !10.ns
118
+ # Fill the memories.
119
+ # First layer
120
+ clk <= 0
121
+ rst <= 0
122
+ fill <= 1
123
+ !10.ns
124
+ 256.times do |i|
125
+ clk <= 1
126
+ !10.ns
127
+ clk <= 0
128
+ val <= val + 1
129
+ !10.ns
130
+ end
131
+ fill <= 0
132
+ clk <= 1
133
+ !10.ns
134
+ # Second layer
135
+ clk <= 0
136
+ rst <= 0
137
+ fill2 <= 1
138
+ !10.ns
139
+ 2.times do |i|
140
+ clk <= 1
141
+ !10.ns
142
+ clk <= 0
143
+ val <= val + 1
144
+ !10.ns
145
+ end
146
+ fill2 <= 0
147
+ clk <= 1
148
+ !10.ns
149
+ clk <= 0
150
+ !10.ns
151
+ clk <= 1
152
+ !10.ns
153
+ clk <= 0
154
+ !10.ns
155
+ # Launch the computation
156
+ clk <= 0
157
+ req <= 1
158
+ !10.ns
159
+ 300.times do
160
+ clk <= 1
161
+ !10.ns
162
+ clk <= 0
163
+ !10.ns
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,69 @@
1
+ require 'std/loop.rb'
2
+
3
+ include HDLRuby::High::Std
4
+
5
+ system :with_loop do
6
+
7
+ # The clock and reset
8
+ inner :clk, :rst
9
+ # The running signals.
10
+ inner :doit0, :doit1
11
+ # The signal to check for finishing.
12
+ inner :over
13
+
14
+ # A counter.
15
+ [8].inner :count, :count2
16
+
17
+ # The first loop: basic while.
18
+ lp0 = while_loop(clk, proc{count<=0}, count<15) { count <= count + 1 }
19
+
20
+ # The second loop: 10 times.
21
+ lp1 = times_loop(clk,10) { count2 <= count2+2 }
22
+ # Control it using doit1 as req and over as ack.
23
+ rst_req_ack(clk.posedge,rst,doit1,over,lp1)
24
+
25
+ par(clk.posedge) do
26
+ doit1 <= 0
27
+ hif(rst) do
28
+ lp0.reset()
29
+ # lp1.reset()
30
+ # doit1 <= 0
31
+ count2 <= 0
32
+ over <= 0
33
+ end
34
+ helse do
35
+ hif(doit0) { lp0.run }
36
+ lp0.finish { doit0 <= 0; doit1 <= 1 }# ; lp1.run }
37
+ hif(doit1) { lp1.run; lp0.reset() }
38
+ # lp1.finish { over <= 1; doit1 <= 0 }
39
+ # Second pass for first loop.
40
+ hif(over) { lp0.run }
41
+ end
42
+ end
43
+
44
+ timed do
45
+ clk <= 0
46
+ rst <= 0
47
+ doit0 <= 0
48
+ !10.ns
49
+ clk <= 1
50
+ !10.ns
51
+ clk <= 0
52
+ rst <= 1
53
+ !10.ns
54
+ clk <= 1
55
+ !10.ns
56
+ clk <= 0
57
+ rst <= 0
58
+ doit0 <= 1
59
+ !10.ns
60
+ clk <= 1
61
+ !10.ns
62
+ 64.times do
63
+ clk <= 0
64
+ !10.ns
65
+ clk <= 1
66
+ !10.ns
67
+ end
68
+ end
69
+ end
@@ -108,16 +108,26 @@ system :mem_test do
108
108
  end
109
109
 
110
110
 
111
- [8].inner :sum
111
+ [8].inner :sum0, :sum1
112
112
 
113
113
  # Declares a dual edge 8-bit data and address memory.
114
114
  mem_dual([8],256,clk,rst, raddr: :rst,waddr: :rst).(:memDI)
115
115
 
116
116
  # Instantiate the producer to access port waddr of the memory.
117
- producer(memDI.branch(:waddr)).(:producerI).(clk,rst)
117
+ producer(memDI.branch(:waddr)).(:producerI0).(clk,rst)
118
118
 
119
119
  # Instantiate the producer to access port raddr of the memory.
120
- consumer(memDI.branch(:raddr)).(:consumerI).(clk,rst,sum)
120
+ consumer(memDI.branch(:raddr)).(:consumerI0).(clk,rst,sum0)
121
+
122
+
123
+ # Declares a 4-bank 8-bit data and address memory.
124
+ mem_bank([8],4,256/4,clk,rst, raddr: :rst, waddr: :rst).(:memBI)
125
+
126
+ # Instantiate the producer to access port waddr of the memory.
127
+ producer(memBI.branch(:waddr)).(:producerI1).(clk,rst)
128
+
129
+ # Instantiate the producer to access port raddr of the memory.
130
+ consumer(memBI.branch(:raddr)).(:consumerI1).(clk,rst,sum1)
121
131
 
122
132
 
123
133
  end
@@ -563,7 +563,7 @@ elsif $options[:clang] then
563
563
  end
564
564
  Dir.chdir($output)
565
565
  # Kernel.system("make -s")
566
- Kernel.system("cc -o3 -o hruby_simulator *.c")
566
+ Kernel.system("cc -o3 -o hruby_simulator *.c -lpthread")
567
567
  Kernel.system("./hruby_simulator")
568
568
  end
569
569
  elsif $options[:verilog] then
@@ -1308,6 +1308,12 @@ module HDLRuby::High
1308
1308
  return true
1309
1309
  end
1310
1310
 
1311
+ # Converts to a type.
1312
+ # Returns self since it is already a type.
1313
+ def to_type
1314
+ return self
1315
+ end
1316
+
1311
1317
  # Sets the +name+.
1312
1318
  #
1313
1319
  # NOTE: can only be done if the name is not already set.
@@ -1851,16 +1857,18 @@ module HDLRuby::High
1851
1857
  # NOTE: a function is a short-cut for a method that creates a scope.
1852
1858
  def function(name, &ruby_block)
1853
1859
  if HDLRuby::High.in_system? then
1854
- define_singleton_method(name.to_sym) do |*args|
1860
+ define_singleton_method(name.to_sym) do |*args,&other_block|
1855
1861
  sub do
1856
- HDLRuby::High.top_user.instance_exec(*args,&ruby_block)
1862
+ HDLRuby::High.top_user.instance_exec(*args,*other_block,
1863
+ &ruby_block)
1857
1864
  # ruby_block.call(*args)
1858
1865
  end
1859
1866
  end
1860
1867
  else
1861
- define_method(name.to_sym) do |*args|
1868
+ define_method(name.to_sym) do |*args,&other_block|
1862
1869
  sub do
1863
- HDLRuby::High.top_user.instance_exec(*args,&ruby_block)
1870
+ HDLRuby::High.top_user.instance_exec(*args,*other_block,
1871
+ &ruby_block)
1864
1872
  end
1865
1873
  end
1866
1874
  end
@@ -1385,7 +1385,8 @@ module HDLRuby::Low
1385
1385
  # NOTE: type definition are actually type with a name refering to another
1386
1386
  # type (and equivalent to it).
1387
1387
  class TypeDef < Type
1388
- extend Forwardable
1388
+ # Moved to constructor
1389
+ # extend Forwardable
1389
1390
 
1390
1391
  # The definition of the type.
1391
1392
  attr_reader :def
@@ -1402,6 +1403,19 @@ module HDLRuby::Low
1402
1403
  end
1403
1404
  # Set the referened type.
1404
1405
  @def = type
1406
+
1407
+ # Sets the delegations
1408
+ self.extend Forwardable
1409
+ [ :signed?, :unsigned?, :fixed?, :float?, :leaf?,
1410
+ :width, :range?, :range, :base?, :base, :types?,
1411
+ :get_all_types, :get_type, :each, :each_type,
1412
+ :regular?,
1413
+ :each_name,
1414
+ :equivalent? ].each do |meth|
1415
+ if @def.respond_to?(meth)
1416
+ self.def_delegator :@def, meth
1417
+ end
1418
+ end
1405
1419
  end
1406
1420
 
1407
1421
  # Comparison for hash: structural comparison.
@@ -1429,14 +1443,15 @@ module HDLRuby::Low
1429
1443
  @def.each_type_deep(&ruby_block)
1430
1444
  end
1431
1445
 
1432
- # Delegate the type methods to the ref.
1433
- def_delegators :@def,
1434
- :signed?, :unsigned?, :fixed?, :float?, :leaf?,
1435
- :width, :range?, :range, :base?, :base, :types?,
1436
- :get_all_types, :get_type, :each, :each_type,
1437
- :regular?,
1438
- :each_name,
1439
- :equivalent?
1446
+ # Moved to constructor
1447
+ # # Delegate the type methods to the ref.
1448
+ # def_delegators :@def,
1449
+ # :signed?, :unsigned?, :fixed?, :float?, :leaf?,
1450
+ # :width, :range?, :range, :base?, :base, :types?,
1451
+ # :get_all_types, :get_type, :each, :each_type,
1452
+ # :regular?,
1453
+ # :each_name,
1454
+ # :equivalent?
1440
1455
  end
1441
1456
 
1442
1457
 
@@ -3059,24 +3074,6 @@ module HDLRuby::Low
3059
3074
  return [@value,@whens,@default].hash
3060
3075
  end
3061
3076
 
3062
- # # Adds a possible +match+ for the case's value that lead to the
3063
- # # execution of +statement+.
3064
- # def add_when(match,statement)
3065
- # # Checks the match.
3066
- # unless match.is_a?(Expression)
3067
- # raise AnyError, "Invalid class for a case match: #{match.class}"
3068
- # end
3069
- # # Checks statement.
3070
- # unless statement.is_a?(Statement)
3071
- # raise AnyError, "Invalid class for a statement: #{statement.class}"
3072
- # end
3073
- # # Add the case.
3074
- # @whens << [match,statement]
3075
- # # And set their parents.
3076
- # match.parent = statement.parent = self
3077
- # [match,statement]
3078
- # end
3079
-
3080
3077
  # Adds possible when case +w+.
3081
3078
  def add_when(w)
3082
3079
  # Check +w+.
@@ -3178,7 +3175,7 @@ module HDLRuby::Low
3178
3175
  # Clones the Case (deeply)
3179
3176
  def clone
3180
3177
  # Clone the default if any.
3181
- defaut = @default ? @default.clone : nil
3178
+ default = @default ? @default.clone : nil
3182
3179
  # Clone the case.
3183
3180
  return Case.new(@value.clone,default,(@whens.map do |w|
3184
3181
  w.clone