HDLRuby 3.1.0 → 3.2.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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/HDLRuby.gemspec +1 -0
  3. data/README.md +10 -0
  4. data/ext/hruby_sim/hruby_rcsim_build.c +2 -0
  5. data/ext/hruby_sim/hruby_sim_calc.c +33 -6
  6. data/ext/hruby_sim/hruby_sim_tree_calc.c +111 -22
  7. data/lib/HDLRuby/hdr_samples/comparison_bench.rb +2 -2
  8. data/lib/HDLRuby/hdr_samples/counter_bench.rb +1 -1
  9. data/lib/HDLRuby/hdr_samples/counter_dff_bench.rb +8 -7
  10. data/lib/HDLRuby/hdr_samples/dff_properties.rb +2 -0
  11. data/lib/HDLRuby/hdr_samples/enum_as_param.rb +52 -0
  12. data/lib/HDLRuby/hdr_samples/linear_test.rb +2 -0
  13. data/lib/HDLRuby/hdr_samples/logic_bench.rb +6 -0
  14. data/lib/HDLRuby/hdr_samples/mei8.rb +6 -6
  15. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +6 -6
  16. data/lib/HDLRuby/hdr_samples/memory_test.rb +2 -0
  17. data/lib/HDLRuby/hdr_samples/named_sub.rb +9 -5
  18. data/lib/HDLRuby/hdr_samples/ram.rb +7 -6
  19. data/lib/HDLRuby/hdr_samples/ruby_fir_hw.rb +2 -0
  20. data/lib/HDLRuby/hdr_samples/struct.rb +15 -3
  21. data/lib/HDLRuby/hdr_samples/with_bram.rb +1 -1
  22. data/lib/HDLRuby/hdr_samples/with_bram_frame_stack.rb +1 -1
  23. data/lib/HDLRuby/hdr_samples/with_bram_stack.rb +1 -1
  24. data/lib/HDLRuby/hdr_samples/with_channel.rb +2 -0
  25. data/lib/HDLRuby/hdr_samples/with_channel_other.rb +2 -0
  26. data/lib/HDLRuby/hdr_samples/with_class.rb +3 -1
  27. data/lib/HDLRuby/hdr_samples/with_connector.rb +2 -0
  28. data/lib/HDLRuby/hdr_samples/with_connector_memory.rb +2 -0
  29. data/lib/HDLRuby/hdr_samples/with_fixpoint.rb +6 -0
  30. data/lib/HDLRuby/hdr_samples/with_fixpoint_adv.rb +73 -0
  31. data/lib/HDLRuby/hdr_samples/with_leftright.rb +1 -1
  32. data/lib/HDLRuby/hdr_samples/with_sequencer.rb +17 -0
  33. data/lib/HDLRuby/hdr_samples/with_sequencer_channel.rb +58 -0
  34. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerable.rb +10 -0
  35. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerator.rb +18 -4
  36. data/lib/HDLRuby/hdr_samples/with_sequencer_sync.rb +2 -1
  37. data/lib/HDLRuby/hdrcc.rb +12 -0
  38. data/lib/HDLRuby/hruby_high.rb +82 -26
  39. data/lib/HDLRuby/hruby_low.rb +127 -3
  40. data/lib/HDLRuby/hruby_low2programs.rb +47 -0
  41. data/lib/HDLRuby/hruby_low_resolve.rb +3 -2
  42. data/lib/HDLRuby/hruby_low_without_namespace.rb +133 -5
  43. data/lib/HDLRuby/hruby_low_without_subsignals.rb +1 -1
  44. data/lib/HDLRuby/hruby_rcsim.rb +24 -1
  45. data/lib/HDLRuby/hruby_serializer.rb +2 -1
  46. data/lib/HDLRuby/hruby_verilog.rb +94 -20
  47. data/lib/HDLRuby/hruby_verilog_name.rb +3 -17
  48. data/lib/HDLRuby/std/fixpoint.rb +2 -2
  49. data/lib/HDLRuby/std/function_generator.rb +1 -1
  50. data/lib/HDLRuby/std/linear.rb +7 -7
  51. data/lib/HDLRuby/std/sequencer.rb +263 -13
  52. data/lib/HDLRuby/std/sequencer_channel.rb +90 -0
  53. data/lib/HDLRuby/std/sequencer_func.rb +28 -15
  54. data/lib/HDLRuby/std/std.rb +1 -0
  55. data/lib/HDLRuby/version.rb +1 -1
  56. metadata +22 -3
@@ -169,7 +169,17 @@ module HDLRuby::Low
169
169
 
170
170
  # Converts the system to Verilog code.
171
171
  def to_verilog
172
- return "(#{self.left.to_verilog} #{self.operator} #{self.right.to_verilog})"
172
+ # In HDLRuby if on term is signed and the other is not, the
173
+ # computation is signed.
174
+ if self.left.type.signed? and self.right.type.unsigned? then
175
+ return "(#{self.left.to_verilog} #{self.operator} " +
176
+ "$signed({1'b0,#{self.right.to_verilog}}))"
177
+ elsif self.left.type.unsigned? and right.type.signed? then
178
+ return "($signed({1'b0,#{self.left.to_verilog}})" +
179
+ " #{self.operator} #{self.right.to_verilog})"
180
+ else
181
+ return "(#{self.left.to_verilog} #{self.operator} #{self.right.to_verilog})"
182
+ end
173
183
  end
174
184
 
175
185
  # Method called when two or more expression terms are present.
@@ -262,7 +272,6 @@ module HDLRuby::Low
262
272
  # Declaration of "inner" part within "always".
263
273
  block.each_inner do |inner|
264
274
  if HDLRuby::Low::VERILOG_REGS.include?(inner.to_verilog) then
265
- # code << " reg"
266
275
  code << "#{" " * (spc+3)}reg"
267
276
  else
268
277
  code << "#{" " * (spc+3)}wire"
@@ -1501,7 +1510,14 @@ module HDLRuby::Low
1501
1510
 
1502
1511
  # Converts the system to Verilog code using +renamer+ for producing Verilog-compatible names.
1503
1512
  def to_verilog
1504
- vname = name_to_verilog(self.name)
1513
+ if (self.ref.is_a?(RefThis)) then
1514
+ # End reference.
1515
+ vname = name_to_verilog(self.name)
1516
+ else
1517
+ # Not end reference, recurse.
1518
+ # vname = name_to_verilog(self.name) + "." + self.ref.to_verilog
1519
+ vname = self.ref.to_verilog + "." + name_to_verilog(self.name)
1520
+ end
1505
1521
  # self.properties[:verilog_name] = vname
1506
1522
  return "#{vname}"
1507
1523
  end
@@ -1565,8 +1581,11 @@ module HDLRuby::Low
1565
1581
  return "#{self.ref.to_verilog}[#{self.range.first.to_getrange}:#{self.range.last.to_getrange}]"
1566
1582
  else
1567
1583
  # No a pure signal, need to use a function for accessing.
1568
- sr = self.range.first.to_i..self.range.last.to_i
1569
- cr = (self.type.width-1)..0
1584
+ # sr = self.range.first.to_i..self.range.last.to_i
1585
+ # cr = (self.type.width-1)..0
1586
+ sr = (self.range.first.to_i+1)*self.ref.type.base.width-1..
1587
+ self.range.last.to_i*self.ref.type.base.width
1588
+ cr = (self.ref.type.width-1)..0
1570
1589
  TruncersI.add(cr,sr)
1571
1590
  return "#{TruncersI.truncer_name(cr,sr)}(#{self.ref.to_verilog})"
1572
1591
  end
@@ -1735,9 +1754,11 @@ module HDLRuby::Low
1735
1754
  if self.default then
1736
1755
  result << " " * (spc+3) + "default: "
1737
1756
  if self.default.each_statement.count >= 1 then
1757
+ result << "begin\n"
1738
1758
  result << self.default.each_statement.map do |stmnt|
1739
- stmnt.to_verilog(spc+3)
1759
+ stmnt.to_verilog(spc+6)
1740
1760
  end.join("\n") << "\n"
1761
+ result << " " * (spc+3) + "end\n"
1741
1762
  else
1742
1763
  result << ";\n"
1743
1764
  end
@@ -2027,11 +2048,60 @@ module HDLRuby::Low
2027
2048
  end
2028
2049
 
2029
2050
 
2051
+ # Get the signals that can be declared as reg.
2052
+ # If +vname+ is given, use as base for reference name.
2053
+ def self.get_regs(expr,vname = nil)
2054
+ if expr.is_a?(RefConcat) then
2055
+ return expr.each_ref.map {|ref| self.get_regs(ref,vname) }.flatten
2056
+ elsif expr.is_a?(RefName) then
2057
+ if vname then
2058
+ puts "vname=#{vname} expr.name=#{expr.name}"
2059
+ if expr.ref && name_to_verilog(expr.name) == vname then
2060
+ return get_regs(expr.ref)
2061
+ else
2062
+ return []
2063
+ end
2064
+ else
2065
+ return [expr]
2066
+ end
2067
+ else
2068
+ return get_regs(expr.ref,vname)
2069
+ end
2070
+ end
2071
+
2072
+ # Get signals indirectly refered that have to become reg in
2073
+ # a sub system. +vname+ is the name of the system whose signals
2074
+ # are to be processed.
2075
+ def self.get_indirect_verilog_regs(systemI,vname)
2076
+ # Get the sub systemT.
2077
+ sub_systemT = systemI.systemT
2078
+ # Get the indirect reg inside it.
2079
+ sub_systemT.each_behavior do |behavior|
2080
+ behavior.each_block_deep do |block|
2081
+ block.each_statement do |statement|
2082
+ if statement.is_a?(Transmit) &&
2083
+ statement.left.to_verilog.include?(vname + ".")
2084
+ puts "hierachical=#{statement.left.to_verilog}"
2085
+ # HDLRuby::Low::VERILOG_REGS << SystemT.get_regs(statement.left.ref).to_verilog
2086
+ HDLRuby::Low::VERILOG_REGS.concat( SystemT.get_regs(statement.left,vname).map(&:to_verilog))
2087
+ end
2088
+ end
2089
+ end
2090
+ end
2091
+ # And recurse on its systemIs.
2092
+ sub_systemT.each_systemI do |sub_systemI|
2093
+ SystemT.get_indirect_verilog_regs(sub_systemI,vname)
2094
+ end
2095
+ end
2096
+
2030
2097
 
2031
2098
  # Converts the system to Verilog code.
2032
2099
  # NOTE: if +vcd+ is true, generate verilog code whose simulation
2033
2100
  # produces a vcd file.
2034
2101
  def to_verilog(vcd = false)
2102
+ # Create the name of the module.
2103
+ vname = name_to_verilog(self.name)
2104
+ # puts "Processing systemT named=#{vname}"
2035
2105
  # Detect the registers
2036
2106
  HDLRuby::Low::VERILOG_REGS.clear
2037
2107
  # The left values.
@@ -2039,11 +2109,15 @@ module HDLRuby::Low
2039
2109
  behavior.each_block_deep do |block|
2040
2110
  block.each_statement do |statement|
2041
2111
  if statement.is_a?(Transmit)
2042
- HDLRuby::Low::VERILOG_REGS << statement.left.to_verilog
2112
+ # HDLRuby::Low::VERILOG_REGS << SystemT.get_regs(statement.left).to_verilog
2113
+ HDLRuby::Low::VERILOG_REGS.concat(SystemT.get_regs(statement.left).map(&:to_verilog))
2043
2114
  end
2044
2115
  end
2045
2116
  end
2046
2117
  end
2118
+ self.each_systemI do |systemI|
2119
+ SystemT.get_indirect_verilog_regs(systemI,vname)
2120
+ end
2047
2121
  # And the initialized signals.
2048
2122
  self.each_output do |output|
2049
2123
  # regs << output.to_verilog if output.value
@@ -2053,17 +2127,18 @@ module HDLRuby::Low
2053
2127
  # regs << inner.to_verilog if inner.value
2054
2128
  HDLRuby::Low::VERILOG_REGS << inner.to_verilog if inner.value
2055
2129
  end
2056
- # And the array types signals.
2057
- self.each_signal do |sig|
2058
- if sig.type.vector? && sig.type.base.vector? then
2059
- HDLRuby::Low::VERILOG_REGS << sig.to_verilog
2060
- end
2061
- end
2062
- self.each_inner do |sig|
2063
- if sig.type.vector? && sig.type.base.vector? then
2064
- HDLRuby::Low::VERILOG_REGS << sig.to_verilog
2065
- end
2066
- end
2130
+ # Actual NOT...
2131
+ # # And the array types signals.
2132
+ # self.each_signal do |sig|
2133
+ # if sig.type.vector? && sig.type.base.vector? then
2134
+ # HDLRuby::Low::VERILOG_REGS << sig.to_verilog
2135
+ # end
2136
+ # end
2137
+ # self.each_inner do |sig|
2138
+ # if sig.type.vector? && sig.type.base.vector? then
2139
+ # HDLRuby::Low::VERILOG_REGS << sig.to_verilog
2140
+ # end
2141
+ # end
2067
2142
 
2068
2143
  # Code generation
2069
2144
  inputs = 0
@@ -2077,7 +2152,6 @@ module HDLRuby::Low
2077
2152
  # Spelling necessary for simulation.
2078
2153
  code = "`timescale 1ps/1ps\n\n"
2079
2154
 
2080
- vname = name_to_verilog(self.name)
2081
2155
  # self.properties[:verilog_name] = vname
2082
2156
  # Output the module name.
2083
2157
  code << "module #{vname}("
@@ -2315,7 +2389,7 @@ module HDLRuby::Low
2315
2389
  codeC << " initial "
2316
2390
  else
2317
2391
  # Generate a standard process.
2318
- codeC << " always @( "
2392
+ codeC << "\n always @( "
2319
2393
  # If there is no "always" condition, it is always @("*").
2320
2394
  if behavior.each_event.to_a.empty? then
2321
2395
  codeC << "*"
@@ -8,26 +8,11 @@ module HDLRuby::Verilog
8
8
  # puts n
9
9
  # name = n.split("")
10
10
 
11
- @@hdr2verilog = {}
11
+ @@hdr2verilog = { "buf" => "_v0_buf", "table" => "_v1_table", "time" => "_v2_time" }
12
12
 
13
13
  # Since it is possible to use $ and numbers other than the beginning of the character string, it is divided.
14
14
  def name_to_verilog(name)
15
- # name = name.to_s
16
- # # Convert special characters.
17
- # name = name.each_char.map do |c|
18
- # if c=~ /[a-z0-9]/ then
19
- # c
20
- # elsif c == "_" then
21
- # "__"
22
- # else
23
- # "_" + c.ord.to_s
24
- # end
25
- # end.join
26
- # # First character: only letter is possible.
27
- # unless name[0] =~ /[a-z_]/ then
28
- # name = "_" + name
29
- # end
30
- # return name
15
+ # puts "name_to_verilog with name=#{name}"
31
16
  name = name.to_s
32
17
  vname = @@hdr2verilog[name]
33
18
  unless vname then
@@ -41,6 +26,7 @@ module HDLRuby::Verilog
41
26
  end
42
27
  @@hdr2verilog[name] = vname
43
28
  end
29
+ # puts "result vname=#{vname}"
44
30
  return vname
45
31
  end
46
32
 
@@ -53,9 +53,9 @@ module HDLRuby::High::Std
53
53
  # Redefine the multiplication and division for fixed point.
54
54
  typ.define_operator(:*) do |left,right|
55
55
  if (typ.signed?) then
56
- (left.as(signed[isize+fsize*2])*right) >> fsize
56
+ ((left.as(signed[isize+fsize*2])*right) >> fsize).as(typ)
57
57
  else
58
- (left.as(bit[isize+fsize*2])*right) >> fsize
58
+ ((left.as(bit[isize+fsize*2])*right) >> fsize).as(typ)
59
59
  end
60
60
  end
61
61
  typ.define_operator(:/) do |left,right|
@@ -75,7 +75,7 @@ module HDLRuby::High::Std
75
75
  base <= lut[address]
76
76
 
77
77
  # Assign the next_data discrete value.
78
- next_data <= lut[address+_b1.as(address.type)]
78
+ next_data <= mux(address < lut_size-1,lut[address],lut[address+_b1.as(address.type)])
79
79
  end
80
80
 
81
81
 
@@ -16,7 +16,7 @@ module HDLRuby::High::Std
16
16
  # - +ruby_block+: the code of the linear computation kernel, it takes
17
17
  # as argument +ev+, and its own req and ack signals
18
18
  # (resp. +req_ker+ +ack_ker+).
19
- function :linearun do |num,ev,req,ack,ruby_block|
19
+ hdef :linearun do |num,ev,req,ack,ruby_block|
20
20
  # Ensure ev is really an event.
21
21
  ev = ev.posedge unless ev.is_a?(Event)
22
22
 
@@ -57,7 +57,7 @@ module HDLRuby::High::Std
57
57
  # Delcares a vector product by a scalar value.
58
58
  #
59
59
  # Can be used for scaling a vector.
60
- function :scale do |typ,ev,req,ack,left,rights,prods,
60
+ hdef :scale do |typ,ev,req,ack,left,rights,prods,
61
61
  mul = proc { |x,y| x*y }|
62
62
  # Ensure ev is really an event.
63
63
  ev = ev.posedge unless ev.is_a?(Event)
@@ -101,7 +101,7 @@ module HDLRuby::High::Std
101
101
  # Declares a 1-dimension vector adder.
102
102
  #
103
103
  # Can be used for the sum of two vectors.
104
- function :add_n do |typ,ev,req,ack,lefts, rights, sums,
104
+ hdef :add_n do |typ,ev,req,ack,lefts, rights, sums,
105
105
  add = proc { |x,y| x+y }|
106
106
  # Ensure ev is really an event.
107
107
  ev = ev.posedge unless ev.is_a?(Event)
@@ -143,7 +143,7 @@ module HDLRuby::High::Std
143
143
  end
144
144
 
145
145
  # Declares a 1-dimension vector element-wise multiplier.
146
- function :mul_n do |typ,ev,req,ack,lefts, rights, prods,
146
+ hdef :mul_n do |typ,ev,req,ack,lefts, rights, prods,
147
147
  mul = proc { |x,y| x*y }|
148
148
  add_n(typ,ev,req,ack,lefts,rights,prods,mul)
149
149
  end
@@ -152,7 +152,7 @@ module HDLRuby::High::Std
152
152
  # Declares a simple multiplier accumulator.
153
153
  #
154
154
  # Can be used for the scalar product of two vectors.
155
- function :mac do |typ,ev,req,ack,left, right, acc,
155
+ hdef :mac do |typ,ev,req,ack,left, right, acc,
156
156
  mul = proc { |x,y| x*y }, add = proc { |x,y| x+y }|
157
157
  # Ensure ev is really an event.
158
158
  ev = ev.posedge unless ev.is_a?(Event)
@@ -193,7 +193,7 @@ module HDLRuby::High::Std
193
193
  # Declares a simple multiple mac with single right data.
194
194
  #
195
195
  # Can be used for the product of a martix-vector product.
196
- function :mac_n1 do |typ,ev,req,ack,lefts, right, accs,
196
+ hdef :mac_n1 do |typ,ev,req,ack,lefts, right, accs,
197
197
  mul = proc { |x,y| x*y }, add = proc { |x,y| x+y }|
198
198
  # Ensure ev is really an event.
199
199
  ev = ev.posedge unless ev.is_a?(Event)
@@ -262,7 +262,7 @@ module HDLRuby::High::Std
262
262
  # Declares a simple pipelined multiple mac with single right data.
263
263
  #
264
264
  # Can be used for the product of a martix-vector product.
265
- function :mac_np do |typ,ev,req,ack,lefts, rights, last,
265
+ hdef :mac_np do |typ,ev,req,ack,lefts, rights, last,
266
266
  mul = proc { |x,y| x*y }, add = proc { |x,y| x+y }|
267
267
  # Ensure ev is really an event.
268
268
  ev = ev.posedge unless ev.is_a?(Event)