STAR-future commited on
Commit
684db41
·
verified ·
1 Parent(s): 055c19b

add chips/yosys (part 8)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. chips/yosys/tests/simple/dff_init.v +54 -0
  2. chips/yosys/tests/simple/dynslice.v +12 -0
  3. chips/yosys/tests/simple/fiedler-cooley.v +33 -0
  4. chips/yosys/tests/simple/forgen01.v +23 -0
  5. chips/yosys/tests/simple/forgen02.v +30 -0
  6. chips/yosys/tests/simple/forloops.v +25 -0
  7. chips/yosys/tests/simple/fsm.v +68 -0
  8. chips/yosys/tests/simple/func_block.v +33 -0
  9. chips/yosys/tests/simple/func_recurse.v +25 -0
  10. chips/yosys/tests/simple/func_width_scope.v +41 -0
  11. chips/yosys/tests/simple/genblk_collide.v +27 -0
  12. chips/yosys/tests/simple/genblk_dive.v +21 -0
  13. chips/yosys/tests/simple/genblk_order.v +18 -0
  14. chips/yosys/tests/simple/genblk_port_shadow.v +10 -0
  15. chips/yosys/tests/simple/generate.v +325 -0
  16. chips/yosys/tests/simple/generate_mk.py +17 -0
  17. chips/yosys/tests/simple/graphtest.v +34 -0
  18. chips/yosys/tests/simple/hierarchy.v +26 -0
  19. chips/yosys/tests/simple/hierdefparam.v +25 -0
  20. chips/yosys/tests/simple/i2c_master_tests.v +61 -0
  21. chips/yosys/tests/simple/ifdef_1.v +88 -0
  22. chips/yosys/tests/simple/ifdef_2.v +21 -0
  23. chips/yosys/tests/simple/implicit_ports.sv +16 -0
  24. chips/yosys/tests/simple/lesser_size_cast.sv +7 -0
  25. chips/yosys/tests/simple/local_loop_var.sv +11 -0
  26. chips/yosys/tests/simple/localparam_attr.v +11 -0
  27. chips/yosys/tests/simple/loop_prefix_case.v +18 -0
  28. chips/yosys/tests/simple/loop_var_shadow.v +15 -0
  29. chips/yosys/tests/simple/loops.v +78 -0
  30. chips/yosys/tests/simple/macro_arg_spaces.sv +28 -0
  31. chips/yosys/tests/simple/macro_arg_surrounding_spaces.v +20 -0
  32. chips/yosys/tests/simple/macros.v +244 -0
  33. chips/yosys/tests/simple/matching_end_labels.sv +29 -0
  34. chips/yosys/tests/simple/mem2reg.v +116 -0
  35. chips/yosys/tests/simple/mem2reg_bounds_tern.v +19 -0
  36. chips/yosys/tests/simple/mem_arst.v +40 -0
  37. chips/yosys/tests/simple/memory.v +319 -0
  38. chips/yosys/tests/simple/memwr_port_connection.sv +13 -0
  39. chips/yosys/tests/simple/module_scope.v +29 -0
  40. chips/yosys/tests/simple/module_scope_case.v +11 -0
  41. chips/yosys/tests/simple/module_scope_func.v +45 -0
  42. chips/yosys/tests/simple/multiplier.v +132 -0
  43. chips/yosys/tests/simple/muxtree.v +82 -0
  44. chips/yosys/tests/simple/named_genblk.v +27 -0
  45. chips/yosys/tests/simple/nested_genblk_resolve.v +14 -0
  46. chips/yosys/tests/simple/omsp_dbg_uart.v +33 -0
  47. chips/yosys/tests/simple/operators.v +121 -0
  48. chips/yosys/tests/simple/param_attr.v +11 -0
  49. chips/yosys/tests/simple/paramods.v +52 -0
  50. chips/yosys/tests/simple/partsel.v +151 -0
chips/yosys/tests/simple/dff_init.v ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module dff0_test(n1, n1_inv, clk);
2
+ input clk;
3
+ output n1;
4
+ reg n1 = 32'd0;
5
+ output n1_inv;
6
+ always @(posedge clk)
7
+ n1 <= n1_inv;
8
+ assign n1_inv = ~n1;
9
+ endmodule
10
+
11
+ module dff1_test(n1, n1_inv, clk);
12
+ input clk;
13
+ (* init = 32'd1 *)
14
+ output n1;
15
+ reg n1 = 32'd1;
16
+ output n1_inv;
17
+ always @(posedge clk)
18
+ n1 <= n1_inv;
19
+ assign n1_inv = ~n1;
20
+ endmodule
21
+
22
+ module dff0a_test(n1, n1_inv, clk);
23
+ input clk;
24
+ (* init = 32'd0 *) // Must be consistent with reg initialiser below
25
+ output n1;
26
+ reg n1 = 32'd0;
27
+ output n1_inv;
28
+ always @(posedge clk)
29
+ n1 <= n1_inv;
30
+ assign n1_inv = ~n1;
31
+ endmodule
32
+
33
+ module dff1a_test(n1, n1_inv, clk);
34
+ input clk;
35
+ (* init = 32'd1 *) // Must be consistent with reg initialiser below
36
+ output n1;
37
+ reg n1 = 32'd1;
38
+ output n1_inv;
39
+ always @(posedge clk)
40
+ n1 <= n1_inv;
41
+ assign n1_inv = ~n1;
42
+ endmodule
43
+
44
+ module dff_test_997 (y, clk, wire4);
45
+ // https://github.com/YosysHQ/yosys/issues/997
46
+ output wire [1:0] y;
47
+ input clk;
48
+ input signed wire4;
49
+ reg [1:0] reg10 = 0;
50
+ always @(posedge clk) begin
51
+ reg10 <= wire4;
52
+ end
53
+ assign y = reg10;
54
+ endmodule
chips/yosys/tests/simple/dynslice.v ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module dynslice (
2
+ input clk ,
3
+ input [9:0] ctrl ,
4
+ input [15:0] din ,
5
+ input [3:0] sel ,
6
+ output reg [127:0] dout
7
+ );
8
+ always @(posedge clk)
9
+ begin
10
+ dout[ctrl*sel+:16] <= din ;
11
+ end
12
+ endmodule
chips/yosys/tests/simple/fiedler-cooley.v ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // borrowed with some modifications from
2
+ // http://www.ee.ed.ac.uk/~gerard/Teach/Verilog/manual/Example/lrgeEx2/cooley.html
3
+ module up3down5(clock, data_in, up, down, carry_out, borrow_out, count_out, parity_out);
4
+
5
+ input [8:0] data_in;
6
+ input clock, up, down;
7
+
8
+ output reg [8:0] count_out;
9
+ output reg carry_out, borrow_out, parity_out;
10
+
11
+ reg [9:0] cnt_up, cnt_dn;
12
+ reg [8:0] count_nxt;
13
+
14
+ always @(posedge clock)
15
+ begin
16
+ cnt_dn = count_out - 3'b 101;
17
+ cnt_up = count_out + 2'b 11;
18
+
19
+ case ({up,down})
20
+ 2'b 00 : count_nxt = data_in;
21
+ 2'b 01 : count_nxt = cnt_dn;
22
+ 2'b 10 : count_nxt = cnt_up;
23
+ 2'b 11 : count_nxt = count_out;
24
+ default : count_nxt = 9'bX;
25
+ endcase
26
+
27
+ parity_out <= ^count_nxt;
28
+ carry_out <= up & cnt_up[9];
29
+ borrow_out <= down & cnt_dn[9];
30
+ count_out <= count_nxt;
31
+ end
32
+
33
+ endmodule
chips/yosys/tests/simple/forgen01.v ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ // VERIFIC-SKIP
3
+
4
+ module uut_forgen01(a, y);
5
+
6
+ input [4:0] a;
7
+ output y;
8
+
9
+ integer i, j;
10
+ reg [31:0] lut;
11
+
12
+ initial begin
13
+ for (i = 0; i < 32; i = i+1) begin
14
+ lut[i] = i > 1;
15
+ for (j = 2; j*j <= i; j = j+1)
16
+ if (i % j == 0)
17
+ lut[i] = 0;
18
+ end
19
+ end
20
+
21
+ assign y = lut[a];
22
+
23
+ endmodule
chips/yosys/tests/simple/forgen02.v ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module uut_forgen02(a, b, cin, y, cout);
2
+
3
+ parameter WIDTH = 8;
4
+
5
+ input [WIDTH-1:0] a, b;
6
+ input cin;
7
+
8
+ output [WIDTH-1:0] y;
9
+ output cout;
10
+
11
+ genvar i;
12
+ wire [WIDTH-1:0] carry;
13
+
14
+ generate
15
+ for (i = 0; i < WIDTH; i=i+1) begin:adder
16
+ wire [2:0] D;
17
+ assign D[1:0] = { a[i], b[i] };
18
+ if (i == 0) begin:chain
19
+ assign D[2] = cin;
20
+ end else begin:chain
21
+ assign D[2] = carry[i-1];
22
+ end
23
+ assign y[i] = ^D;
24
+ assign carry[i] = &D[1:0] | (^D[1:0] & D[2]);
25
+ end
26
+ endgenerate
27
+
28
+ assign cout = carry[WIDTH-1];
29
+
30
+ endmodule
chips/yosys/tests/simple/forloops.v ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module forloops01 (input clk, a, b, output reg [3:0] p, q, x, y);
2
+ integer k;
3
+ always @(posedge clk) begin
4
+ for (k=0; k<2; k=k+1)
5
+ p[2*k +: 2] = {a, b} ^ {2{k}};
6
+ x <= k + {a, b};
7
+ end
8
+ always @* begin
9
+ for (k=0; k<4; k=k+1)
10
+ q[k] = {~a, ~b, a, b} >> k[1:0];
11
+ y = k - {a, b};
12
+ end
13
+ endmodule
14
+
15
+ module forloops02 (input clk, a, b, output reg [3:0] q, x, output [3:0] y);
16
+ integer k;
17
+ always @* begin
18
+ for (k=0; k<4; k=k+1)
19
+ q[k] = {~a, ~b, a, b} >> k[1:0];
20
+ end
21
+ always @* begin
22
+ x = k + {a, b};
23
+ end
24
+ assign y = k - {a, b};
25
+ endmodule
chips/yosys/tests/simple/fsm.v ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ // `define ASYNC_RESET
3
+
4
+ module fsm_test(clk, reset, button_a, button_b, red_a, green_a, red_b, green_b);
5
+
6
+ input clk, reset, button_a, button_b;
7
+ output reg red_a, green_a, red_b, green_b;
8
+
9
+ (* gentb_constant = 0 *)
10
+ wire reset;
11
+
12
+ integer state;
13
+ reg [3:0] cnt;
14
+
15
+ `ifdef ASYNC_RESET
16
+ always @(posedge clk, posedge reset)
17
+ `else
18
+ always @(posedge clk)
19
+ `endif
20
+ begin
21
+ cnt <= 0;
22
+ red_a <= 1;
23
+ red_b <= 1;
24
+ green_a <= 0;
25
+ green_b <= 0;
26
+
27
+ if (reset)
28
+ state <= 100;
29
+ else
30
+ case (state)
31
+ 100: begin
32
+ if (button_a && !button_b)
33
+ state <= 200;
34
+ if (!button_a && button_b)
35
+ state <= 300;
36
+ end
37
+ 200: begin
38
+ red_a <= 0;
39
+ green_a <= 1;
40
+ cnt <= cnt + 1;
41
+ if (cnt == 5)
42
+ state <= 210;
43
+ end
44
+ 210: begin
45
+ red_a <= 0;
46
+ green_a <= cnt[0];
47
+ cnt <= cnt + 1;
48
+ if (cnt == 10)
49
+ state <= 100;
50
+ end
51
+ 300: begin
52
+ red_b <= 0;
53
+ green_b <= 1;
54
+ cnt <= cnt + 1;
55
+ if (cnt == 5)
56
+ state <= 310;
57
+ end
58
+ 310: begin
59
+ red_b <= 0;
60
+ green_b <= cnt[0];
61
+ cnt <= cnt + 1;
62
+ if (cnt == 10)
63
+ state <= 100;
64
+ end
65
+ endcase
66
+ end
67
+
68
+ endmodule
chips/yosys/tests/simple/func_block.v ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `default_nettype none
2
+
3
+ module func_block_top(inp, out1, out2, out3);
4
+ input wire [31:0] inp;
5
+
6
+ function automatic [31:0] func1;
7
+ input [31:0] inp;
8
+ reg [31:0] idx;
9
+ for (idx = 0; idx < 32; idx = idx + 1) begin : blk
10
+ func1[idx] = (idx & 1'b1) ^ inp[idx];
11
+ end
12
+ endfunction
13
+
14
+ function automatic [31:0] func2;
15
+ input [31:0] inp;
16
+ reg [31:0] idx;
17
+ for (idx = 0; idx < 32; idx = idx + 1) begin : blk
18
+ func2[idx] = (idx & 1'b1) ^ inp[idx];
19
+ end
20
+ endfunction
21
+
22
+ function automatic [31:0] func3;
23
+ localparam A = 32 - 1;
24
+ parameter B = 1 - 0;
25
+ input [31:0] inp;
26
+ func3[A:B] = inp[A:B];
27
+ endfunction
28
+
29
+ output wire [31:0] out1, out2, out3;
30
+ assign out1 = func1(inp);
31
+ assign out2 = func2(inp);
32
+ assign out3 = func3(inp);
33
+ endmodule
chips/yosys/tests/simple/func_recurse.v ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module func_recurse_top(
2
+ input wire [3:0] inp,
3
+ output wire [3:0] out1, out2
4
+ );
5
+ function automatic [3:0] pow_a;
6
+ input [3:0] base, exp;
7
+ begin
8
+ pow_a = 1;
9
+ if (exp > 0)
10
+ pow_a = base * pow_a(base, exp - 1);
11
+ end
12
+ endfunction
13
+
14
+ function automatic [3:0] pow_b;
15
+ input [3:0] base, exp;
16
+ begin
17
+ pow_b = 1;
18
+ if (exp > 0)
19
+ pow_b = base * pow_b(base, exp - 1);
20
+ end
21
+ endfunction
22
+
23
+ assign out1 = pow_a(inp, 3);
24
+ assign out2 = pow_b(2, 2);
25
+ endmodule
chips/yosys/tests/simple/func_width_scope.v ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module func_width_scope_top(inp, out1, out2);
2
+ input wire signed inp;
3
+
4
+ localparam WIDTH_A = 5;
5
+ function automatic [WIDTH_A-1:0] func1;
6
+ input reg [WIDTH_A-1:0] inp;
7
+ func1 = ~inp;
8
+ endfunction
9
+ wire [func1(0)-1:0] xc;
10
+ assign xc = 1'sb1;
11
+ wire [WIDTH_A-1:0] xn;
12
+ assign xn = func1(inp);
13
+
14
+ generate
15
+ if (1) begin : blk
16
+ localparam WIDTH_A = 6;
17
+ function automatic [WIDTH_A-1:0] func2;
18
+ input reg [WIDTH_A-1:0] inp;
19
+ func2 = ~inp;
20
+ endfunction
21
+ wire [func2(0)-1:0] yc;
22
+ assign yc = 1'sb1;
23
+ wire [WIDTH_A-1:0] yn;
24
+ assign yn = func2(inp);
25
+
26
+ localparam WIDTH_B = 7;
27
+ function automatic [WIDTH_B-1:0] func3;
28
+ input reg [WIDTH_B-1:0] inp;
29
+ func3 = ~inp;
30
+ endfunction
31
+ wire [func3(0)-1:0] zc;
32
+ assign zc = 1'sb1;
33
+ wire [WIDTH_B-1:0] zn;
34
+ assign zn = func3(inp);
35
+ end
36
+ endgenerate
37
+
38
+ output wire [1023:0] out1, out2;
39
+ assign out1 = {xc, 1'b0, blk.yc, 1'b0, blk.zc};
40
+ assign out2 = {xn, 1'b0, blk.yn, 1'b0, blk.zn};
41
+ endmodule
chips/yosys/tests/simple/genblk_collide.v ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `default_nettype none
2
+
3
+ module genblock_collide_top1;
4
+ generate
5
+ if (1) begin : foo
6
+ if (1) begin : bar
7
+ wire x;
8
+ end
9
+ assign bar.x = 1;
10
+ wire y;
11
+ end
12
+ endgenerate
13
+ endmodule
14
+
15
+ module genblock_collide_top2;
16
+ genvar i;
17
+ generate
18
+ if (1) begin : foo
19
+ wire x;
20
+ for (i = 0; i < 1; i = i + 1) begin : foo
21
+ if (1) begin : foo
22
+ assign x = 1;
23
+ end
24
+ end
25
+ end
26
+ endgenerate
27
+ endmodule
chips/yosys/tests/simple/genblk_dive.v ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `default_nettype none
2
+ module genblk_dive_top(output wire x);
3
+ generate
4
+ if (1) begin : Z
5
+ if (1) begin : A
6
+ wire x;
7
+ if (1) begin : B
8
+ wire x;
9
+ if (1) begin : C
10
+ wire x;
11
+ assign B.x = 0;
12
+ wire z = A.B.C.x;
13
+ end
14
+ assign A.x = A.B.C.x;
15
+ end
16
+ assign B.C.x = B.x;
17
+ end
18
+ end
19
+ endgenerate
20
+ assign x = Z.A.x;
21
+ endmodule
chips/yosys/tests/simple/genblk_order.v ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `default_nettype none
2
+ module genblk_order_top(
3
+ output wire out1,
4
+ output wire out2
5
+ );
6
+ generate
7
+ if (1) begin : outer
8
+ if (1) begin : foo
9
+ wire x = 0;
10
+ if (1) begin : foo
11
+ wire x = 1;
12
+ assign out1 = foo.x;
13
+ end
14
+ assign out2 = foo.x;
15
+ end
16
+ end
17
+ endgenerate
18
+ endmodule
chips/yosys/tests/simple/genblk_port_shadow.v ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ module genblock_port_shadow_top(x);
2
+ generate
3
+ if (1) begin : blk
4
+ wire x;
5
+ assign x = 0;
6
+ end
7
+ endgenerate
8
+ output wire x;
9
+ assign x = blk.x;
10
+ endmodule
chips/yosys/tests/simple/generate.v ADDED
@@ -0,0 +1,325 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module gen_test1(clk, a, b, y);
3
+
4
+ input clk;
5
+ input [7:0] a, b;
6
+ output reg [7:0] y;
7
+
8
+ genvar i, j;
9
+ wire [15:0] tmp1;
10
+
11
+ generate
12
+
13
+ for (i = 0; i < 8; i = i + 1) begin:gen1
14
+ wire and_wire, or_wire;
15
+ assign and_wire = a[i] & b[i];
16
+ assign or_wire = a[i] | b[i];
17
+ if (i % 2 == 0) begin:gen2true
18
+ assign tmp1[i] = and_wire;
19
+ assign tmp1[i+8] = or_wire;
20
+ end else begin:gen2false
21
+ assign tmp1[i] = or_wire;
22
+ assign tmp1[i+8] = and_wire;
23
+ end
24
+ end
25
+
26
+ for (i = 0; i < 8; i = i + 1) begin:gen3
27
+ wire [4:0] tmp2;
28
+ for (j = 0; j <= 4; j = j + 1) begin:gen4
29
+ wire tmpbuf;
30
+ assign tmpbuf = tmp1[i+2*j];
31
+ assign tmp2[j] = tmpbuf;
32
+ end
33
+ always @(posedge clk)
34
+ y[i] <= ^tmp2;
35
+ end
36
+
37
+ endgenerate
38
+
39
+ endmodule
40
+
41
+ // ------------------------------------------
42
+
43
+ module gen_test2(clk, a, b, y);
44
+
45
+ input clk;
46
+ input [7:0] a, b;
47
+ output reg [8:0] y;
48
+
49
+ integer i;
50
+ reg [8:0] carry;
51
+
52
+ always @(posedge clk) begin
53
+ carry[0] = 0;
54
+ for (i = 0; i < 8; i = i + 1) begin
55
+ casez ({a[i], b[i], carry[i]})
56
+ 3'b?11, 3'b1?1, 3'b11?:
57
+ carry[i+1] = 1;
58
+ default:
59
+ carry[i+1] = 0;
60
+ endcase
61
+ y[i] = a[i] ^ b[i] ^ carry[i];
62
+ end
63
+ y[8] = carry[8];
64
+ end
65
+
66
+ endmodule
67
+
68
+ // ------------------------------------------
69
+
70
+ module gen_test3(a, b, sel, y, z);
71
+
72
+ input [3:0] a, b;
73
+ input sel;
74
+ output [3:0] y, z;
75
+
76
+ genvar i;
77
+ generate
78
+ for (i=0; i < 2; i=i+1)
79
+ assign y[i] = sel ? a[i] : b[i], z[i] = sel ? b[i] : a[i];
80
+ for (i=0; i < 2; i=i+1) begin
81
+ if (i == 0)
82
+ assign y[2] = sel ? a[2] : b[2];
83
+ else
84
+ assign z[2] = sel ? a[2] : b[2];
85
+ case (i)
86
+ default:
87
+ assign z[3] = sel ? a[3] : b[3];
88
+ 0:
89
+ assign y[3] = sel ? a[3] : b[3];
90
+ endcase
91
+ end
92
+ endgenerate
93
+ endmodule
94
+
95
+ // ------------------------------------------
96
+
97
+ module gen_test4(a, b);
98
+
99
+ input [3:0] a;
100
+ output [3:0] b;
101
+
102
+ genvar i;
103
+ generate
104
+ for (i=0; i < 3; i=i+1) begin : foo
105
+ localparam PREV = i - 1;
106
+ wire temp;
107
+ if (i == 0)
108
+ assign temp = a[0];
109
+ else
110
+ assign temp = foo[PREV].temp & a[i];
111
+ assign b[i] = temp;
112
+ end
113
+ endgenerate
114
+ endmodule
115
+
116
+ // ------------------------------------------
117
+
118
+ module gen_test5(input_bits, out);
119
+
120
+ parameter WIDTH = 256;
121
+ parameter CHUNK = 4;
122
+
123
+ input [WIDTH-1:0] input_bits;
124
+ output out;
125
+
126
+ genvar step, i, j;
127
+ generate
128
+ for (step = 1; step <= WIDTH; step = step * CHUNK) begin : steps
129
+ localparam PREV = step / CHUNK;
130
+ localparam DIM = WIDTH / step;
131
+ for (i = 0; i < DIM; i = i + 1) begin : outer
132
+ localparam LAST_START = i * CHUNK;
133
+ for (j = 0; j < CHUNK; j = j + 1) begin : inner
134
+ wire temp;
135
+ if (step == 1)
136
+ assign temp = input_bits[i];
137
+ else if (j == 0)
138
+ assign temp = steps[PREV].outer[LAST_START].val;
139
+ else
140
+ assign temp
141
+ = steps[step].outer[i].inner[j-1].temp
142
+ & steps[PREV].outer[LAST_START + j].val;
143
+ end
144
+ wire val;
145
+ assign val = steps[step].outer[i].inner[CHUNK - 1].temp;
146
+ end
147
+ end
148
+ endgenerate
149
+ assign out = steps[WIDTH].outer[0].val;
150
+ endmodule
151
+
152
+ // ------------------------------------------
153
+
154
+ module gen_test6(output [3:0] o);
155
+ generate
156
+ genvar i;
157
+ for (i = 3; i >= 0; i = i-1) begin
158
+ assign o[i] = 1'b0;
159
+ end
160
+ endgenerate
161
+ endmodule
162
+
163
+ // ------------------------------------------
164
+
165
+ module gen_test7;
166
+ reg [2:0] out1;
167
+ reg [2:0] out2;
168
+ wire [2:0] out3;
169
+ generate
170
+ if (1) begin : cond
171
+ reg [2:0] sub_out1;
172
+ reg [2:0] sub_out2;
173
+ wire [2:0] sub_out3;
174
+ initial begin : init
175
+ reg signed [31:0] x;
176
+ x = 2 ** 2;
177
+ out1 = x;
178
+ sub_out1 = x;
179
+ end
180
+ always @* begin : proc
181
+ reg signed [31:0] x;
182
+ x = 2 ** 1;
183
+ out2 = x;
184
+ sub_out2 = x;
185
+ end
186
+ genvar x;
187
+ for (x = 0; x < 3; x = x + 1) begin
188
+ assign out3[x] = 1;
189
+ assign sub_out3[x] = 1;
190
+ end
191
+ end
192
+ endgenerate
193
+
194
+ // `define VERIFY
195
+ `ifdef VERIFY
196
+ assert property (out1 == 4);
197
+ assert property (out2 == 2);
198
+ assert property (out3 == 7);
199
+ assert property (cond.sub_out1 == 4);
200
+ assert property (cond.sub_out2 == 2);
201
+ assert property (cond.sub_out3 == 7);
202
+ `endif
203
+ endmodule
204
+
205
+ // ------------------------------------------
206
+
207
+ module gen_test8;
208
+
209
+ // `define VERIFY
210
+ `ifdef VERIFY
211
+ `define ASSERT(expr) assert property (expr);
212
+ `else
213
+ `define ASSERT(expr)
214
+ `endif
215
+
216
+ wire [1:0] x = 2'b11;
217
+ generate
218
+ if (1) begin : A
219
+ wire [1:0] x;
220
+ if (1) begin : B
221
+ wire [1:0] x = 2'b00;
222
+ `ASSERT(x == 0)
223
+ `ASSERT(A.x == 2)
224
+ `ASSERT(A.C.x == 1)
225
+ `ASSERT(A.B.x == 0)
226
+ `ASSERT(gen_test8.x == 3)
227
+ `ASSERT(gen_test8.A.x == 2)
228
+ `ASSERT(gen_test8.A.C.x == 1)
229
+ `ASSERT(gen_test8.A.B.x == 0)
230
+ end
231
+ if (1) begin : C
232
+ wire [1:0] x = 2'b01;
233
+ `ASSERT(x == 1)
234
+ `ASSERT(A.x == 2)
235
+ `ASSERT(A.C.x == 1)
236
+ `ASSERT(A.B.x == 0)
237
+ `ASSERT(gen_test8.x == 3)
238
+ `ASSERT(gen_test8.A.x == 2)
239
+ `ASSERT(gen_test8.A.C.x == 1)
240
+ `ASSERT(gen_test8.A.B.x == 0)
241
+ end
242
+ assign x = B.x ^ 2'b11 ^ C.x;
243
+ `ASSERT(x == 2)
244
+ `ASSERT(A.x == 2)
245
+ `ASSERT(A.C.x == 1)
246
+ `ASSERT(A.B.x == 0)
247
+ `ASSERT(gen_test8.x == 3)
248
+ `ASSERT(gen_test8.A.x == 2)
249
+ `ASSERT(gen_test8.A.C.x == 1)
250
+ `ASSERT(gen_test8.A.B.x == 0)
251
+ end
252
+ endgenerate
253
+
254
+ `ASSERT(x == 3)
255
+ `ASSERT(A.x == 2)
256
+ `ASSERT(A.C.x == 1)
257
+ `ASSERT(A.B.x == 0)
258
+ `ASSERT(gen_test8.x == 3)
259
+ `ASSERT(gen_test8.A.x == 2)
260
+ `ASSERT(gen_test8.A.C.x == 1)
261
+ `ASSERT(gen_test8.A.B.x == 0)
262
+ endmodule
263
+
264
+ // ------------------------------------------
265
+
266
+ module gen_test9;
267
+
268
+ // `define VERIFY
269
+ `ifdef VERIFY
270
+ `define ASSERT(expr) assert property (expr);
271
+ `else
272
+ `define ASSERT(expr)
273
+ `endif
274
+
275
+ wire [1:0] w = 2'b11;
276
+ generate
277
+ begin : A
278
+ wire [1:0] x;
279
+ begin : B
280
+ wire [1:0] y = 2'b00;
281
+ `ASSERT(w == 3)
282
+ `ASSERT(x == 2)
283
+ `ASSERT(y == 0)
284
+ `ASSERT(A.x == 2)
285
+ `ASSERT(A.C.z == 1)
286
+ `ASSERT(A.B.y == 0)
287
+ `ASSERT(gen_test9.w == 3)
288
+ `ASSERT(gen_test9.A.x == 2)
289
+ `ASSERT(gen_test9.A.C.z == 1)
290
+ `ASSERT(gen_test9.A.B.y == 0)
291
+ end
292
+ begin : C
293
+ wire [1:0] z = 2'b01;
294
+ `ASSERT(w == 3)
295
+ `ASSERT(x == 2)
296
+ `ASSERT(z == 1)
297
+ `ASSERT(A.x == 2)
298
+ `ASSERT(A.C.z == 1)
299
+ `ASSERT(A.B.y == 0)
300
+ `ASSERT(gen_test9.w == 3)
301
+ `ASSERT(gen_test9.A.x == 2)
302
+ `ASSERT(gen_test9.A.C.z == 1)
303
+ `ASSERT(gen_test9.A.B.y == 0)
304
+ end
305
+ assign x = B.y ^ 2'b11 ^ C.z;
306
+ `ASSERT(x == 2)
307
+ `ASSERT(A.x == 2)
308
+ `ASSERT(A.C.z == 1)
309
+ `ASSERT(A.B.y == 0)
310
+ `ASSERT(gen_test9.w == 3)
311
+ `ASSERT(gen_test9.A.x == 2)
312
+ `ASSERT(gen_test9.A.C.z == 1)
313
+ `ASSERT(gen_test9.A.B.y == 0)
314
+ end
315
+ endgenerate
316
+
317
+ `ASSERT(w == 3)
318
+ `ASSERT(A.x == 2)
319
+ `ASSERT(A.C.z == 1)
320
+ `ASSERT(A.B.y == 0)
321
+ `ASSERT(gen_test9.w == 3)
322
+ `ASSERT(gen_test9.A.x == 2)
323
+ `ASSERT(gen_test9.A.C.z == 1)
324
+ `ASSERT(gen_test9.A.B.y == 0)
325
+ endmodule
chips/yosys/tests/simple/generate_mk.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ import sys
4
+ sys.path.append("..")
5
+
6
+ import shutil
7
+
8
+ # ----------------------
9
+ # Check if iverilog is installed
10
+ # ----------------------
11
+ if shutil.which("iverilog") is None:
12
+ print("Error: Icarus Verilog 'iverilog' not found.", file=sys.stderr)
13
+ sys.exit(1)
14
+
15
+ import gen_tests_makefile
16
+
17
+ gen_tests_makefile.generate_autotest("*.*v", "")
chips/yosys/tests/simple/graphtest.v ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module graphtest (A,B,X,Y,Z);
2
+
3
+ input [3:0] A;
4
+ input [3:0] B;
5
+ output reg [3:0] X;
6
+ output [9:0] Y;
7
+ output [7:0] Z;
8
+
9
+ wire [4:0] t;
10
+
11
+ assign t[4] = 1'b0; // Constant connects to wire
12
+ assign t[2:0] = A[2:0] & { 2'b10, B[3]}; // Concatenation of intermediate wire
13
+ assign t[3] = A[2] ^ B[3]; // Bitwise-XOR
14
+
15
+ // assign Y[2:0] = 3'b111;
16
+ // assign Y[6:3] = A;
17
+ // assign Y[9:7] = t[0:2];
18
+ assign Y = {3'b111, A, t[2:0]}; // Direct assignment of concatenation
19
+
20
+ assign Z[0] = 1'b0; // Constant connects to PO
21
+ assign Z[1] = t[3]; // Intermediate sig connects to PO
22
+ assign Z[3:2] = A[2:1]; // PI connects to PO
23
+ assign Z[7:4] = {1'b0, B[2:0]}; // Concat of CV and PI connect to PO
24
+
25
+ always @* begin
26
+ if (A == 4'b1111) begin // All-Const at port (eq)
27
+ X = B;
28
+ end
29
+ else begin
30
+ X = 4'b0000; // All-Const at port (mux)
31
+ end
32
+ end
33
+
34
+ endmodule
chips/yosys/tests/simple/hierarchy.v ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ (* top *)
3
+ module hierarchy_top(a, b, y1, y2, y3, y4);
4
+ input [3:0] a;
5
+ input signed [3:0] b;
6
+ output [7:0] y1, y2, y3, y4;
7
+
8
+ // this version triggers a bug in Icarus Verilog
9
+ // submod #(-3'sd1, 3'b111 + 3'b001) foo (a, b, y1, y2, y3, y4);
10
+
11
+ // this version is handled correctly by Icarus Verilog
12
+ submod #(-3'sd1, -3'sd1) foo (a, b, y1, y2, y3, y4);
13
+
14
+ endmodule
15
+
16
+ (* gentb_skip *)
17
+ module submod(a, b, y1, y2, y3, y4);
18
+ parameter c = 0;
19
+ parameter [7:0] d = 0;
20
+ input [3:0] a, b;
21
+ output [7:0] y1, y2, y3, y4;
22
+ assign y1 = a;
23
+ assign y2 = b;
24
+ assign y3 = c;
25
+ assign y4 = d;
26
+ endmodule
chips/yosys/tests/simple/hierdefparam.v ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `default_nettype none
2
+
3
+ module hierdefparam_top(input wire [7:0] A, output wire [7:0] Y);
4
+ generate begin:foo
5
+ hierdefparam_a mod_a(.A(A), .Y(Y));
6
+ end endgenerate
7
+ defparam foo.mod_a.bar[0].mod_b.addvalue = 42;
8
+ defparam foo.mod_a.bar[1].mod_b.addvalue = 43;
9
+ endmodule
10
+
11
+ module hierdefparam_a(input wire [7:0] A, output wire [7:0] Y);
12
+ genvar i;
13
+ generate
14
+ for (i = 0; i < 2; i=i+1) begin:bar
15
+ wire [7:0] a, y;
16
+ hierdefparam_b mod_b(.A(a), .Y(y));
17
+ end
18
+ endgenerate
19
+ assign bar[0].a = A, bar[1].a = bar[0].y, Y = bar[1].y;
20
+ endmodule
21
+
22
+ module hierdefparam_b(input wire [7:0] A, output wire [7:0] Y);
23
+ parameter [7:0] addvalue = 44;
24
+ assign Y = A + addvalue;
25
+ endmodule
chips/yosys/tests/simple/i2c_master_tests.v ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // one of my early test cases was the OpenCores I2C master
2
+ // This is a collection of stripped down code snippets from
3
+ // this core that triggered bugs in early versions of yosys.
4
+
5
+ // from i2c_master_bit_ctrl
6
+ module i2c_test01(clk, rst, nReset, al);
7
+
8
+ input clk, rst, nReset;
9
+ output reg al;
10
+
11
+ reg cmd_stop;
12
+ always @(posedge clk or negedge nReset)
13
+ if (~nReset)
14
+ cmd_stop <= #1 1'b0;
15
+ else if (rst)
16
+ cmd_stop <= #1 1'b0;
17
+
18
+ always @(posedge clk or negedge nReset)
19
+ if (~nReset)
20
+ al <= #1 1'b0;
21
+ else if (rst)
22
+ al <= #1 1'b0;
23
+ else
24
+ al <= #1 ~cmd_stop;
25
+
26
+ endmodule
27
+
28
+ // from i2c_master_bit_ctrl
29
+ module i2c_test02(clk, slave_wait, clk_cnt, cmd, cmd_stop, cnt);
30
+
31
+ input clk, slave_wait, clk_cnt;
32
+ input cmd;
33
+
34
+ output reg cmd_stop;
35
+
36
+ reg clk_en;
37
+ output reg [15:0] cnt;
38
+
39
+ always @(posedge clk)
40
+ if (~|cnt)
41
+ if (~slave_wait)
42
+ begin
43
+ cnt <= #1 clk_cnt;
44
+ clk_en <= #1 1'b1;
45
+ end
46
+ else
47
+ begin
48
+ cnt <= #1 cnt;
49
+ clk_en <= #1 1'b0;
50
+ end
51
+ else
52
+ begin
53
+ cnt <= #1 cnt - 16'h1;
54
+ clk_en <= #1 1'b0;
55
+ end
56
+
57
+ always @(posedge clk)
58
+ if (clk_en)
59
+ cmd_stop <= #1 cmd;
60
+
61
+ endmodule
chips/yosys/tests/simple/ifdef_1.v ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module ifdef_1_top(o1, o2, o3, o4);
2
+
3
+ `define FAIL input wire not_a_port;
4
+
5
+ `ifdef COND_1
6
+ `FAIL
7
+ `elsif COND_2
8
+ `FAIL
9
+ `elsif COND_3
10
+ `FAIL
11
+ `elsif COND_4
12
+ `FAIL
13
+ `else
14
+
15
+ `define COND_4
16
+ output wire o4;
17
+
18
+ `ifdef COND_1
19
+ `FAIL
20
+ `elsif COND_2
21
+ `FAIL
22
+ `elsif COND_3
23
+ `FAIL
24
+ `elsif COND_4
25
+
26
+ `define COND_3
27
+ output wire o3;
28
+
29
+ `ifdef COND_1
30
+ `FAIL
31
+ `elsif COND_2
32
+ `FAIL
33
+ `elsif COND_3
34
+
35
+ `define COND_2
36
+ output wire o2;
37
+
38
+ `ifdef COND_1
39
+ `FAIL
40
+ `elsif COND_2
41
+
42
+ `define COND_1
43
+ output wire o1;
44
+
45
+ `ifdef COND_1
46
+
47
+ `ifdef COND_1
48
+ `elsif COND_2
49
+ `FAIL
50
+ `elsif COND_3
51
+ `FAIL
52
+ `elsif COND_4
53
+ `FAIL
54
+ `else
55
+ `FAIL
56
+ `endif
57
+
58
+ `elsif COND_2
59
+ `FAIL
60
+ `elsif COND_3
61
+ `FAIL
62
+ `elsif COND_4
63
+ `FAIL
64
+ `else
65
+ `FAIL
66
+ `endif
67
+
68
+ `elsif COND_3
69
+ `FAIL
70
+ `elsif COND_4
71
+ `FAIL
72
+ `else
73
+ `FAIL
74
+ `endif
75
+
76
+ `elsif COND_4
77
+ `FAIL
78
+ `else
79
+ `FAIL
80
+ `endif
81
+
82
+ `else
83
+ `FAIL
84
+ `endif
85
+
86
+ `endif
87
+
88
+ endmodule
chips/yosys/tests/simple/ifdef_2.v ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module ifdef_2_top(o1, o2, o3);
2
+
3
+ output wire o1;
4
+
5
+ `define COND_1
6
+ `define COND_2
7
+ `define COND_3
8
+
9
+ `ifdef COND_1
10
+ output wire o2;
11
+ `elsif COND_2
12
+ input wire dne1;
13
+ `elsif COND_3
14
+ input wire dne2;
15
+ `else
16
+ input wire dne3;
17
+ `endif
18
+
19
+ output wire o3;
20
+
21
+ endmodule
chips/yosys/tests/simple/implicit_ports.sv ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Test implicit port connections
2
+ module alu (input [2:0] a, input [2:0] b, input cin, output cout, output [2:0] result);
3
+ assign cout = cin;
4
+ assign result = a + b;
5
+ endmodule
6
+
7
+ module named_ports(input [2:0] a, b, output [2:0] alu_result, output cout);
8
+ wire cin = 1;
9
+ alu alu (
10
+ .a(a),
11
+ .b, // Implicit connection is equivalent to .b(b)
12
+ .cin(), // Explicitely unconnected
13
+ .cout(cout),
14
+ .result(alu_result)
15
+ );
16
+ endmodule
chips/yosys/tests/simple/lesser_size_cast.sv ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ module top (
2
+ input signed [1:0] a,
3
+ input signed [2:0] b,
4
+ output signed [4:0] c
5
+ );
6
+ assign c = 2'(a) * b;
7
+ endmodule
chips/yosys/tests/simple/local_loop_var.sv ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module local_loop_top(out);
2
+ output integer out;
3
+ initial begin
4
+ integer i;
5
+ for (i = 0; i < 5; i = i + 1)
6
+ if (i == 0)
7
+ out = 1;
8
+ else
9
+ out += 2 ** i;
10
+ end
11
+ endmodule
chips/yosys/tests/simple/localparam_attr.v ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module uut_localparam_attr (I, O);
2
+
3
+ (* LOCALPARAM_ATTRIBUTE = "attribute_content" *)
4
+ localparam WIDTH = 1;
5
+
6
+ input wire [WIDTH-1:0] I;
7
+ output wire [WIDTH-1:0] O;
8
+
9
+ assign O = I;
10
+
11
+ endmodule
chips/yosys/tests/simple/loop_prefix_case.v ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module loop_prefix_case_top(
2
+ input wire x,
3
+ output reg y
4
+ );
5
+ localparam I = 1;
6
+ genvar i;
7
+ generate
8
+ for (i = 0; i < 1; i = i + 1) begin : blk
9
+ wire [i:i] z = x;
10
+ end
11
+ endgenerate
12
+ always @* begin
13
+ case (blk[I - 1].z)
14
+ 1: y = 0;
15
+ 0: y = 1;
16
+ endcase
17
+ end
18
+ endmodule
chips/yosys/tests/simple/loop_var_shadow.v ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module loop_var_shadow_top(out);
2
+ genvar i;
3
+ generate
4
+ for (i = 0; i < 2; i = i + 1) begin : loop
5
+ localparam j = i + 1;
6
+ if (1) begin : blk
7
+ localparam i = j + 1;
8
+ wire [i:0] x;
9
+ assign x = 1'sb1;
10
+ end
11
+ end
12
+ endgenerate
13
+ output wire [63:0] out;
14
+ assign out = {loop[0].blk.x, loop[1].blk.x};
15
+ endmodule
chips/yosys/tests/simple/loops.v ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ // a simple test case extracted from systemcaes (as included in iwls2005)
3
+ // this design has latches (or logic loops) for the two temp variables.
4
+ // this latches (or logic loops) must be removed in the final synthesis results
5
+
6
+ module aes(
7
+ // inputs
8
+ input [3:0] addroundkey_data_i,
9
+ input [3:0] addroundkey_data_reg,
10
+ input [3:0] addroundkey_round,
11
+ input [3:0] key_i,
12
+ input [3:0] keysched_new_key_o,
13
+ input [3:0] round,
14
+ input addroundkey_start_i,
15
+ input keysched_ready_o,
16
+
17
+ // outputs
18
+ output reg [3:0] keysched_last_key_i,
19
+ output reg [3:0] keysched_round_i,
20
+ output reg [3:0] next_addroundkey_data_reg,
21
+ output reg [3:0] next_addroundkey_round,
22
+ output reg [3:0] round_data_var,
23
+ output reg keysched_start_i,
24
+ output reg next_addroundkey_ready_o
25
+ );
26
+
27
+ // temp variables
28
+ reg [3:0] data_var;
29
+ reg [3:0] round_key_var;
30
+
31
+ always @*
32
+ begin
33
+ keysched_start_i = 0;
34
+ keysched_round_i = addroundkey_round;
35
+ round_data_var = addroundkey_data_reg;
36
+ next_addroundkey_data_reg = addroundkey_data_reg;
37
+ next_addroundkey_ready_o = 0;
38
+ next_addroundkey_round = addroundkey_round;
39
+
40
+ if (addroundkey_round == 1 || addroundkey_round == 0)
41
+ keysched_last_key_i = key_i;
42
+ else
43
+ keysched_last_key_i = keysched_new_key_o;
44
+
45
+ if (round == 0 && addroundkey_start_i)
46
+ begin
47
+ data_var = addroundkey_data_i;
48
+ round_key_var = key_i;
49
+ round_data_var = round_key_var ^ data_var;
50
+ next_addroundkey_data_reg = round_data_var;
51
+ next_addroundkey_ready_o = 1;
52
+ end
53
+ else if (addroundkey_start_i && round != 0)
54
+ begin
55
+ keysched_last_key_i = key_i;
56
+ keysched_start_i = 1;
57
+ keysched_round_i = 1;
58
+ next_addroundkey_round = 1;
59
+ end
60
+ else if (addroundkey_round != round && keysched_ready_o)
61
+ begin
62
+ next_addroundkey_round = addroundkey_round + 1;
63
+ keysched_last_key_i = keysched_new_key_o;
64
+ keysched_start_i = 1;
65
+ keysched_round_i = addroundkey_round + 1;
66
+ end
67
+ else if (addroundkey_round == round && keysched_ready_o)
68
+ begin
69
+ data_var = addroundkey_data_i;
70
+ round_key_var = keysched_new_key_o;
71
+ round_data_var = round_key_var ^ data_var;
72
+ next_addroundkey_data_reg = round_data_var;
73
+ next_addroundkey_ready_o = 1;
74
+ next_addroundkey_round = 0;
75
+ end
76
+ end
77
+
78
+ endmodule
chips/yosys/tests/simple/macro_arg_spaces.sv ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module macro_arg_spaces_top(
2
+ input wire [31:0] i,
3
+ output wire [31:0] x, y, z
4
+ );
5
+
6
+ `define BAR(a) a
7
+ `define FOO(a = function automatic [31:0] f) a
8
+
9
+ `BAR(function automatic [31:0] a);
10
+ input [31:0] i;
11
+ a = i * 2;
12
+ endfunction
13
+
14
+ `FOO();
15
+ input [31:0] i;
16
+ f = i * 3;
17
+ endfunction
18
+
19
+ `FOO(function automatic [31:0] b);
20
+ input [31:0] i;
21
+ b = i * 5;
22
+ endfunction
23
+
24
+ assign x = a(i);
25
+ assign y = f(i);
26
+ assign z = b(i);
27
+
28
+ endmodule
chips/yosys/tests/simple/macro_arg_surrounding_spaces.v ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module macr_arg_surrounding_spaces_top(
2
+ IDENT_V_,
3
+ IDENT_W_,
4
+ IDENT_X_,
5
+ IDENT_Y_,
6
+ IDENT_Z_,
7
+ IDENT_A_,
8
+ IDENT_B_,
9
+ IDENT_C_
10
+ );
11
+ `define MACRO(dummy, x) IDENT_``x``_
12
+ output wire IDENT_V_;
13
+ output wire `MACRO(_,W);
14
+ output wire `MACRO(_, X);
15
+ output wire `MACRO(_,Y );
16
+ output wire `MACRO(_, Z );
17
+ output wire `MACRO(_, A);
18
+ output wire `MACRO(_,B );
19
+ output wire `MACRO(_, C );
20
+ endmodule
chips/yosys/tests/simple/macros.v ADDED
@@ -0,0 +1,244 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module test_def(a, y);
3
+
4
+ `define MSB_LSB_SEP :
5
+ `define get_msb(off, len) ((off)+(len)-1)
6
+ `define get_lsb(off, len) (off)
7
+ `define sel_bits(offset, len) `get_msb(offset, len) `MSB_LSB_SEP `get_lsb(offset, len)
8
+
9
+ input [31:0] a;
10
+ output [7:0] y;
11
+
12
+ assign y = a[`sel_bits(16, 8)];
13
+
14
+ endmodule
15
+
16
+ // ---------------------------------------------------
17
+
18
+ module test_ifdef(a, y);
19
+
20
+ input [2:0] a;
21
+ output reg [31:0] y;
22
+
23
+ always @* begin
24
+ y = 0;
25
+
26
+ `undef X
27
+ `ifdef X
28
+ y = y + 42;
29
+ `else
30
+ `undef A
31
+ `undef B
32
+ `ifdef A
33
+ y = (y << 1) | a[0];
34
+ `elsif B
35
+ y = (y << 1) | a[1];
36
+ `else
37
+ y = (y << 1) | a[2];
38
+ `endif
39
+ `undef A
40
+ `define B
41
+ `ifdef A
42
+ y = (y << 1) | a[0];
43
+ `elsif B
44
+ y = (y << 1) | a[1];
45
+ `else
46
+ y = (y << 1) | a[2];
47
+ `endif
48
+ `define A
49
+ `undef B
50
+ `ifdef A
51
+ y = (y << 1) | a[0];
52
+ `elsif B
53
+ y = (y << 1) | a[1];
54
+ `else
55
+ y = (y << 1) | a[2];
56
+ `endif
57
+ `define A
58
+ `define B
59
+ `ifdef A
60
+ y = (y << 1) | a[0];
61
+ `elsif B
62
+ y = (y << 1) | a[1];
63
+ `else
64
+ y = (y << 1) | a[2];
65
+ `endif
66
+ // ------------------------------------
67
+ `undef A
68
+ `undef B
69
+ `ifndef A
70
+ y = (y << 1) | a[0];
71
+ `elsif B
72
+ y = (y << 1) | a[1];
73
+ `else
74
+ y = (y << 1) | a[2];
75
+ `endif
76
+ `undef A
77
+ `define B
78
+ `ifndef A
79
+ y = (y << 1) | a[0];
80
+ `elsif B
81
+ y = (y << 1) | a[1];
82
+ `else
83
+ y = (y << 1) | a[2];
84
+ `endif
85
+ `define A
86
+ `undef B
87
+ `ifndef A
88
+ y = (y << 1) | a[0];
89
+ `elsif B
90
+ y = (y << 1) | a[1];
91
+ `else
92
+ y = (y << 1) | a[2];
93
+ `endif
94
+ `define A
95
+ `define B
96
+ `ifndef A
97
+ y = (y << 1) | a[0];
98
+ `elsif B
99
+ y = (y << 1) | a[1];
100
+ `else
101
+ y = (y << 1) | a[2];
102
+ `endif
103
+ // ------------------------------------
104
+ `undef A
105
+ `ifdef A
106
+ y = (y << 1) | a[0];
107
+ `else
108
+ y = (y << 1) | a[2];
109
+ `endif
110
+ `define A
111
+ `ifdef A
112
+ y = (y << 1) | a[0];
113
+ `else
114
+ y = (y << 1) | a[2];
115
+ `endif
116
+ // ------------------------------------
117
+ `undef A
118
+ `ifndef A
119
+ y = (y << 1) | a[0];
120
+ `else
121
+ y = (y << 1) | a[2];
122
+ `endif
123
+ `define A
124
+ `ifndef A
125
+ y = (y << 1) | a[0];
126
+ `else
127
+ y = (y << 1) | a[2];
128
+ `endif
129
+ `endif
130
+
131
+ `define X
132
+ `ifdef X
133
+ `undef A
134
+ `undef B
135
+ `ifdef A
136
+ y = (y << 1) | a[0];
137
+ `elsif B
138
+ y = (y << 1) | a[1];
139
+ `else
140
+ y = (y << 1) | a[2];
141
+ `endif
142
+ `undef A
143
+ `define B
144
+ `ifdef A
145
+ y = (y << 1) | a[0];
146
+ `elsif B
147
+ y = (y << 1) | a[1];
148
+ `else
149
+ y = (y << 1) | a[2];
150
+ `endif
151
+ `define A
152
+ `undef B
153
+ `ifdef A
154
+ y = (y << 1) | a[0];
155
+ `elsif B
156
+ y = (y << 1) | a[1];
157
+ `else
158
+ y = (y << 1) | a[2];
159
+ `endif
160
+ `define A
161
+ `define B
162
+ `ifdef A
163
+ y = (y << 1) | a[0];
164
+ `elsif B
165
+ y = (y << 1) | a[1];
166
+ `else
167
+ y = (y << 1) | a[2];
168
+ `endif
169
+ // ------------------------------------
170
+ `undef A
171
+ `undef B
172
+ `ifndef A
173
+ y = (y << 1) | a[0];
174
+ `elsif B
175
+ y = (y << 1) | a[1];
176
+ `else
177
+ y = (y << 1) | a[2];
178
+ `endif
179
+ `undef A
180
+ `define B
181
+ `ifndef A
182
+ y = (y << 1) | a[0];
183
+ `elsif B
184
+ y = (y << 1) | a[1];
185
+ `else
186
+ y = (y << 1) | a[2];
187
+ `endif
188
+ `define A
189
+ `undef B
190
+ `ifndef A
191
+ y = (y << 1) | a[0];
192
+ `elsif B
193
+ y = (y << 1) | a[1];
194
+ `else
195
+ y = (y << 1) | a[2];
196
+ `endif
197
+ `define A
198
+ `define B
199
+ `ifndef A
200
+ y = (y << 1) | a[0];
201
+ `elsif B
202
+ y = (y << 1) | a[1];
203
+ `else
204
+ y = (y << 1) | a[2];
205
+ `endif
206
+ // ------------------------------------
207
+ `undef A
208
+ `ifdef A
209
+ y = (y << 1) | a[0];
210
+ `else
211
+ y = (y << 1) | a[2];
212
+ `endif
213
+ `define A
214
+ `ifdef A
215
+ y = (y << 1) | a[0];
216
+ `else
217
+ y = (y << 1) | a[2];
218
+ `endif
219
+ // ------------------------------------
220
+ `undef A
221
+ `ifndef A
222
+ y = (y << 1) | a[0];
223
+ `else
224
+ y = (y << 1) | a[2];
225
+ `endif
226
+ `define A
227
+ `ifndef A
228
+ y = (y << 1) | a[0];
229
+ `else
230
+ y = (y << 1) | a[2];
231
+ `endif
232
+ `else
233
+ y = y + 42;
234
+ `endif
235
+ end
236
+
237
+ endmodule
238
+
239
+ `define SIZE 4 // comment supported in this part
240
+ module test_comment_in_macro ( din_a, dout_a );
241
+ input [`SIZE-1:0] din_a;
242
+ output [`SIZE-1:0] dout_a;
243
+ assign dout_a = din_a | `SIZE'ha;
244
+ endmodule
chips/yosys/tests/simple/matching_end_labels.sv ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module matching_end_labels_top(
2
+ output reg [7:0]
3
+ out1, out2, out3, out4
4
+ );
5
+ initial begin
6
+ begin : blk1
7
+ reg x;
8
+ x = 1;
9
+ end
10
+ out1 = blk1.x;
11
+ begin : blk2
12
+ reg x;
13
+ x = 2;
14
+ end : blk2
15
+ out2 = blk2.x;
16
+ end
17
+ if (1) begin
18
+ if (1) begin : blk3
19
+ reg x;
20
+ assign x = 3;
21
+ end
22
+ assign out3 = blk3.x;
23
+ if (1) begin : blk4
24
+ reg x;
25
+ assign x = 4;
26
+ end : blk4
27
+ assign out4 = blk4.x;
28
+ end
29
+ endmodule
chips/yosys/tests/simple/mem2reg.v ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module mem2reg_test1(in_addr, in_data, out_addr, out_data);
3
+
4
+ input [1:0] in_addr, out_addr;
5
+ input [3:0] in_data;
6
+ output reg [3:0] out_data;
7
+
8
+ reg [3:0] array [2:0];
9
+
10
+ always @* begin
11
+ array[0] = 0;
12
+ array[1] = 23;
13
+ array[2] = 42;
14
+ array[in_addr] = in_data;
15
+ out_data = array[out_addr];
16
+ end
17
+
18
+ endmodule
19
+
20
+ // ------------------------------------------------------
21
+
22
+ module mem2reg_test2(clk, reset, mode, addr, data);
23
+
24
+ input clk, reset, mode;
25
+ input [2:0] addr;
26
+ output [3:0] data;
27
+
28
+ (* mem2reg *)
29
+ reg [3:0] mem [0:7];
30
+
31
+ assign data = mem[addr];
32
+
33
+ integer i;
34
+
35
+ always @(posedge clk) begin
36
+ if (reset) begin
37
+ for (i=0; i<8; i=i+1)
38
+ mem[i] <= i;
39
+ end else
40
+ if (mode) begin
41
+ for (i=0; i<8; i=i+1)
42
+ mem[i] <= mem[i]+1;
43
+ end else begin
44
+ mem[addr] <= 0;
45
+ end
46
+ end
47
+
48
+ endmodule
49
+
50
+ // ------------------------------------------------------
51
+
52
+ // http://www.reddit.com/r/yosys/comments/28d9lx/problem_with_concatenation_of_two_dimensional/
53
+ module mem2reg_test3( input clk, input [8:0] din_a, output reg [7:0] dout_a, output [7:0] dout_b);
54
+ reg [7:0] dint_c [0:7];
55
+ always @(posedge clk)
56
+ begin
57
+ {dout_a[0], dint_c[3]} <= din_a;
58
+ end
59
+ assign dout_b = dint_c[3];
60
+ endmodule
61
+
62
+ // ------------------------------------------------------
63
+
64
+ module mem2reg_test4(result1, result2, result3);
65
+ output signed [9:0] result1;
66
+ output signed [9:0] result2;
67
+ output signed [9:0] result3;
68
+
69
+ wire signed [9:0] intermediate [0:3];
70
+
71
+ function integer depth2Index;
72
+ input integer depth;
73
+ depth2Index = depth;
74
+ endfunction
75
+
76
+ assign intermediate[depth2Index(1)] = 1;
77
+ assign intermediate[depth2Index(2)] = 2;
78
+ assign intermediate[3] = 3;
79
+ assign result1 = intermediate[1];
80
+ assign result2 = intermediate[depth2Index(2)];
81
+ assign result3 = intermediate[depth2Index(3)];
82
+ endmodule
83
+
84
+ // ------------------------------------------------------
85
+
86
+ module mem2reg_test5(input ctrl, output out);
87
+ wire [0:0] foo[0:0];
88
+ wire [0:0] bar[0:1];
89
+
90
+ assign foo[0] = ctrl;
91
+ assign bar[0] = 0, bar[1] = 1;
92
+ assign out = bar[foo[0]];
93
+ endmodule
94
+
95
+ // ------------------------------------------------------
96
+
97
+ module mem2reg_test6 (din, dout);
98
+ input wire [3:0] din;
99
+ output reg [3:0] dout;
100
+
101
+ reg [1:0] din_array [1:0];
102
+ reg [1:0] dout_array [1:0];
103
+
104
+ always @* begin
105
+ din_array[0] = din[0 +: 2];
106
+ din_array[1] = din[2 +: 2];
107
+
108
+ dout_array[0] = din_array[0];
109
+ dout_array[1] = din_array[1];
110
+
111
+ {dout_array[0][1], dout_array[0][0]} = dout_array[0][0] + dout_array[1][0];
112
+
113
+ dout[0 +: 2] = dout_array[0];
114
+ dout[2 +: 2] = dout_array[1];
115
+ end
116
+ endmodule
chips/yosys/tests/simple/mem2reg_bounds_tern.v ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module mem2reg_bounds_term_top(
2
+ input clk,
3
+ input wire [1:0] sel,
4
+ input wire [7:0] base,
5
+ output reg [7:0] line
6
+ );
7
+ reg [0:7] mem [0:2];
8
+
9
+ generate
10
+ genvar i;
11
+ for (i = 0; i < 4; i = i + 1) begin : gen
12
+ always @(posedge clk)
13
+ mem[i] <= i == 0 ? base : mem[i - 1] + 1;
14
+ end
15
+ endgenerate
16
+
17
+ always @(posedge clk)
18
+ line = mem[sel];
19
+ endmodule
chips/yosys/tests/simple/mem_arst.v ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module MyMem #(
3
+ parameter AddrWidth = 4,
4
+ parameter DataWidth = 4) (
5
+ (* gentb_constant = 1 *)
6
+ input Reset_n_i,
7
+ input Clk_i,
8
+ input [AddrWidth-1:0] Addr_i,
9
+ input [DataWidth-1:0] Data_i,
10
+ output reg [DataWidth-1:0] Data_o,
11
+ input WR_i);
12
+
13
+ localparam Size = 2**AddrWidth;
14
+
15
+ (* mem2reg *)
16
+ reg [DataWidth-1:0] Mem[Size-1:0];
17
+
18
+ integer i;
19
+
20
+ always @(negedge Reset_n_i or posedge Clk_i)
21
+ begin
22
+ if (!Reset_n_i)
23
+ begin
24
+ Data_o <= 'bx;
25
+ for (i=0; i<Size; i=i+1)
26
+ begin
27
+ Mem[i] <= 0;
28
+ end
29
+ end
30
+ else
31
+ begin
32
+ Data_o <= Mem[Addr_i];
33
+ if (WR_i)
34
+ begin
35
+ Mem[Addr_i] <= Data_i;
36
+ end
37
+ end
38
+ end
39
+
40
+ endmodule
chips/yosys/tests/simple/memory.v ADDED
@@ -0,0 +1,319 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module memtest00(clk, setA, setB, y);
3
+
4
+ input clk, setA, setB;
5
+ output y;
6
+ reg mem [1:0];
7
+
8
+ always @(posedge clk) begin
9
+ if (setA) mem[0] <= 0; // this is line 9
10
+ if (setB) mem[0] <= 1; // this is line 10
11
+ end
12
+
13
+ assign y = mem[0];
14
+
15
+ endmodule
16
+
17
+ // ----------------------------------------------------------
18
+
19
+ module memtest01(clk, wr_en, wr_addr, wr_value, rd_addr, rd_value);
20
+
21
+ input clk, wr_en;
22
+ input [3:0] wr_addr, rd_addr;
23
+ input [7:0] wr_value;
24
+ output reg [7:0] rd_value;
25
+
26
+ reg [7:0] data [15:0];
27
+
28
+ always @(posedge clk)
29
+ if (wr_en)
30
+ data[wr_addr] <= wr_value;
31
+
32
+ always @(posedge clk)
33
+ rd_value <= data[rd_addr];
34
+
35
+ endmodule
36
+
37
+ // ----------------------------------------------------------
38
+
39
+ module memtest02(clk, setA, setB, addr, bit, y1, y2, y3, y4);
40
+
41
+ input clk, setA, setB;
42
+ input [1:0] addr;
43
+ input [2:0] bit;
44
+ output reg y1, y2;
45
+ output y3, y4;
46
+
47
+ (* nomem2reg *)
48
+ reg [7:0] mem1 [3:0];
49
+
50
+ (* mem2reg *)
51
+ reg [7:0] mem2 [3:0];
52
+
53
+ always @(posedge clk) begin
54
+ if (setA) begin
55
+ mem1[0] <= 10;
56
+ mem1[1] <= 20;
57
+ mem1[2] <= 30;
58
+ mem2[0] <= 17;
59
+ mem2[1] <= 27;
60
+ mem2[2] <= 37;
61
+ end
62
+ if (setB) begin
63
+ mem1[0] <= 1;
64
+ mem1[1] <= 2;
65
+ mem1[2] <= 3;
66
+ mem2[0] <= 71;
67
+ mem2[1] <= 72;
68
+ mem2[2] <= 73;
69
+ end
70
+ y1 <= mem1[addr][bit];
71
+ y2 <= mem2[addr][bit];
72
+ end
73
+
74
+ assign y3 = mem1[addr][bit];
75
+ assign y4 = mem2[addr][bit];
76
+
77
+ endmodule
78
+
79
+ // ----------------------------------------------------------
80
+
81
+ module memtest03(clk, wr_addr, wr_data, wr_enable, rd_addr, rd_data);
82
+
83
+ input clk, wr_enable;
84
+ input [3:0] wr_addr, wr_data, rd_addr;
85
+ output reg [3:0] rd_data;
86
+
87
+ reg [3:0] memory [0:15];
88
+
89
+ always @(posedge clk) begin
90
+ if (wr_enable)
91
+ memory[wr_addr] <= wr_data;
92
+ rd_data <= memory[rd_addr];
93
+ end
94
+
95
+ endmodule
96
+
97
+ // ----------------------------------------------------------
98
+
99
+ module memtest04(clk, wr_addr, wr_data, wr_enable, rd_addr, rd_data);
100
+
101
+ input clk, wr_enable;
102
+ input [3:0] wr_addr, wr_data, rd_addr;
103
+ output [3:0] rd_data;
104
+
105
+ reg rd_addr_buf;
106
+ reg [3:0] memory [0:15];
107
+
108
+ always @(posedge clk) begin
109
+ if (wr_enable)
110
+ memory[wr_addr] <= wr_data;
111
+ rd_addr_buf <= rd_addr;
112
+ end
113
+
114
+ assign rd_data = memory[rd_addr_buf];
115
+
116
+ endmodule
117
+
118
+ // ----------------------------------------------------------
119
+
120
+ module memtest05(clk, addr, wdata, rdata, wen);
121
+
122
+ input clk;
123
+ input [1:0] addr;
124
+ input [7:0] wdata;
125
+ output reg [7:0] rdata;
126
+ input [3:0] wen;
127
+
128
+ reg [7:0] mem [0:3];
129
+
130
+ integer i;
131
+ always @(posedge clk) begin
132
+ for (i = 0; i < 4; i = i+1)
133
+ if (wen[i]) mem[addr][i*2 +: 2] <= wdata[i*2 +: 2];
134
+ rdata <= mem[addr];
135
+ end
136
+
137
+ endmodule
138
+
139
+ // ----------------------------------------------------------
140
+
141
+ module memtest06_sync(clk, rst, idx, din, dout);
142
+ input clk;
143
+ input rst;
144
+ (* gentb_constant=0 *) wire rst;
145
+ input [2:0] idx;
146
+ input [7:0] din;
147
+ output [7:0] dout;
148
+ reg [7:0] test [0:7];
149
+ integer i;
150
+ always @(posedge clk) begin
151
+ if (rst) begin
152
+ for (i=0; i<8; i=i+1)
153
+ test[i] <= 0;
154
+ end else begin
155
+ test[0][2] <= din[1];
156
+ test[0][5] <= test[0][2];
157
+ test[idx][3] <= din[idx];
158
+ test[idx][6] <= test[idx][2];
159
+ test[idx][idx] <= !test[idx][idx];
160
+ end
161
+ end
162
+ assign dout = test[idx];
163
+ endmodule
164
+
165
+ module memtest06_async(clk, rst, idx, din, dout);
166
+ input clk;
167
+ input rst;
168
+ (* gentb_constant=0 *) wire rst;
169
+ input [2:0] idx;
170
+ input [7:0] din;
171
+ output [7:0] dout;
172
+ reg [7:0] test [0:7];
173
+ integer i;
174
+ always @(posedge clk or posedge rst) begin
175
+ if (rst) begin
176
+ for (i=0; i<8; i=i+1)
177
+ test[i] <= 0;
178
+ end else begin
179
+ test[0][2] <= din[1];
180
+ test[0][5] <= test[0][2];
181
+ test[idx][3] <= din[idx];
182
+ test[idx][6] <= test[idx][2];
183
+ test[idx][idx] <= !test[idx][idx];
184
+ end
185
+ end
186
+ assign dout = test[idx];
187
+ endmodule
188
+
189
+ // ----------------------------------------------------------
190
+
191
+ module memtest07(clk, addr, woffset, wdata, rdata);
192
+
193
+ input clk;
194
+ input [1:0] addr;
195
+ input [3:0] wdata;
196
+ input [1:0] woffset;
197
+ output reg [7:0] rdata;
198
+
199
+ reg [7:0] mem [0:3];
200
+
201
+ integer i;
202
+ always @(posedge clk) begin
203
+ mem[addr][woffset +: 4] <= wdata;
204
+ rdata <= mem[addr];
205
+ end
206
+
207
+ endmodule
208
+
209
+ // ----------------------------------------------------------
210
+
211
+ module memtest08(input clk, input [3:0] a, b, c, output reg [3:0] y);
212
+ reg [3:0] mem [0:15] [0:15];
213
+ always @(posedge clk) begin
214
+ y <= mem[a][b];
215
+ mem[a][b] <= c;
216
+ end
217
+ endmodule
218
+
219
+ // ----------------------------------------------------------
220
+
221
+ module memtest09 (
222
+ input clk,
223
+ input [3:0] a_addr, a_din, b_addr, b_din,
224
+ input a_wen, b_wen,
225
+ output reg [3:0] a_dout, b_dout
226
+ );
227
+ reg [3:0] memory [10:35];
228
+
229
+ always @(posedge clk) begin
230
+ if (a_wen)
231
+ memory[10 + a_addr] <= a_din;
232
+ a_dout <= memory[10 + a_addr];
233
+ end
234
+
235
+ always @(posedge clk) begin
236
+ if (b_wen && (10 + a_addr != 20 + b_addr || !a_wen))
237
+ memory[20 + b_addr] <= b_din;
238
+ b_dout <= memory[20 + b_addr];
239
+ end
240
+ endmodule
241
+
242
+ // ----------------------------------------------------------
243
+
244
+ module memtest10(input clk, input [5:0] din, output [5:0] dout);
245
+ reg [5:0] queue [0:3];
246
+ integer i;
247
+
248
+ always @(posedge clk) begin
249
+ queue[0] <= din;
250
+ for (i = 1; i < 4; i=i+1) begin
251
+ queue[i] <= queue[i-1];
252
+ end
253
+ end
254
+
255
+ assign dout = queue[3];
256
+ endmodule
257
+
258
+ // ----------------------------------------------------------
259
+
260
+ module memtest11(clk, wen, waddr, raddr, wdata, rdata);
261
+ input clk, wen;
262
+ input [1:0] waddr, raddr;
263
+ input [7:0] wdata;
264
+ output [7:0] rdata;
265
+
266
+ reg [7:0] mem [3:0];
267
+
268
+ assign rdata = mem[raddr];
269
+
270
+ always @(posedge clk) begin
271
+ if (wen)
272
+ mem[waddr] <= wdata;
273
+ else
274
+ mem[waddr] <= mem[waddr];
275
+ end
276
+ endmodule
277
+
278
+ // ----------------------------------------------------------
279
+
280
+ module memtest12 (
281
+ input clk,
282
+ input [1:0] adr,
283
+ input [1:0] din,
284
+ output reg [1:0] q
285
+ );
286
+ reg [1:0] ram [3:0];
287
+ always@(posedge clk)
288
+ {ram[adr], q} <= {din, ram[adr]};
289
+ endmodule
290
+
291
+ // ----------------------------------------------------------
292
+
293
+ module memtest13 (
294
+ input clk, rst,
295
+ input [1:0] a1, a2, a3, a4, a5, a6,
296
+ input [3:0] off1, off2,
297
+ input [31:5] din1,
298
+ input [3:0] din2, din3,
299
+ output reg [3:0] dout1, dout2,
300
+ output reg [31:5] dout3
301
+ );
302
+ reg [31:5] mem [0:3];
303
+
304
+ always @(posedge clk) begin
305
+ if (rst) begin
306
+ mem[0] <= 0;
307
+ mem[1] <= 0;
308
+ mem[2] <= 0;
309
+ mem[3] <= 0;
310
+ end else begin
311
+ mem[a1] <= din1;
312
+ mem[a2][14:11] <= din2;
313
+ mem[a3][5 + off1 +: 4] <= din3;
314
+ dout1 <= mem[a4][12:9];
315
+ dout2 <= mem[a5][5 + off2 +: 4];
316
+ dout3 <= mem[a6];
317
+ end
318
+ end
319
+ endmodule
chips/yosys/tests/simple/memwr_port_connection.sv ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module producer(
2
+ output logic [3:0] out
3
+ );
4
+ assign out = 4'hA;
5
+ endmodule
6
+
7
+ module top(
8
+ output logic [3:0] out
9
+ );
10
+ logic [3:0] v[0:0];
11
+ producer p(v[0]);
12
+ assign out = v[0];
13
+ endmodule
chips/yosys/tests/simple/module_scope.v ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `default_nettype none
2
+
3
+ module module_scope_Example(o1, o2);
4
+ parameter [31:0] v1 = 10;
5
+ parameter [31:0] v2 = 20;
6
+ output wire [31:0] o1, o2;
7
+ assign module_scope_Example.o1 = module_scope_Example.v1;
8
+ assign module_scope_Example.o2 = module_scope_Example.v2;
9
+ endmodule
10
+
11
+ module module_scope_ExampleLong(o1, o2);
12
+ parameter [31:0] ThisIsAnExtremelyLongParameterNameToTriggerTheSHA1Checksum1 = 10;
13
+ parameter [31:0] ThisIsAnExtremelyLongParameterNameToTriggerTheSHA1Checksum2 = 20;
14
+ output wire [31:0] o1, o2;
15
+ assign module_scope_ExampleLong.o1 = module_scope_ExampleLong.ThisIsAnExtremelyLongParameterNameToTriggerTheSHA1Checksum1;
16
+ assign module_scope_ExampleLong.o2 = module_scope_ExampleLong.ThisIsAnExtremelyLongParameterNameToTriggerTheSHA1Checksum2;
17
+ endmodule
18
+
19
+ module module_scope_top(
20
+ output wire [31:0] a1, a2, b1, b2, c1, c2,
21
+ output wire [31:0] d1, d2, e1, e2, f1, f2
22
+ );
23
+ module_scope_Example a(a1, a2);
24
+ module_scope_Example #(1) b(b1, b2);
25
+ module_scope_Example #(1, 2) c(c1, c2);
26
+ module_scope_ExampleLong d(d1, d2);
27
+ module_scope_ExampleLong #(1) e(e1, e2);
28
+ module_scope_ExampleLong #(1, 2) f(f1, f2);
29
+ endmodule
chips/yosys/tests/simple/module_scope_case.v ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module module_scope_case_top(
2
+ input wire x,
3
+ output reg y
4
+ );
5
+ always @* begin
6
+ case (module_scope_case_top.x)
7
+ 1: module_scope_case_top.y = 0;
8
+ 0: module_scope_case_top.y = 1;
9
+ endcase
10
+ end
11
+ endmodule
chips/yosys/tests/simple/module_scope_func.v ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Some strict implementatins either forbid hierarchical identifiers within
2
+ // constant expressions, or forbid declaring functions in generate blocks, or
3
+ // both. Yosys and Iverilog are not strict in either of these ways.
4
+ module module_scope_func_top(
5
+ input wire inp,
6
+ output wire [31:0] out1, out2, out4, out5, out7, out8,
7
+ output reg [31:0] out3, out6, out9
8
+ );
9
+ function automatic integer incr;
10
+ input integer value;
11
+ incr = value + 1;
12
+ endfunction
13
+ task send;
14
+ output integer out;
15
+ out = 55;
16
+ endtask
17
+
18
+ assign out1 = module_scope_func_top.incr(inp);
19
+ localparam C = module_scope_func_top.incr(10);
20
+ assign out2 = C;
21
+ initial module_scope_func_top.send(out3);
22
+
23
+ if (1) begin : blk
24
+ // shadows module_scope_func_top.incr
25
+ function automatic integer incr;
26
+ input integer value;
27
+ incr = value * 2;
28
+ endfunction
29
+ // shadows module_scope_func_top.send
30
+ task send;
31
+ output integer out;
32
+ out = 66;
33
+ endtask
34
+
35
+ assign out4 = module_scope_func_top.incr(inp);
36
+ localparam D = module_scope_func_top.incr(20);
37
+ assign out5 = D;
38
+ initial module_scope_func_top.send(out6);
39
+
40
+ assign out7 = incr(inp);
41
+ localparam E = incr(30);
42
+ assign out8 = E;
43
+ initial send(out9);
44
+ end
45
+ endmodule
chips/yosys/tests/simple/multiplier.v ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ // Via http://www.edaplayground.com/s/6/591
3
+ // stackoverflow 20556634
4
+ // http://stackoverflow.com/questions/20556634/how-can-i-iteratively-create-buses-of-parameterized-size-to-connect-modules-also
5
+
6
+ // Code your design here
7
+ `define macro_args
8
+ `define indexed_part_select
9
+
10
+ module Multiplier_flat #(parameter M = 4, parameter N = 4)(
11
+ input [M-1:0] A, //Input A, size M
12
+ input [N-1:0] B, //Input B, size N
13
+ output [M+N-1:0] P ); //Output P (product), size M+N
14
+
15
+ /* Calculate LSB using Wolfram Alpha
16
+ N==3 : http://www.wolframalpha.com/input/?i=0%2C+4%2C+9%2C+15%2C+...
17
+ N==4 : http://www.wolframalpha.com/input/?i=0%2C+5%2C+11%2C+18%2C+26%2C+35%2C+...
18
+ N==5 : http://www.wolframalpha.com/input/?i=0%2C+6%2C+13%2C+21%2C+30%2C+...
19
+ */
20
+ `ifdef macro_args
21
+ // initial $display("Use Macro Args");
22
+ `define calc_pp_lsb(n) (((n)-1)*((n)+2*M)/2)
23
+ //`define calc_pp_msb(n) (`calc_pp_lsb(n+1)-1)
24
+ `define calc_pp_msb(n) ((n**2+(2*M+1)*n-2)/2)
25
+ //`define calc_range(n) `calc_pp_msb(n):`calc_pp_lsb(n)
26
+ `define calc_pp_range(n) `calc_pp_lsb(n) +: (M+n)
27
+
28
+ wire [`calc_pp_msb(N):0] PP;
29
+ assign PP[`calc_pp_range(1)] = { 1'b0 , { A & {M{B[0]}} } };
30
+ assign P = PP[`calc_pp_range(N)];
31
+ `elsif indexed_part_select
32
+ // initial $display("Use Indexed Part Select");
33
+ localparam MSB = (N**2+(2*M+1)*N-2)/2;
34
+ wire [MSB:0] PP;
35
+ assign PP[M:0] = { 1'b0 , { A & {M{B[0]}} } };
36
+ assign P = PP[MSB -: M+N];
37
+ `else
38
+ // initial $display("Use Worst Case");
39
+ localparam MSB = (N**2+(2*M+1)*N-2)/2;
40
+ wire [MSB:0] PP;
41
+ assign PP[M:0] = { 1'b0 , { A & {M{B[0]}} } };
42
+ assign P = PP[MSB : MSB+1-M-N];
43
+ `endif
44
+
45
+ genvar i;
46
+ generate
47
+ for (i=1; i < N; i=i+1)
48
+ begin: addPartialProduct
49
+ wire [M+i-1:0] gA,gB,gS;
50
+ wire Cout;
51
+ assign gA = { A & {M{B[i]}} , {i{1'b0}} };
52
+ `ifdef macro_args
53
+ assign gB = PP[`calc_pp_range(i)];
54
+ assign PP[`calc_pp_range(i+1)] = {Cout,gS};
55
+ `elsif indexed_part_select
56
+ assign gB = PP[(i-1)*(i+2*M)/2 +: M+i];
57
+ assign PP[i*((i+1)+2*M)/2 +: M+i+1] = {Cout,gS};
58
+ `else
59
+ localparam LSB = (i-1)*(i+2*M)/2;
60
+ localparam MSB = (i**2+(2*M+1)*i-2)/2;
61
+ localparam MSB2 = ((i+1)**2+(2*M+1)*(i+1)-2)/2;
62
+ assign gB = PP[MSB : LSB];
63
+ assign PP[ MSB2 : MSB+1] = {Cout,gS};
64
+ `endif
65
+ RippleCarryAdder#(M+i) adder( .A(gA), .B(gB), .S(gS), .Cin (1'b0), .Cout(Cout) );
66
+ end
67
+ endgenerate
68
+
69
+ `ifdef macro_args
70
+ // Cleanup global space
71
+ `undef calc_pp_range
72
+ `undef calc_pp_msb
73
+ `undef calc_pp_lsb
74
+ `endif
75
+ endmodule
76
+
77
+ module Multiplier_2D #(parameter M = 4, parameter N = 4)(
78
+ input [M-1:0] A, //Input A, size M
79
+ input [N-1:0] B, //Input B, size N
80
+ output [M+N-1:0] P ); //Output P (product), size M+N
81
+
82
+ wire [M+N-1:0] PP [N-1:0];
83
+
84
+ // Note: bits PP[0][M+N-1:M+1] are never used. Unused bits are optimized out during synthesis
85
+ //assign PP[0][M:0] = { {1'b0} , { A & {M{B[0]}} } };
86
+ //assign PP[0][M+N-1:M+1] = {(N-1){1'b0}}; // uncomment to make probing readable
87
+ assign PP[0] = { {N{1'b0}} , { A & {M{B[0]}} } };
88
+ assign P = PP[N-1];
89
+
90
+ genvar i;
91
+ generate
92
+ for (i=1; i < N; i=i+1)
93
+ begin: addPartialProduct
94
+ wire [M+i-1:0] gA,gB,gS; wire Cout;
95
+ assign gA = { A & {M{B[i]}} , {i{1'b0}} };
96
+ assign gB = PP[i-1][M+i-1:0];
97
+ //assign PP[i][M+i:0] = {Cout,gS};
98
+ //if (i+1<N) assign PP[i][M+N-1:M+i+1] = {(N-i){1'b0}}; // uncomment to make probing readable
99
+ assign PP[i] = { {(N-i){1'b0}}, Cout, gS};
100
+ RippleCarryAdder#(M+i) adder(
101
+ .A(gA), .B(gB), .S(gS), .Cin(1'b0), .Cout(Cout) );
102
+ end
103
+ endgenerate
104
+
105
+ //always@* foreach(S[i]) $display("S[%0d]:%b",i,S[i]);
106
+
107
+ endmodule
108
+
109
+ module RippleCarryAdder#(parameter N = 4)(A,B,Cin,S,Cout);
110
+
111
+ input [N-1:0] A;
112
+ input [N-1:0] B;
113
+ input Cin;
114
+ output [N-1:0] S;
115
+ output Cout;
116
+ wire [N:0] CC;
117
+
118
+ assign CC[0] = Cin;
119
+ assign Cout = CC[N];
120
+ genvar i;
121
+ generate
122
+ for (i=0; i < N; i=i+1)
123
+ begin: addbit
124
+ FullAdder unit(A[i],B[i],CC[i],S[i],CC[i+1]);
125
+ end
126
+ endgenerate
127
+
128
+ endmodule
129
+
130
+ module FullAdder(input A,B,Cin, output wire S,Cout);
131
+ assign {Cout,S} = A+B+Cin;
132
+ endmodule
chips/yosys/tests/simple/muxtree.v ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ // test case generated from IWLS 2005 usb_phy core
3
+ // (triggered a bug in opt_muxtree pass)
4
+
5
+ module usb_tx_phy(clk, rst, DataOut_i, TxValid_i, hold_reg);
6
+
7
+ input clk;
8
+ input rst;
9
+ input DataOut_i;
10
+ input TxValid_i;
11
+ output reg hold_reg;
12
+
13
+ reg state, next_state;
14
+ reg ld_sop_d;
15
+ reg ld_data_d;
16
+
17
+ always @(posedge clk)
18
+ if(ld_sop_d)
19
+ hold_reg <= 0;
20
+ else
21
+ hold_reg <= DataOut_i;
22
+
23
+ always @(posedge clk)
24
+ if(!rst) state <= 0;
25
+ else state <= next_state;
26
+
27
+ always @(state or TxValid_i)
28
+ begin
29
+ next_state = state;
30
+
31
+ ld_sop_d = 1'b0;
32
+ ld_data_d = 1'b0;
33
+
34
+ case(state) // synopsys full_case parallel_case
35
+ 0:
36
+ if(TxValid_i)
37
+ begin
38
+ ld_sop_d = 1'b1;
39
+ next_state = 1;
40
+ end
41
+ 1:
42
+ if(TxValid_i)
43
+ begin
44
+ ld_data_d = 1'b1;
45
+ next_state = 0;
46
+ end
47
+ endcase
48
+ end
49
+
50
+ endmodule
51
+
52
+
53
+ // test case inspired by softusb_navre code:
54
+ // default not as last case
55
+
56
+ module default_cases(a, y);
57
+
58
+ input [2:0] a;
59
+ output reg [3:0] y;
60
+
61
+ always @* begin
62
+ case (a)
63
+ 3'b000, 3'b111: y <= 0;
64
+ default: y <= 4;
65
+ 3'b001: y <= 1;
66
+ 3'b010: y <= 2;
67
+ 3'b100: y <= 3;
68
+ endcase
69
+ end
70
+
71
+ endmodule
72
+
73
+
74
+ // test case for muxtree with select on leaves
75
+
76
+ module select_leaves(input R, C, D, output reg Q);
77
+ always @(posedge C)
78
+ if (!R)
79
+ Q <= R;
80
+ else
81
+ Q <= Q ? Q : D ? D : Q;
82
+ endmodule
chips/yosys/tests/simple/named_genblk.v ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `default_nettype none
2
+ module named_genblk_top;
3
+ generate
4
+ if (1) begin
5
+ wire t;
6
+ begin : foo
7
+ wire x;
8
+ end
9
+ wire u;
10
+ end
11
+ begin : bar
12
+ wire x;
13
+ wire y;
14
+ begin : baz
15
+ wire x;
16
+ wire z;
17
+ end
18
+ end
19
+ endgenerate
20
+ assign genblk1.t = 1;
21
+ assign genblk1.foo.x = 1;
22
+ assign genblk1.u = 1;
23
+ assign bar.x = 1;
24
+ assign bar.y = 1;
25
+ assign bar.baz.x = 1;
26
+ assign bar.baz.z = 1;
27
+ endmodule
chips/yosys/tests/simple/nested_genblk_resolve.v ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ `default_nettype none
2
+ module nested_genblk_resolve_top;
3
+ generate
4
+ if (1) begin
5
+ wire x;
6
+ genvar i;
7
+ for (i = 0; i < 1; i = i + 1) begin
8
+ if (1) begin
9
+ assign x = 1;
10
+ end
11
+ end
12
+ end
13
+ endgenerate
14
+ endmodule
chips/yosys/tests/simple/omsp_dbg_uart.v ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module omsp_dbg_uart (dbg_clk, dbg_rst, mem_burst, cmd_valid);
3
+
4
+ input dbg_clk;
5
+ input dbg_rst;
6
+ input mem_burst;
7
+ output cmd_valid;
8
+
9
+ reg [2:0] uart_state;
10
+ reg [2:0] uart_state_nxt;
11
+
12
+ wire xfer_done;
13
+
14
+ parameter RX_SYNC = 3'h0;
15
+ parameter RX_CMD = 3'h1;
16
+ parameter RX_DATA = 3'h2;
17
+
18
+ always @(uart_state or mem_burst)
19
+ case (uart_state)
20
+ RX_SYNC : uart_state_nxt = RX_CMD;
21
+ RX_CMD : uart_state_nxt = mem_burst ? RX_DATA : RX_SYNC;
22
+ RX_DATA : uart_state_nxt = RX_SYNC;
23
+ default : uart_state_nxt = RX_CMD;
24
+ endcase
25
+
26
+ always @(posedge dbg_clk or posedge dbg_rst)
27
+ if (dbg_rst) uart_state <= RX_SYNC;
28
+ else if (xfer_done | mem_burst) uart_state <= uart_state_nxt;
29
+
30
+ assign cmd_valid = (uart_state==RX_CMD) & xfer_done;
31
+ assign xfer_done = uart_state!=RX_SYNC;
32
+
33
+ endmodule
chips/yosys/tests/simple/operators.v ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module optest(clk, mode, u1, s1, u2, s2, y);
2
+
3
+ input clk;
4
+ input [6:0] mode;
5
+
6
+ input [3:0] u1, u2;
7
+ input signed [3:0] s1, s2;
8
+
9
+ output reg [7:0] y;
10
+
11
+ always @(posedge clk) begin
12
+ y <= 8'h42;
13
+ case (mode)
14
+ 0: y <= u1 << u2;
15
+ 1: y <= u1 << s2;
16
+ 2: y <= s1 << u2;
17
+ 3: y <= s1 << s2;
18
+
19
+ 4: y <= u1 >> u2;
20
+ 5: y <= u1 >> s2;
21
+ 6: y <= s1 >> u2;
22
+ 7: y <= s1 >> s2;
23
+
24
+ 8: y <= u1 <<< u2;
25
+ 9: y <= u1 <<< s2;
26
+ 10: y <= s1 <<< u2;
27
+ 11: y <= s1 <<< s2;
28
+
29
+ 12: y <= u1 >>> u2;
30
+ 13: y <= u1 >>> s2;
31
+ 14: y <= s1 >>> u2;
32
+ 15: y <= s1 >>> s2;
33
+
34
+ 16: y <= u1 < u2;
35
+ 17: y <= u1 < s2;
36
+ 18: y <= s1 < u2;
37
+ 19: y <= s1 < s2;
38
+
39
+ 20: y <= u1 <= u2;
40
+ 21: y <= u1 <= s2;
41
+ 22: y <= s1 <= u2;
42
+ 23: y <= s1 <= s2;
43
+
44
+ 24: y <= u1 == u2;
45
+ 25: y <= u1 == s2;
46
+ 26: y <= s1 == u2;
47
+ 27: y <= s1 == s2;
48
+
49
+ 28: y <= u1 != u2;
50
+ 29: y <= u1 != s2;
51
+ 30: y <= s1 != u2;
52
+ 31: y <= s1 != s2;
53
+
54
+ 32: y <= u1 >= u2;
55
+ 33: y <= u1 >= s2;
56
+ 34: y <= s1 >= u2;
57
+ 35: y <= s1 >= s2;
58
+
59
+ 36: y <= u1 > u2;
60
+ 37: y <= u1 > s2;
61
+ 38: y <= s1 > u2;
62
+ 39: y <= s1 > s2;
63
+
64
+ 40: y <= u1 + u2;
65
+ 41: y <= u1 + s2;
66
+ 42: y <= s1 + u2;
67
+ 43: y <= s1 + s2;
68
+
69
+ 44: y <= u1 - u2;
70
+ 45: y <= u1 - s2;
71
+ 46: y <= s1 - u2;
72
+ 47: y <= s1 - s2;
73
+
74
+ 48: y <= u1 * u2;
75
+ 49: y <= u1 * s2;
76
+ 50: y <= s1 * u2;
77
+ 51: y <= s1 * s2;
78
+
79
+ 52: y <= u1 / u2;
80
+ 53: y <= u1 / s2;
81
+ 54: y <= s1 / u2;
82
+ 55: y <= s1 / s2;
83
+
84
+ 56: y <= u1 % u2;
85
+ 57: y <= u1 % s2;
86
+ 58: y <= s1 % u2;
87
+ 59: y <= s1 % s2;
88
+
89
+ 60: y <= 4'd2 ** u1;
90
+ 61: y <= 4'd2 ** s1;
91
+ 62: y <= 4'sd2 ** u1;
92
+ 63: y <= 4'sd2 ** s1;
93
+
94
+ 64: y <= +u1;
95
+ 65: y <= -u1;
96
+ 66: y <= ~u1;
97
+ 67: y <= !u1;
98
+
99
+ 68: y <= +s1;
100
+ 69: y <= -s1;
101
+ 70: y <= ~s1;
102
+ 71: y <= !s1;
103
+
104
+ 72: y <= { &u1, ~&u1, |u1, ~|u1, ^u1, ~^u1, ^~u1 };
105
+ 73: y <= { &s1, ~&s1, |s1, ~|s1, ^s1, ~^s1, ^~s1 };
106
+ 74: y <= { &u1[1:0], ~&u1[1:0], |u1[1:0], ~|u1[1:0], ^u1[1:0], ~^u1[1:0], ^~u1[1:0] };
107
+ 75: y <= { &s1[1:0], ~&s1[1:0], |s1[1:0], ~|s1[1:0], ^s1[1:0], ~^s1[1:0], ^~s1[1:0] };
108
+
109
+ 76: y <= { u1[1:0] && u2[1:0], u1[1:0] && u2[1:0], !u1[1:0] };
110
+ 77: y <= {4{u1[1:0]}};
111
+ 78: y <= {u1, u2} ^ {s1, s2};
112
+ 79: y <= {u1, u2} & {s1, s2};
113
+
114
+ 80: y <= u1[0] ? u1 : u2;
115
+ 81: y <= u1[0] ? u1 : s2;
116
+ 82: y <= u1[0] ? s1 : u2;
117
+ 83: y <= u1[0] ? s1 : s2;
118
+ endcase
119
+ end
120
+
121
+ endmodule
chips/yosys/tests/simple/param_attr.v ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module uut_param_attr (I, O);
2
+
3
+ (* PARAMETER_ATTRIBUTE = "attribute_content" *)
4
+ parameter WIDTH = 1;
5
+
6
+ input wire [WIDTH-1:0] I;
7
+ output wire [WIDTH-1:0] O;
8
+
9
+ assign O = I;
10
+
11
+ endmodule
chips/yosys/tests/simple/paramods.v ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ module pm_test1(a, b, x, y);
3
+
4
+ input [7:0] a, b;
5
+ output [7:0] x, y;
6
+
7
+ inc #(.step(3)) inc_a (.in(a), .out(x));
8
+ inc #(.width(4), .step(7)) inc_b (b, y);
9
+
10
+ endmodule
11
+
12
+ // -----------------------------------
13
+
14
+ module pm_test2(a, b, x, y);
15
+
16
+ input [7:0] a, b;
17
+ output [7:0] x, y;
18
+
19
+ inc #(5) inc_a (.in(a), .out(x));
20
+ inc #(4, 7) inc_b (b, y);
21
+
22
+ endmodule
23
+
24
+ // -----------------------------------
25
+
26
+ module pm_test3(a, b, x, y);
27
+
28
+ input [7:0] a, b;
29
+ output [7:0] x, y;
30
+
31
+ inc inc_a (.in(a), .out(x));
32
+ inc inc_b (b, y);
33
+
34
+ defparam inc_a.step = 3;
35
+ defparam inc_b.step = 7;
36
+ defparam inc_b.width = 4;
37
+
38
+ endmodule
39
+
40
+ // -----------------------------------
41
+
42
+ module inc(in, out);
43
+
44
+ parameter width = 8;
45
+ parameter step = 1;
46
+
47
+ input [width-1:0] in;
48
+ output [width-1:0] out;
49
+
50
+ assign out = in + step;
51
+
52
+ endmodule
chips/yosys/tests/simple/partsel.v ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ module partsel_test001(input [2:0] idx, input [31:0] data, output [3:0] slice_up, slice_down);
2
+ wire [5:0] offset = idx << 2;
3
+ assign slice_up = data[offset +: 4];
4
+ assign slice_down = data[offset + 3 -: 4];
5
+ endmodule
6
+
7
+ module partsel_test002 (
8
+ input clk, rst,
9
+ input [7:0] a,
10
+ input [0:7] b,
11
+ input [1:0] s,
12
+ output [7:0] x1, x2, x3,
13
+ output [0:7] x4, x5, x6,
14
+ output [7:0] y1, y2, y3,
15
+ output [0:7] y4, y5, y6,
16
+ output [7:0] z1, z2, z3,
17
+ output [0:7] z4, z5, z6,
18
+ output [7:0] w1, w2, w3,
19
+ output [0:7] w4, w5, w6,
20
+ output [7:0] p1, p2, p3, p4, p5, p6,
21
+ output [0:7] q1, q2, q3, q4, q5, q6,
22
+ output reg [7:0] r1,
23
+ output reg [0:7] r2
24
+ );
25
+
26
+ assign x1 = a, x2 = a + b, x3 = b;
27
+ assign x4 = a, x5 = a + b, x6 = b;
28
+ assign y1 = a[4 +: 3], y2 = a[4 +: 3] + b[4 +: 3], y3 = b[4 +: 3];
29
+ assign y4 = a[4 +: 3], y5 = a[4 +: 3] + b[4 +: 3], y6 = b[4 +: 3];
30
+ assign z1 = a[4 -: 3], z2 = a[4 -: 3] + b[4 -: 3], z3 = b[4 -: 3];
31
+ assign z4 = a[4 -: 3], z5 = a[4 -: 3] + b[4 -: 3], z6 = b[4 -: 3];
32
+ assign w1 = a[6:3], w2 = a[6:3] + b[3:6], w3 = b[3:6];
33
+ assign w4 = a[6:3], w5 = a[6:3] + b[3:6], w6 = b[3:6];
34
+ assign p1 = a[s], p2 = b[s], p3 = a[s+2 +: 2], p4 = b[s+2 +: 2], p5 = a[s+2 -: 2], p6 = b[s+2 -: 2];
35
+ assign q1 = a[s], q2 = b[s], q3 = a[s+2 +: 2], q4 = b[s+2 +: 2], q5 = a[s+2 -: 2], q6 = b[s+2 -: 2];
36
+
37
+ always @(posedge clk) begin
38
+ if (rst) begin
39
+ { r1, r2 } = 16'h1337 ^ {a, b};
40
+ end else begin
41
+ case (s)
42
+ 0: begin
43
+ r1[3:0] <= r2[0:3] ^ x1;
44
+ r2[4:7] <= r1[7:4] ^ x4;
45
+ end
46
+ 1: begin
47
+ r1[2 +: 3] <= r2[5 -: 3] + x1;
48
+ r2[3 +: 3] <= r1[6 -: 3] + x4;
49
+ end
50
+ 2: begin
51
+ r1[6 -: 3] <= r2[3 +: 3] - x1;
52
+ r2[7 -: 3] <= r1[4 +: 3] - x4;
53
+ end
54
+ 3: begin
55
+ r1 <= r2;
56
+ r2 <= r1;
57
+ end
58
+ endcase
59
+ end
60
+ end
61
+
62
+ endmodule
63
+
64
+ module partsel_test003(input [2:0] a, b, input [31:0] din, output [3:0] dout);
65
+ assign dout = din[a*b +: 2];
66
+ endmodule
67
+
68
+ module partsel_test004 (
69
+ input [31:0] din,
70
+ input signed [4:0] n,
71
+ output reg [31:0] dout
72
+ );
73
+ always @(*) begin
74
+ dout = 0;
75
+ dout[n+1 +: 2] = din[n +: 2];
76
+ end
77
+ endmodule
78
+
79
+
80
+ module partsel_test005 (
81
+ input [31:0] din,
82
+ input signed [4:0] n,
83
+ output reg [31:0] dout
84
+ );
85
+ always @(*) begin
86
+ dout = 0;
87
+ dout[n+1] = din[n];
88
+ end
89
+ endmodule
90
+
91
+ module partsel_test006 (
92
+ input [31:-32] din,
93
+ input signed [4:0] n,
94
+ output reg [31:-32] dout
95
+ );
96
+ always @(*) begin
97
+ dout = 0;
98
+ dout[n+1 +: 2] = din[n +: 2];
99
+ end
100
+ endmodule
101
+
102
+
103
+ module partsel_test007 (
104
+ input [31:-32] din,
105
+ input signed [4:0] n,
106
+ output reg [31:-32] dout
107
+ );
108
+ always @(*) begin
109
+ dout = 0;
110
+ dout[n+1] = din[n];
111
+ end
112
+ endmodule
113
+
114
+
115
+ module partsel_test008 (
116
+ input [127:0] din,
117
+ input [3:0] idx,
118
+ input [4:0] uoffset,
119
+ input signed [4:0] soffset,
120
+ output [ 7:0] dout0,
121
+ output [ 7:0] dout1,
122
+ output [ 7:0] dout2,
123
+ output [ 7:0] dout3,
124
+ output [ 3:0] dout4,
125
+ output [ 3:0] dout5,
126
+ output [ 3:0] dout6,
127
+ output [ 3:0] dout7,
128
+ output [ 3:0] dout8,
129
+ output [11:0] dout9,
130
+ output [11:0] dout10,
131
+ output [11:0] dout11
132
+ );
133
+
134
+ // common: block-select with offsets
135
+ assign dout0 = din[idx*8 +uoffset +:8];
136
+ assign dout1 = din[idx*8 -uoffset +:8];
137
+ assign dout2 = din[idx*8 +soffset +:8];
138
+ assign dout3 = din[idx*8 -soffset +:8];
139
+
140
+ // only partial block used
141
+ assign dout4 = din[idx*8 +uoffset +:4];
142
+ assign dout5 = din[idx*8 -uoffset +:4];
143
+ assign dout6 = din[idx*8 +soffset +:4];
144
+ assign dout7 = din[idx*8 -soffset +:4];
145
+
146
+ // uncommon: more than one block used
147
+ assign dout8 = din[idx*8 +uoffset +:12];
148
+ assign dout9 = din[idx*8 -uoffset +:12];
149
+ assign dout10 = din[idx*8 +soffset +:12];
150
+ assign dout11 = din[idx*8 -soffset +:12];
151
+ endmodule