HDLRuby 3.0.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.
- checksums.yaml +4 -4
- data/HDLRuby.gemspec +1 -0
- data/README.md +149 -79
- data/ext/hruby_sim/hruby_rcsim_build.c +2 -0
- data/ext/hruby_sim/hruby_sim_calc.c +33 -6
- data/ext/hruby_sim/hruby_sim_tree_calc.c +111 -22
- data/lib/HDLRuby/hdr_samples/comparison_bench.rb +2 -2
- data/lib/HDLRuby/hdr_samples/constant_in_function.rb +2 -1
- data/lib/HDLRuby/hdr_samples/counter_bench.rb +1 -1
- data/lib/HDLRuby/hdr_samples/counter_dff_bench.rb +8 -7
- data/lib/HDLRuby/hdr_samples/dff_properties.rb +2 -0
- data/lib/HDLRuby/hdr_samples/enum_as_param.rb +52 -0
- data/lib/HDLRuby/hdr_samples/linear_test.rb +2 -0
- data/lib/HDLRuby/hdr_samples/logic_bench.rb +6 -0
- data/lib/HDLRuby/hdr_samples/mei8.rb +6 -6
- data/lib/HDLRuby/hdr_samples/mei8_bench.rb +6 -6
- data/lib/HDLRuby/hdr_samples/memory_test.rb +2 -0
- data/lib/HDLRuby/hdr_samples/named_sub.rb +9 -5
- data/lib/HDLRuby/hdr_samples/ram.rb +7 -6
- data/lib/HDLRuby/hdr_samples/ruby_fir_hw.rb +2 -0
- data/lib/HDLRuby/hdr_samples/struct.rb +15 -3
- data/lib/HDLRuby/hdr_samples/with_bram.rb +1 -1
- data/lib/HDLRuby/hdr_samples/with_bram_frame_stack.rb +1 -1
- data/lib/HDLRuby/hdr_samples/with_bram_stack.rb +1 -1
- data/lib/HDLRuby/hdr_samples/with_channel.rb +2 -0
- data/lib/HDLRuby/hdr_samples/with_channel_other.rb +2 -0
- data/lib/HDLRuby/hdr_samples/with_class.rb +3 -1
- data/lib/HDLRuby/hdr_samples/with_connector.rb +2 -0
- data/lib/HDLRuby/hdr_samples/with_connector_memory.rb +2 -0
- data/lib/HDLRuby/hdr_samples/with_fixpoint.rb +6 -0
- data/lib/HDLRuby/hdr_samples/with_fixpoint_adv.rb +73 -0
- data/lib/HDLRuby/hdr_samples/with_leftright.rb +1 -1
- data/lib/HDLRuby/hdr_samples/with_ref_expr.rb +30 -0
- data/lib/HDLRuby/hdr_samples/with_sequencer.rb +49 -37
- data/lib/HDLRuby/hdr_samples/with_sequencer_channel.rb +58 -0
- data/lib/HDLRuby/hdr_samples/with_sequencer_enumerable.rb +113 -69
- data/lib/HDLRuby/hdr_samples/with_sequencer_enumerator.rb +28 -14
- data/lib/HDLRuby/hdr_samples/with_sequencer_func.rb +63 -0
- data/lib/HDLRuby/hdr_samples/with_sequencer_sync.rb +2 -1
- data/lib/HDLRuby/hdrcc.rb +13 -1
- data/lib/HDLRuby/hruby_high.rb +105 -31
- data/lib/HDLRuby/hruby_low.rb +127 -3
- data/lib/HDLRuby/hruby_low2programs.rb +47 -0
- data/lib/HDLRuby/hruby_low_resolve.rb +3 -2
- data/lib/HDLRuby/hruby_low_without_namespace.rb +133 -5
- data/lib/HDLRuby/hruby_low_without_subsignals.rb +51 -12
- data/lib/HDLRuby/hruby_rcsim.rb +24 -1
- data/lib/HDLRuby/hruby_serializer.rb +2 -1
- data/lib/HDLRuby/hruby_types.rb +5 -5
- data/lib/HDLRuby/hruby_values.rb +7 -7
- data/lib/HDLRuby/hruby_verilog.rb +193 -35
- data/lib/HDLRuby/hruby_verilog_name.rb +35 -42
- data/lib/HDLRuby/std/fixpoint.rb +2 -2
- data/lib/HDLRuby/std/fsm.rb +10 -1
- data/lib/HDLRuby/std/function_generator.rb +1 -1
- data/lib/HDLRuby/std/linear.rb +7 -7
- data/lib/HDLRuby/std/sequencer.rb +538 -60
- data/lib/HDLRuby/std/sequencer_channel.rb +90 -0
- data/lib/HDLRuby/std/sequencer_func.rb +546 -0
- data/lib/HDLRuby/std/std.rb +2 -0
- data/lib/HDLRuby/version.rb +1 -1
- data/tuto/tutorial_sw.md +267 -61
- metadata +25 -4
- data/lib/HDLRuby/hdr_samples/with_register_stack.rb +0 -150
|
@@ -89,10 +89,10 @@ module HDLRuby::Low
|
|
|
89
89
|
# Convert the ranges to arrays.
|
|
90
90
|
rngI,rngS = self.r2a(rngI), self.r2a(rngS)
|
|
91
91
|
# Generate the name.
|
|
92
|
-
return "
|
|
92
|
+
return "truncer_#{rngI[0]}_#{rngI[1]}_#{rngS[0]}_#{rngS[1]}"
|
|
93
93
|
end
|
|
94
94
|
|
|
95
|
-
# Generate the truncating
|
|
95
|
+
# Generate the truncating functions.
|
|
96
96
|
def dump
|
|
97
97
|
# Ensure there is only one truncating function per range.
|
|
98
98
|
@truncers.sort!.uniq!
|
|
@@ -117,12 +117,69 @@ module HDLRuby::Low
|
|
|
117
117
|
TruncersI = Truncers.new
|
|
118
118
|
|
|
119
119
|
|
|
120
|
+
# Class for generating the truncating functions in verilog.
|
|
121
|
+
# Such function are necessary as expression cannot be truncated directly.
|
|
122
|
+
class Indexers
|
|
123
|
+
def initialize
|
|
124
|
+
@indexers = []
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Add an indexer to of expression of verilog type +typI+ returning
|
|
128
|
+
# verilog type +typR+.
|
|
129
|
+
def add(typI,typR)
|
|
130
|
+
# Add them
|
|
131
|
+
@indexers << [typI,typR]
|
|
132
|
+
end
|
|
133
|
+
alias_method :<<, :add
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# Generate an indexer function name for expression of verilog type
|
|
137
|
+
# +typI+ returning verilog type +typR+.
|
|
138
|
+
def indexer_name(typI,typR)
|
|
139
|
+
# Generate the name.
|
|
140
|
+
return "indexer_#{name_to_verilog(typI)}_#{name_to_verilog(typR)}"
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Generate the indexing functions.
|
|
144
|
+
def dump
|
|
145
|
+
# Ensure there is only one indexing function per range.
|
|
146
|
+
@indexers.sort!.uniq!
|
|
147
|
+
# Generate the resulting code.
|
|
148
|
+
codeT = ""
|
|
149
|
+
@indexers.each do |(typI,typR)|
|
|
150
|
+
codeT << " function #{typR} "
|
|
151
|
+
codeT << self.indexer_name(typI,typR)
|
|
152
|
+
codeT << "(input #{typI} val, input integer idx);\n"
|
|
153
|
+
codeT << " " << self.indexer_name(typI,typR) << " = "
|
|
154
|
+
codeT << "val[idx];\n"
|
|
155
|
+
codeT << " endfunction\n\n"
|
|
156
|
+
end
|
|
157
|
+
# Clears the indexers.
|
|
158
|
+
@indexers = []
|
|
159
|
+
return codeT
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# Declaration of the truncating function generator.
|
|
164
|
+
IndexersI = Indexers.new
|
|
165
|
+
|
|
166
|
+
|
|
120
167
|
class Binary
|
|
121
168
|
## Enhances Binary with verilog generation.
|
|
122
169
|
|
|
123
170
|
# Converts the system to Verilog code.
|
|
124
171
|
def to_verilog
|
|
125
|
-
|
|
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
|
|
126
183
|
end
|
|
127
184
|
|
|
128
185
|
# Method called when two or more expression terms are present.
|
|
@@ -215,7 +272,6 @@ module HDLRuby::Low
|
|
|
215
272
|
# Declaration of "inner" part within "always".
|
|
216
273
|
block.each_inner do |inner|
|
|
217
274
|
if HDLRuby::Low::VERILOG_REGS.include?(inner.to_verilog) then
|
|
218
|
-
# code << " reg"
|
|
219
275
|
code << "#{" " * (spc+3)}reg"
|
|
220
276
|
else
|
|
221
277
|
code << "#{" " * (spc+3)}wire"
|
|
@@ -1454,7 +1510,14 @@ module HDLRuby::Low
|
|
|
1454
1510
|
|
|
1455
1511
|
# Converts the system to Verilog code using +renamer+ for producing Verilog-compatible names.
|
|
1456
1512
|
def to_verilog
|
|
1457
|
-
|
|
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
|
|
1458
1521
|
# self.properties[:verilog_name] = vname
|
|
1459
1522
|
return "#{vname}"
|
|
1460
1523
|
end
|
|
@@ -1479,7 +1542,16 @@ module HDLRuby::Low
|
|
|
1479
1542
|
|
|
1480
1543
|
# Converts the system to Verilog code.
|
|
1481
1544
|
def to_verilog
|
|
1482
|
-
return "#{self.ref.to_verilog}[#{self.index.to_verilog}]"
|
|
1545
|
+
# return "#{self.ref.to_verilog}[#{self.index.to_verilog}]"
|
|
1546
|
+
if self.ref.is_a?(RefName) then
|
|
1547
|
+
return "#{self.ref.to_verilog}[#{self.index.to_verilog}]"
|
|
1548
|
+
else
|
|
1549
|
+
# No a pure signal, need to use a function for accessing.
|
|
1550
|
+
at = self.ref.type.to_verilog
|
|
1551
|
+
rt = self.type.to_verilog
|
|
1552
|
+
IndexersI.add(at,rt)
|
|
1553
|
+
return "#{IndexersI.indexer_name(at,rt)}(#{self.ref.to_verilog},#{self.index.to_verilog})"
|
|
1554
|
+
end
|
|
1483
1555
|
end
|
|
1484
1556
|
end
|
|
1485
1557
|
|
|
@@ -1505,7 +1577,18 @@ module HDLRuby::Low
|
|
|
1505
1577
|
|
|
1506
1578
|
# Converts the system to Verilog code.
|
|
1507
1579
|
def to_verilog(unknown = false)
|
|
1508
|
-
|
|
1580
|
+
if self.ref.is_a?(RefName) then
|
|
1581
|
+
return "#{self.ref.to_verilog}[#{self.range.first.to_getrange}:#{self.range.last.to_getrange}]"
|
|
1582
|
+
else
|
|
1583
|
+
# No a pure signal, need to use a function for accessing.
|
|
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
|
|
1589
|
+
TruncersI.add(cr,sr)
|
|
1590
|
+
return "#{TruncersI.truncer_name(cr,sr)}(#{self.ref.to_verilog})"
|
|
1591
|
+
end
|
|
1509
1592
|
end
|
|
1510
1593
|
end
|
|
1511
1594
|
|
|
@@ -1576,20 +1659,28 @@ module HDLRuby::Low
|
|
|
1576
1659
|
# end
|
|
1577
1660
|
# return "#{self.type.range.first + 1}'b#{self.content.to_verilog}"
|
|
1578
1661
|
if self.content.is_a?(Numeric) then
|
|
1579
|
-
if self.
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1662
|
+
if self.type.signed? then
|
|
1663
|
+
if self.content < 0 then
|
|
1664
|
+
# str = (2**self.type.width + self.content).to_s(2)
|
|
1665
|
+
str = self.content.to_s(2)
|
|
1666
|
+
str = "0" * (self.type.width-str.length+1) + str[1..-1]
|
|
1667
|
+
return "-#{self.type.width}'sb#{str}"
|
|
1668
|
+
else
|
|
1669
|
+
str = self.content.to_s(2)
|
|
1670
|
+
str = "0" * (self.type.width-str.length) + str
|
|
1671
|
+
return "#{self.type.width}'sb#{str}"
|
|
1672
|
+
end
|
|
1584
1673
|
else
|
|
1585
|
-
|
|
1586
|
-
str = "0" * (self.type.width-str.length) + str
|
|
1587
|
-
return "#{self.type.width}'b#{str}"
|
|
1674
|
+
return "#{self.type.width}'b#{self.content.to_s(2)}"
|
|
1588
1675
|
end
|
|
1589
1676
|
# return "#{self.type.width}'b#{str}"
|
|
1590
1677
|
else
|
|
1591
1678
|
str = self.content.to_verilog
|
|
1592
|
-
|
|
1679
|
+
if self.content.negative? then
|
|
1680
|
+
return "#{str.length}'sb#{str}"
|
|
1681
|
+
else
|
|
1682
|
+
return "#{str.length}'b#{str}"
|
|
1683
|
+
end
|
|
1593
1684
|
end
|
|
1594
1685
|
end
|
|
1595
1686
|
# How to use when simply obtaining the width
|
|
@@ -1663,9 +1754,11 @@ module HDLRuby::Low
|
|
|
1663
1754
|
if self.default then
|
|
1664
1755
|
result << " " * (spc+3) + "default: "
|
|
1665
1756
|
if self.default.each_statement.count >= 1 then
|
|
1757
|
+
result << "begin\n"
|
|
1666
1758
|
result << self.default.each_statement.map do |stmnt|
|
|
1667
|
-
stmnt.to_verilog(spc+
|
|
1759
|
+
stmnt.to_verilog(spc+6)
|
|
1668
1760
|
end.join("\n") << "\n"
|
|
1761
|
+
result << " " * (spc+3) + "end\n"
|
|
1669
1762
|
else
|
|
1670
1763
|
result << ";\n"
|
|
1671
1764
|
end
|
|
@@ -1770,10 +1863,20 @@ module HDLRuby::Low
|
|
|
1770
1863
|
cw = self.child.type.width
|
|
1771
1864
|
sw = self.type.width
|
|
1772
1865
|
if self.type.signed? then
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
return "$signed({
|
|
1776
|
-
|
|
1866
|
+
# Need to sign extend.
|
|
1867
|
+
if cw == 1 then
|
|
1868
|
+
return "$signed({#{sw}{#{self.child.to_verilog}}})"
|
|
1869
|
+
elsif (sw>cw) then
|
|
1870
|
+
# return "$signed({{#{sw-cw}{#{self.child.to_verilog}[#{cw-1}]}}," + "#{self.child.to_verilog}})"
|
|
1871
|
+
if self.child.is_a?(RefName) then
|
|
1872
|
+
return "$signed({{#{sw-cw}{#{self.child.to_verilog}[#{cw-1}]}}," + "#{self.child.to_verilog}})"
|
|
1873
|
+
else
|
|
1874
|
+
# No a pure signal, need to use a function for accessing.
|
|
1875
|
+
at = self.child.type.to_verilog
|
|
1876
|
+
rt = bit.to_verilog
|
|
1877
|
+
IndexersI.add(at,rt)
|
|
1878
|
+
return "$signed({{#{sw-cw}{#{IndexersI.indexer_name(at,rt)}(#{self.child.to_verilog},#{cw-1})}}," + "#{self.child.to_verilog}})"
|
|
1879
|
+
end
|
|
1777
1880
|
elsif (sw<cw) then
|
|
1778
1881
|
# Need to truncate
|
|
1779
1882
|
# return "$signed(#{self.child.to_verilog}[#{sw-1}:0])"
|
|
@@ -1945,11 +2048,60 @@ module HDLRuby::Low
|
|
|
1945
2048
|
end
|
|
1946
2049
|
|
|
1947
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
|
+
|
|
1948
2097
|
|
|
1949
2098
|
# Converts the system to Verilog code.
|
|
1950
2099
|
# NOTE: if +vcd+ is true, generate verilog code whose simulation
|
|
1951
2100
|
# produces a vcd file.
|
|
1952
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}"
|
|
1953
2105
|
# Detect the registers
|
|
1954
2106
|
HDLRuby::Low::VERILOG_REGS.clear
|
|
1955
2107
|
# The left values.
|
|
@@ -1957,11 +2109,15 @@ module HDLRuby::Low
|
|
|
1957
2109
|
behavior.each_block_deep do |block|
|
|
1958
2110
|
block.each_statement do |statement|
|
|
1959
2111
|
if statement.is_a?(Transmit)
|
|
1960
|
-
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))
|
|
1961
2114
|
end
|
|
1962
2115
|
end
|
|
1963
2116
|
end
|
|
1964
2117
|
end
|
|
2118
|
+
self.each_systemI do |systemI|
|
|
2119
|
+
SystemT.get_indirect_verilog_regs(systemI,vname)
|
|
2120
|
+
end
|
|
1965
2121
|
# And the initialized signals.
|
|
1966
2122
|
self.each_output do |output|
|
|
1967
2123
|
# regs << output.to_verilog if output.value
|
|
@@ -1971,17 +2127,18 @@ module HDLRuby::Low
|
|
|
1971
2127
|
# regs << inner.to_verilog if inner.value
|
|
1972
2128
|
HDLRuby::Low::VERILOG_REGS << inner.to_verilog if inner.value
|
|
1973
2129
|
end
|
|
1974
|
-
#
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
end
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
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
|
|
1985
2142
|
|
|
1986
2143
|
# Code generation
|
|
1987
2144
|
inputs = 0
|
|
@@ -1995,7 +2152,6 @@ module HDLRuby::Low
|
|
|
1995
2152
|
# Spelling necessary for simulation.
|
|
1996
2153
|
code = "`timescale 1ps/1ps\n\n"
|
|
1997
2154
|
|
|
1998
|
-
vname = name_to_verilog(self.name)
|
|
1999
2155
|
# self.properties[:verilog_name] = vname
|
|
2000
2156
|
# Output the module name.
|
|
2001
2157
|
code << "module #{vname}("
|
|
@@ -2233,7 +2389,7 @@ module HDLRuby::Low
|
|
|
2233
2389
|
codeC << " initial "
|
|
2234
2390
|
else
|
|
2235
2391
|
# Generate a standard process.
|
|
2236
|
-
codeC << " always @( "
|
|
2392
|
+
codeC << "\n always @( "
|
|
2237
2393
|
# If there is no "always" condition, it is always @("*").
|
|
2238
2394
|
if behavior.each_event.to_a.empty? then
|
|
2239
2395
|
codeC << "*"
|
|
@@ -2288,6 +2444,8 @@ module HDLRuby::Low
|
|
|
2288
2444
|
|
|
2289
2445
|
# Adds the truncing functions.
|
|
2290
2446
|
code << TruncersI.dump
|
|
2447
|
+
# Adds the indexing functions.
|
|
2448
|
+
code << IndexersI.dump
|
|
2291
2449
|
# Adds the content code.
|
|
2292
2450
|
code << codeC
|
|
2293
2451
|
return code
|
|
@@ -1,42 +1,35 @@
|
|
|
1
|
-
# Program with inverse conversion
|
|
2
|
-
# last update 2019 01 29
|
|
3
|
-
|
|
4
|
-
module HDLRuby::Verilog
|
|
5
|
-
|
|
6
|
-
# This is sample.
|
|
7
|
-
# n = "abc_ABC_いろは"
|
|
8
|
-
# puts n
|
|
9
|
-
# name = n.split("")
|
|
10
|
-
|
|
11
|
-
@@hdr2verilog = {}
|
|
12
|
-
|
|
13
|
-
# Since it is possible to use $ and numbers other than the beginning of the character string, it is divided.
|
|
14
|
-
def name_to_verilog(name)
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
#
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
end
|
|
37
|
-
return vname
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
#puts ref
|
|
41
|
-
|
|
42
|
-
end
|
|
1
|
+
# Program with inverse conversion
|
|
2
|
+
# last update 2019 01 29
|
|
3
|
+
|
|
4
|
+
module HDLRuby::Verilog
|
|
5
|
+
|
|
6
|
+
# This is sample.
|
|
7
|
+
# n = "abc_ABC_いろは"
|
|
8
|
+
# puts n
|
|
9
|
+
# name = n.split("")
|
|
10
|
+
|
|
11
|
+
@@hdr2verilog = { "buf" => "_v0_buf", "table" => "_v1_table", "time" => "_v2_time" }
|
|
12
|
+
|
|
13
|
+
# Since it is possible to use $ and numbers other than the beginning of the character string, it is divided.
|
|
14
|
+
def name_to_verilog(name)
|
|
15
|
+
# puts "name_to_verilog with name=#{name}"
|
|
16
|
+
name = name.to_s
|
|
17
|
+
vname = @@hdr2verilog[name]
|
|
18
|
+
unless vname then
|
|
19
|
+
# Shall we change the string?
|
|
20
|
+
if name.match?(/^[_a-zA-Z][_a-zA-Z0-9]*$/) then
|
|
21
|
+
# No, just clone
|
|
22
|
+
vname = name.clone
|
|
23
|
+
else
|
|
24
|
+
# Yes, ensure it is a verilog-compatible name.
|
|
25
|
+
vname = "_v#{@@hdr2verilog.size}_#{name.split(/[^a-zA-Z_0-9]/)[-1]}"
|
|
26
|
+
end
|
|
27
|
+
@@hdr2verilog[name] = vname
|
|
28
|
+
end
|
|
29
|
+
# puts "result vname=#{vname}"
|
|
30
|
+
return vname
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
#puts ref
|
|
34
|
+
|
|
35
|
+
end
|
data/lib/HDLRuby/std/fixpoint.rb
CHANGED
|
@@ -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|
|
data/lib/HDLRuby/std/fsm.rb
CHANGED
|
@@ -219,7 +219,11 @@ module HDLRuby::High::Std
|
|
|
219
219
|
# The default code.
|
|
220
220
|
default_codes.each(&:call)
|
|
221
221
|
# Depending on the state.
|
|
222
|
-
|
|
222
|
+
if (type == :sync) then
|
|
223
|
+
hcase(this.next_state_sig)
|
|
224
|
+
else
|
|
225
|
+
hcase(this.cur_state_sig)
|
|
226
|
+
end
|
|
223
227
|
states.each do |st|
|
|
224
228
|
# Register the working state (for the gotos)
|
|
225
229
|
this.work_state = st
|
|
@@ -345,6 +349,11 @@ module HDLRuby::High::Std
|
|
|
345
349
|
|
|
346
350
|
|
|
347
351
|
## The interface for building the fsm
|
|
352
|
+
|
|
353
|
+
# Gets the current number of states.
|
|
354
|
+
def size
|
|
355
|
+
@states.size
|
|
356
|
+
end
|
|
348
357
|
|
|
349
358
|
# Sets the event synchronizing the fsm.
|
|
350
359
|
def for_event(event = nil,&ruby_block)
|
data/lib/HDLRuby/std/linear.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)
|