HDLRuby 3.9.5 → 3.9.7

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.
@@ -471,6 +471,43 @@ void execute_statement(Statement stmnt, int mode, Behavior behavior) {
471
471
  }
472
472
  break;
473
473
  }
474
+ case HCASEZ:
475
+ {
476
+ HCaseZ hcasez = (HCaseZ)stmnt;
477
+ /* Calculation the value to check. */
478
+ // Value value = calc_expression(hcasez->value);
479
+ Value value = get_value();
480
+ value = calc_expression(hcasez->value,value);
481
+ /* Tell if a casez if matched. */
482
+ int met = 0;
483
+ /* Check each case. */
484
+ Value cmp = get_value();
485
+ for(int i=0; i<hcasez->num_whens; ++i) {
486
+ // cmp = equal_value_z_c(value,calc_expression(hcasez->matches[i]),
487
+ // cmp);
488
+ Value match = get_value();
489
+ match = calc_expression(hcasez->matches[i],match);
490
+ cmp = equal_value_z_c(value,match,cmp);
491
+ if (is_defined_value(cmp) && value2integer(cmp)) {
492
+ /* Found the right case, execute the corresponding
493
+ * statement. */
494
+ execute_statement(hcasez->stmnts[i],mode,behavior);
495
+ /* And remeber it. */
496
+ met = 1;
497
+ free_value();
498
+ break;
499
+ }
500
+ free_value();
501
+ }
502
+ free_value();
503
+ free_value();
504
+ /* Was no case found and is there a default statement? */
505
+ if (!met && hcasez->defolt) {
506
+ /* Yes, execute the default statement. */
507
+ execute_statement(hcasez->defolt,mode,behavior);
508
+ }
509
+ break;
510
+ }
474
511
  case TIME_WAIT:
475
512
  {
476
513
  /* Get the value of the delay. */
@@ -1,4 +1,4 @@
1
- # Test the comparison operators.
1
+ # Test the case.
2
2
 
3
3
  # A benchmark for the case statement.
4
4
  system :case_bench do
@@ -2,25 +2,25 @@
2
2
  # A benchmark for the logic operations.
3
3
  system :logic_bench do
4
4
  [3].inner :x,:y
5
- [3].inner :s_not, :s_and, :s_or, :s_xor, :s_nxor
5
+ [3].inner :s_not, :s_and, :s_or, :s_xor, :s_eq
6
6
 
7
7
  signed[16].inner :a,:b,:shl,:shr
8
8
 
9
9
  timed do
10
10
  8.times do |i|
11
11
  8.times do |j|
12
- x <= i
13
- y <= j
14
- s_not <= ~x
15
- s_and <= x & y
16
- s_or <= x | y
17
- s_xor <= x ^ y
18
- s_nxor <= (x == y)
12
+ x <= i
13
+ y <= j
14
+ s_not <= ~x
15
+ s_and <= x & y
16
+ s_or <= x | y
17
+ s_xor <= x ^ y
18
+ s_eq <= (x == y)
19
19
  !10.ns
20
- a <= i
21
- b <= j
22
- shl <= (a << b)
23
- shr <= (a >> b)
20
+ a <= i
21
+ b <= j
22
+ shl <= (a << b)
23
+ shr <= (a >> b)
24
24
  end
25
25
  end
26
26
  end
@@ -0,0 +1,19 @@
1
+ system :assign_to_slice do
2
+ [8].inner :reg
3
+
4
+ timed do
5
+ !10.ns
6
+ reg[1..0] <= _b00
7
+ !10.ns
8
+ reg[3..2] <= _b01
9
+ !10.ns
10
+ reg[5..4] <= _b10
11
+ !10.ns
12
+ reg[7..6] <= _b11
13
+ !10.ns
14
+ reg[3..0] <= _ha
15
+ !10.ns
16
+ reg[7..4] <= _h5
17
+ !10.ns
18
+ end
19
+ end
@@ -0,0 +1,40 @@
1
+ # A test of auto connection.
2
+
3
+
4
+ system :adder8 do
5
+ [8].input :x, :y
6
+ [8].output :z
7
+
8
+ z <= x + y
9
+ end
10
+
11
+ system :adder do |n|
12
+ [n].input :x, :y
13
+ [n].output :s
14
+
15
+ s <= x + y
16
+ end
17
+
18
+
19
+ # A benchmark for testing the auto connection.
20
+ system :auto_connect_bench do
21
+
22
+ [8].inner :x, :y, :z #, :s # For checking non-existant signal
23
+
24
+ adder8(:my_adder8).auto_connect
25
+ adder(8).(:my_adder).auto_connect
26
+
27
+ timed do
28
+ x <= 0
29
+ y <= 0
30
+ !10.ns
31
+ x <= x + 1
32
+ !10.ns
33
+ y <= y + 1
34
+ !10.ns
35
+ x <= x + 1
36
+ !10.ns
37
+ y <= y + 1
38
+ !10.ns
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ # Test the casez statement.
2
+
3
+ # A benchmark for the case statement.
4
+ system :case_bench do
5
+ [8].inner :x, :z
6
+
7
+ par do
8
+ hcasez(x)
9
+ hwhen(_b0000_0000) { z <= 0 }
10
+ hwhen(_b000z_0001) { z <= 1 }
11
+ hwhen(_b00z0_0010) { z <= 4 }
12
+ hwhen(_b00zz_0011) { z <= 9 }
13
+ hwhen(_b0z00_0100) { z <= 16 }
14
+ hwhen(_b0z0z_0101) { z <= 25 }
15
+ hwhen(_b0zz0_0110) { z <= 36 }
16
+ hwhen(_b0zzz_0111) { z <= 49 }
17
+ hwhen(_bz000_1000) { z <= 64 }
18
+ hwhen(_bz00z_1001) { z <= 81 }
19
+ hwhen(_bz0z0_1010) { z <= 100 }
20
+ hwhen(_bz0zz_1011) { z <= 121 }
21
+ hwhen(_bzz00_1100) { z <= 144 }
22
+ hwhen(_bzz0z_1101) { z <= 169 }
23
+ hwhen(_bzzz0_1110) { z <= 196 }
24
+ hwhen(_bzzzz_1111) { z <= 225 }
25
+ helse { z <= _zzzzzzzz }
26
+ end
27
+
28
+ timed do
29
+ !10.ns
30
+ 20.times do |i|
31
+ x <= i
32
+ !10.ns
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ # Test the expression decodor syntatic sugars.
2
+
3
+ # A benchmark for the expression decoder.
4
+ system :expr_decoder_bench do
5
+ [8].inner :x, :y, :z
6
+ inner :a,:b,:c, :u, :v, :w, :s
7
+
8
+ seq do
9
+ decoder(x,y,z).(u,[1,2,3]).(v,[1]).(w,[nil,nil,3])
10
+ [a,b,c] <= decoder(x,1,2,3)
11
+ decoder(x,y,z,:|).(s,[1,2,3])
12
+ end
13
+
14
+ timed do
15
+ !10.ns
16
+ x <= 0
17
+ y <= 1
18
+ z <= 2
19
+ !10.ns
20
+ x <= 0
21
+ y <= 1
22
+ z <= 3
23
+ !10.ns
24
+ x <= 1
25
+ y <= 2
26
+ z <= 0
27
+ !10.ns
28
+ x <= 1
29
+ y <= 2
30
+ z <= 3
31
+ !10.ns
32
+ x <= 2
33
+ !10.ns
34
+ x <= 3
35
+ !10.ns
36
+ end
37
+ end
38
+
@@ -0,0 +1,34 @@
1
+ # Test the expression if syntatic sugars.
2
+
3
+ # A benchmark for the expression if.
4
+ system :expr_if_bench do
5
+ [8].inner :x, :y, :z, :a, :b, :c, :d, :u, :v, :w, :s
6
+
7
+ seq do
8
+ u <= hif(x < y, a, b)
9
+ v <= hif(x < y, a).(b)
10
+ w <= hif(x < y, a).(x < z, b, c)
11
+ s <= hif(x < y, a).(x < z, b).(y < z, c, d)
12
+ end
13
+
14
+ timed do
15
+ !10.ns
16
+ a <= 1
17
+ b <= 2
18
+ c <= 3
19
+ d <= 4
20
+ x <= 0
21
+ y <= 1
22
+ z <= 2
23
+ !10.ns
24
+ x <= x + 1
25
+ !10.ns
26
+ x <= x + 1
27
+ !10.ns
28
+ x <= x + 1
29
+ !10.ns
30
+ y <= x
31
+ !10.ns
32
+ end
33
+ end
34
+
@@ -0,0 +1,42 @@
1
+ system :with_hbreak do
2
+
3
+ # The clock and reset
4
+ inner :clk, :rst
5
+
6
+ # A counter.
7
+ [8].inner :count
8
+
9
+ par(clk.posedge) do
10
+ hif(rst) do
11
+ count <= 0
12
+ hbreak
13
+ end
14
+ # helse { count <= count + 1 }
15
+ count <= count + 1
16
+ end
17
+
18
+
19
+ timed do
20
+ clk <= 0
21
+ rst <= 0
22
+ !10.ns
23
+ clk <= 1
24
+ !10.ns
25
+ clk <= 0
26
+ rst <= 1
27
+ !10.ns
28
+ clk <= 1
29
+ !10.ns
30
+ clk <= 0
31
+ rst <= 0
32
+ !10.ns
33
+ clk <= 1
34
+ !10.ns
35
+ 64.times do
36
+ clk <= 0
37
+ !10.ns
38
+ clk <= 1
39
+ !10.ns
40
+ end
41
+ end
42
+ end
@@ -344,7 +344,7 @@ system :henmerable_checks do
344
344
 
345
345
  par(clk.posedge) do
346
346
  # hprint("}0\n")
347
- vals.hzip([_h12]*8).each_with_index { |(a,b),i| res62[i] <= a+b }
347
+ vals.hzip([_h12]*8).heach_with_index { |(a,b),i| res62[i] <= a+b }
348
348
  end
349
349
 
350
350
  # Test enumerators of values.
@@ -75,5 +75,8 @@ system :with_values do
75
75
  !10.ns
76
76
  v8 <= _CST
77
77
  !10.ns
78
+ v8 <= _8b1
79
+ v16 <= _16hx
80
+ !10.ns
78
81
  end
79
82
  end