HDLRuby 2.5.1 → 2.6.8

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/HDLRuby/hdr_samples/adder.rb +1 -1
  3. data/lib/HDLRuby/hdr_samples/adder_bench.rb +1 -1
  4. data/lib/HDLRuby/hdr_samples/adder_gen.rb +1 -1
  5. data/lib/HDLRuby/hdr_samples/comparison_bench.rb +40 -0
  6. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +27 -0
  7. data/lib/HDLRuby/hdr_samples/dff_unit.rb +3 -3
  8. data/lib/HDLRuby/hdr_samples/huge_rom.rb +25 -0
  9. data/lib/HDLRuby/hdr_samples/logic_bench.rb +21 -0
  10. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +1 -1
  11. data/lib/HDLRuby/hdr_samples/multi_timed_bench.rb +54 -0
  12. data/lib/HDLRuby/hdr_samples/music.rb +79 -0
  13. data/lib/HDLRuby/hdr_samples/named_sub.rb +42 -0
  14. data/lib/HDLRuby/hdr_samples/rom.rb +16 -0
  15. data/lib/HDLRuby/hdr_samples/type_minmax_bench.rb +37 -0
  16. data/lib/HDLRuby/hdr_samples/with_function_generator.rb +25 -0
  17. data/lib/HDLRuby/hdr_samples/with_to_array.rb +29 -0
  18. data/lib/HDLRuby/hdrcc.rb +69 -9
  19. data/lib/HDLRuby/hruby_decorator.rb +3 -1
  20. data/lib/HDLRuby/hruby_high.rb +220 -29
  21. data/lib/HDLRuby/hruby_low.rb +433 -45
  22. data/lib/HDLRuby/hruby_low2c.rb +122 -168
  23. data/lib/HDLRuby/hruby_low2hdr.rb +738 -0
  24. data/lib/HDLRuby/hruby_low2high.rb +331 -549
  25. data/lib/HDLRuby/hruby_low2vhd.rb +39 -2
  26. data/lib/HDLRuby/hruby_low_bool2select.rb +29 -0
  27. data/lib/HDLRuby/hruby_low_casts_without_expression.rb +27 -0
  28. data/lib/HDLRuby/hruby_low_fix_types.rb +25 -0
  29. data/lib/HDLRuby/hruby_low_mutable.rb +70 -0
  30. data/lib/HDLRuby/hruby_low_resolve.rb +28 -0
  31. data/lib/HDLRuby/hruby_low_without_connection.rb +6 -3
  32. data/lib/HDLRuby/hruby_low_without_namespace.rb +7 -4
  33. data/lib/HDLRuby/hruby_low_without_select.rb +13 -0
  34. data/lib/HDLRuby/hruby_tools.rb +11 -1
  35. data/lib/HDLRuby/hruby_verilog.rb +1572 -1723
  36. data/lib/HDLRuby/sim/hruby_sim.h +45 -5
  37. data/lib/HDLRuby/sim/hruby_sim_calc.c +192 -20
  38. data/lib/HDLRuby/sim/hruby_sim_core.c +24 -9
  39. data/lib/HDLRuby/sim/hruby_sim_vcd.c +7 -3
  40. data/lib/HDLRuby/sim/hruby_sim_vizualize.c +22 -6
  41. data/lib/HDLRuby/std/fixpoint.rb +9 -0
  42. data/lib/HDLRuby/std/function_generator.rb +139 -0
  43. data/lib/HDLRuby/std/hruby_unit.rb +75 -0
  44. data/lib/HDLRuby/version.rb +1 -1
  45. metadata +18 -6
  46. data/lib/HDLRuby/hruby_unit.rb +0 -43
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 53e83131d2fb3a3f03c085a3139a69d70f4422ade7be950d009e97e17bb92490
4
- data.tar.gz: dcbbcbf3bd1e5aa43ac359e502dc0da6dec886d115371f3b2fceead01bcaa9d3
3
+ metadata.gz: 01f27a3801dbe93fa55cba40a6a66b91f94df070e255689ac9d73f894b006bd0
4
+ data.tar.gz: 911aadbbb04317300946682df515527e72602d36aacb792bc2c3f80ea88fa14d
5
5
  SHA512:
6
- metadata.gz: 1656a5763fef86bd1b8c01eff8d377cc94ff3145889fd486fac99ac7d86b6f6671a30e040679f81da6a76bc08ee09ff5babd11cae72fc8adb721f0258e724fb9
7
- data.tar.gz: 8f83372948477da9374abf302ab3910d73b434b22aa020b25071f2ed9127dc7ee95b3c6959952bd9ec008f1ff17327c7edc9e1b9584d1437a530a753b0886f4d
6
+ metadata.gz: ea09062dfce477be1db11be382672323711d6fa996cb2f3716cd43692ba1063f9ccd651b6b870a09b319fbd8374b82635075a72b00b89a8e305385adf72c097b
7
+ data.tar.gz: 0ecc3b863e4e41ed3f25083dcf579b014a2a6d04dfb41cd71262d45d115b4efb23d8d869c714508ada05b0a239afd484143733a16343f9fd8738375bbf871dbe
@@ -3,5 +3,5 @@ system :adder do
3
3
  [15..0].input :x,:y
4
4
  [16..0].output :s
5
5
 
6
- s <= x + y
6
+ s <= x.as(bit[17]) + y
7
7
  end
@@ -3,7 +3,7 @@ system :adder do
3
3
  [15..0].input :x,:y
4
4
  [16..0].output :s
5
5
 
6
- s <= x + y
6
+ s <= x.as(bit[17]) + y
7
7
  end
8
8
 
9
9
  # A benchmark for the adder.
@@ -3,5 +3,5 @@ system :adder do |w|
3
3
  [(w-1)..0].input :x,:y
4
4
  [w..0].output :s
5
5
 
6
- s <= x + y
6
+ s <= x.as(bit[w+1]) + y
7
7
  end
@@ -0,0 +1,40 @@
1
+ # Test the comparison operators.
2
+
3
+ # A benchmark for the adder.
4
+ system :adder_bench do
5
+ [8].inner :x, :y
6
+ signed[8].inner :u,:v
7
+ inner :ue, :ult, :ule, :ugt, :uge
8
+ inner :se, :slt, :sle, :sgt, :sge
9
+
10
+ par do
11
+ ue <= (x == y)
12
+ ult <= (x < y)
13
+ ule <= (x <= y)
14
+ ugt <= (x > y)
15
+ uge <= (x >= y)
16
+
17
+ se <= (u == v)
18
+ slt <= (u < v)
19
+ sle <= (u <= v)
20
+ sgt <= (u > v)
21
+ sge <= (u >= v)
22
+ end
23
+
24
+ timed do
25
+ x <= 0
26
+ y <= 0
27
+ u <= 0
28
+ v <= 0
29
+ !10.ns
30
+ x <= 1
31
+ u <= 1
32
+ !10.ns
33
+ y <= 2
34
+ v <= 2
35
+ !10.ns
36
+ x <= 2
37
+ u <= -2
38
+ !10.ns
39
+ end
40
+ end
@@ -0,0 +1,27 @@
1
+ # Sample for testing constant declaration in function.
2
+
3
+
4
+ function :func do |addr|
5
+ bit[4][-4].constant tbl: [ _0000, _0001, _0010, _0011 ]
6
+
7
+ tbl[addr]
8
+ end
9
+
10
+
11
+ system :with_func do
12
+ [4].inner :addr, :val
13
+
14
+ val <= func(addr)
15
+ # val <= 1
16
+
17
+ timed do
18
+ addr <= 0
19
+ !10.ns
20
+ addr <= 1
21
+ !10.ns
22
+ addr <= 2
23
+ !10.ns
24
+ addr <= 3
25
+ !10.ns
26
+ end
27
+ end
@@ -1,9 +1,9 @@
1
1
  # Testing HDLRuby unit test.
2
- # require 'hruby_unit.rb'
2
+ # require 'std/hruby_unit.rb'
3
3
 
4
4
  # Declare multiple simple dff-systems and their corresponding test.
5
5
 
6
- 1.times do |i|
6
+ 3.times do |i|
7
7
 
8
8
  # A simple D-FF
9
9
  system:"dff#{i}" do
@@ -21,7 +21,7 @@
21
21
 
22
22
  send(:"dff#{i}",:dffI).(clk,rst,d,q,qb)
23
23
 
24
- timed do
24
+ test do
25
25
  clk <= 0
26
26
  rst <= 0
27
27
  d <= 0
@@ -0,0 +1,25 @@
1
+ # Describes an 8-bit data 16-bit address ROM.
2
+ system :huge_rom do
3
+ [15..0].input :addr
4
+ [7..0].output :data
5
+
6
+ bit[7..0][-65536].constant content: 65536.times.to_a
7
+
8
+ data <= content[addr]
9
+ end
10
+
11
+
12
+
13
+ system :test_rom do
14
+ [15..0].inner :addr
15
+ [7..0].inner :data
16
+
17
+ huge_rom(:my_rom).(addr,data)
18
+
19
+ timed do
20
+ 8.times do |i|
21
+ addr <= i
22
+ !10.ns
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+
2
+ # A benchmark for the logic operations.
3
+ system :logic_bench do
4
+ [3].inner :x,:y
5
+ [3].inner :s_not, :s_and, :s_or, :s_xor, :s_nxor
6
+
7
+ timed do
8
+ 8.times do |i|
9
+ 8.times do |j|
10
+ x <= i
11
+ y <= j
12
+ s_not <= ~x
13
+ s_and <= x & y
14
+ s_or <= x | y
15
+ s_xor <= x ^ y
16
+ s_nxor <= (x == y)
17
+ !10.ns
18
+ end
19
+ end
20
+ end
21
+ end
@@ -28,7 +28,7 @@ system :mei8 do |prog_file = "./prog.obj"|
28
28
  bit[7..0][-256].constant mem: # The content of the memory
29
29
  ( File.readlines(prog_file).map {|l| l.split[0] }.select do |l|
30
30
  ["0","1"].include?(l[2])
31
- end.map {|l| l[2..9] } )
31
+ end.map {|l| l[2..9].to_i(2) } )
32
32
  instr <= mem[addr] # The access procedure
33
33
  end
34
34
 
@@ -0,0 +1,54 @@
1
+ # Test the execution of multiple timed behaviors
2
+ system :multi_timed do
3
+ inner :clk1, :clk2, :rst, :button
4
+ [8].inner :counter1, :counter2
5
+
6
+ # The process controlling counter1.
7
+ par(clk1.posedge) do
8
+ hif(rst) { counter1 <= 0 }
9
+ helsif(button) { counter1 <= counter1 + 1 }
10
+ end
11
+
12
+ # The process controlling counter2.
13
+ par(clk2.posedge) do
14
+ hif(rst) { counter2 <= 0 }
15
+ helsif(button) { counter2 <= counter2 + 1 }
16
+ end
17
+
18
+ # The process for clk1
19
+ timed do
20
+ 50.times do
21
+ clk1 <= 0
22
+ !10.ns
23
+ clk1 <= 1
24
+ !10.ns
25
+ end
26
+ end
27
+
28
+ # The process for clk2
29
+ timed do
30
+ 80.times do
31
+ clk2 <= 0
32
+ !3.ns
33
+ clk2 <= 1
34
+ !3.ns
35
+ end
36
+ end
37
+
38
+ # The control process
39
+ timed do
40
+ rst <= 0
41
+ button <= 0
42
+ !10.ns
43
+ rst <= 1
44
+ !20.ns
45
+ rst <= 0
46
+ !10.ns
47
+ 10.times do
48
+ button <= 1
49
+ !20.ns
50
+ button <= 0
51
+ !20.ns
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,79 @@
1
+ # require "std/fixpoint.rb"
2
+ # require_relative "activation_function.rb"
3
+ require 'std/function_generator.rb'
4
+
5
+ include HDLRuby::High::Std
6
+
7
+ system :music do
8
+
9
+ input :clk, :rst
10
+ [24].output :sound
11
+
12
+ # func_sin = proc { |i| Math.sin(i) }
13
+ # More efficient:
14
+ func_sin = Math.method(:sin)
15
+
16
+ # bit[8,8].inner :time
17
+ # signed[2,22].inner :sin_val0
18
+ # signed[2,22].inner :sin_val1
19
+ bit[8].inner :time
20
+ signed[24].inner :sin_val0
21
+ signed[24].inner :sin_val1
22
+
23
+ # activation_function(func_sin,signed[2,22],8,8,16).(:func_sin0_generator).(time,sin_val0)
24
+ # activation_function(func_sin,signed[2,22],8,8,16).(:func_sin1_generator).(time/2,sin_val1)
25
+ function_generator(func_sin,bit[8],signed[24],4,-Math::PI..Math::PI,-2..2).(:func_sin0_generator).(time,sin_val0)
26
+ function_generator(func_sin,bit[8],signed[24],4,-Math::PI*2..Math::PI*2,-2..2).(:func_sin1_generator).(time/2,sin_val1)
27
+
28
+ # signed[2,22].inner :sound0
29
+ signed[48].inner :sound0
30
+
31
+ sound0 <= sin_val0.as(signed[24]) * sin_val1
32
+
33
+ sound <= sound0[47..24]
34
+
35
+ par(clk.posedge) do
36
+ hif(rst) { time <= 0 }
37
+ helse do
38
+ # time <= time + _0000000000000001
39
+ time <= time + _00000001
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+
46
+
47
+
48
+ system :music_test do
49
+
50
+ inner :clk,:rst
51
+ [24].inner :sound
52
+
53
+ music(:my_music).(clk,rst,sound)
54
+
55
+ timed do
56
+ clk <= 0
57
+ rst <= 0
58
+ !10.ns
59
+ clk <= 1
60
+ !10.ns
61
+ clk <= 0
62
+ rst <= 1
63
+ !10.ns
64
+ clk <= 1
65
+ !10.ns
66
+ clk <= 0
67
+ !10.ns
68
+ clk <= 1
69
+ !10.ns
70
+ clk <= 0
71
+ rst <= 0
72
+ 256.times do
73
+ !10.ns
74
+ clk <= 1
75
+ !10.ns
76
+ clk <= 0
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,42 @@
1
+ ##
2
+ # Sample testing named sub
3
+ #######################################
4
+
5
+
6
+ # A simple circuit with named sub
7
+ system :named_sub do
8
+ input :x, :y
9
+ output :s
10
+
11
+ sub :somesub do
12
+ inner :sig
13
+ end
14
+
15
+ seq do
16
+ somesub.sig <= x | y
17
+ s <= ~somesub.sig
18
+ end
19
+
20
+ end
21
+
22
+ # A benchmark for the circuit.
23
+ system :named_sub_bench do
24
+ inner :x, :y, :s
25
+
26
+ named_sub(:my_named_sub).(x,y,s)
27
+
28
+ timed do
29
+ x <= 0
30
+ y <= 0
31
+ !10.ns
32
+ x <= 1
33
+ y <= 0
34
+ !10.ns
35
+ x <= 0
36
+ y <= 1
37
+ !10.ns
38
+ x <= 1
39
+ y <= 1
40
+ !10.ns
41
+ end
42
+ end
@@ -14,3 +14,19 @@ system :rom4_8 do
14
14
  data1 <= content1[addr]
15
15
  data2 <= content2[addr]
16
16
  end
17
+
18
+
19
+
20
+ system :test_rom do
21
+ [2..0].inner :addr
22
+ [7..0].inner :data0,:data1,:data2
23
+
24
+ rom4_8(:my_rom).(addr,data0,data1,data2)
25
+
26
+ timed do
27
+ 8.times do |i|
28
+ addr <= i
29
+ !10.ns
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,37 @@
1
+ # Test the type method min and max
2
+
3
+ # A benchmark for the adder.
4
+ system :adder_bench do
5
+ [32].inner :x
6
+ signed[32].inner :y
7
+
8
+ timed do
9
+ x <= 0
10
+ y <= 0
11
+ !10.ns
12
+ x <= bit[8].max
13
+ y <= signed[8].max
14
+ !10.ns
15
+ x <= bit[8].min
16
+ y <= signed[8].min
17
+ !10.ns
18
+ x <= bit[10].max
19
+ y <= signed[10].max
20
+ !10.ns
21
+ x <= bit[10].min
22
+ y <= signed[10].min
23
+ !10.ns
24
+ x <= bit[16].max
25
+ y <= signed[16].max
26
+ !10.ns
27
+ x <= bit[16].min
28
+ y <= signed[16].min
29
+ !10.ns
30
+ x <= bit[32].max
31
+ y <= signed[32].max
32
+ !10.ns
33
+ x <= bit[32].min
34
+ y <= signed[32].min
35
+ !10.ns
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ require 'std/function_generator.rb'
2
+
3
+ include HDLRuby::High::Std
4
+
5
+ # System for testing the function generator standard library.
6
+ system :with_function_generator do
7
+ # signed[8].inner :x
8
+ # signed[32].inner :y
9
+ bit[8].inner :x
10
+ signed[8].inner :y
11
+
12
+ # function_generator(Math.method(:sin).to_proc,
13
+ # signed[8],signed[32],4,-Math::PI..Math::PI,-2..2).
14
+ function_generator(Math.method(:sin).to_proc,
15
+ bit[8],signed[8],4,-Math::PI..Math::PI,-2..2).
16
+ (:my_sin).(x,y)
17
+
18
+ timed do
19
+ # (-128..127).each do |i|
20
+ (0..255).each do |i|
21
+ x <= i
22
+ !10.ns
23
+ end
24
+ end
25
+ end