Merge pull request #2365 from zachjs/const-arg-loop-split-type
[yosys.git] / tests / various / const_func.v
1 module Example(outA, outB, outC, outD);
2 parameter OUTPUT = "FOO";
3 output wire [23:0] outA;
4 output wire [23:0] outB;
5 output reg outC, outD;
6 function automatic [23:0] flip;
7 input [23:0] inp;
8 flip = ~inp;
9 endfunction
10
11 generate
12 if (flip(OUTPUT) == flip("BAR"))
13 assign outA = OUTPUT;
14 else
15 assign outA = 0;
16
17 case (flip(OUTPUT))
18 flip("FOO"): assign outB = OUTPUT;
19 flip("BAR"): assign outB = 0;
20 flip("BAZ"): assign outB = "HI";
21 endcase
22
23 genvar i;
24 initial outC = 0;
25 for (i = 0; i != flip(flip(OUTPUT[15:8])); i = i + 1)
26 if (i + 1 == flip(flip("O")))
27 initial outC = 1;
28 endgenerate
29
30 integer j;
31 initial begin
32 outD = 1;
33 for (j = 0; j != flip(flip(OUTPUT[15:8])); j = j + 1)
34 if (j + 1 == flip(flip("O")))
35 outD = 0;
36 end
37 endmodule
38
39 module top(out);
40 wire [23:0] a1, a2, a3, a4;
41 wire [23:0] b1, b2, b3, b4;
42 wire c1, c2, c3, c4;
43 wire d1, d2, d3, d4;
44 Example e1(a1, b1, c1, d1);
45 Example #("FOO") e2(a2, b2, c2, d2);
46 Example #("BAR") e3(a3, b3, c3, d3);
47 Example #("BAZ") e4(a4, b4, c4, d4);
48
49 output wire [24 * 8 - 1 + 4 :0] out;
50 assign out = {
51 a1, a2, a3, a4,
52 b1, b2, b3, b4,
53 c1, c2, c3, c4,
54 d1, d2, d3, d4};
55
56 function signed [31:0] negate;
57 input integer inp;
58 negate = ~inp;
59 endfunction
60 parameter W = 10;
61 parameter X = 3;
62 localparam signed Y = $floor(W / X);
63 localparam signed Z = negate($floor(W / X));
64
65 // `define VERIFY
66 `ifdef VERIFY
67 assert property (a1 == 0);
68 assert property (a2 == 0);
69 assert property (a3 == "BAR");
70 assert property (a4 == 0);
71 assert property (b1 == "FOO");
72 assert property (b2 == "FOO");
73 assert property (b3 == 0);
74 assert property (b4 == "HI");
75 assert property (c1 == 1);
76 assert property (c2 == 1);
77 assert property (c3 == 0);
78 assert property (c4 == 0);
79 assert property (d1 == 0);
80 assert property (d2 == 0);
81 assert property (d3 == 1);
82 assert property (d4 == 1);
83
84 assert property (Y == 3);
85 assert property (Z == ~3);
86 `endif
87 endmodule