Merge pull request #1814 from YosysHQ/mmicko/pyosys_makefile
[yosys.git] / tests / simple / task_func.v
1
2 module task_func_test01(clk, a, b, c, x, y, z, w);
3
4 input clk;
5 input [7:0] a, b, c;
6 output reg [7:0] x, y, z, w;
7
8 function [7:0] sum_shift;
9 input [3:0] s1, s2, s3;
10 sum_shift = s1 + (s2 << 2) + (s3 << 4);
11 endfunction
12
13 task reset_w;
14 w = 0;
15 endtask
16
17 task add_to;
18 output [7:0] out;
19 input [7:0] in;
20 out = out + in;
21 endtask
22
23 always @(posedge clk) begin
24 x = sum_shift(a, b, c);
25 y = sum_shift(a[7:4], b[5:2], c[3:0]);
26 z = sum_shift(a[0], b[5:4], c >> 5) ^ sum_shift(1, 2, 3);
27
28 reset_w;
29 add_to(w, x);
30 add_to(w, y);
31 add_to(w, z);
32 end
33
34 endmodule
35
36 // -------------------------------------------------------------------
37
38 module task_func_test02(clk, a, b, c, x, y, z, w);
39
40 input clk;
41 input [7:0] a, b, c;
42 output reg [7:0] x, y, z, w;
43
44 function [7:0] sum_shift(input [3:0] s1, s2, s3);
45 sum_shift = s1 + (s2 << 2) + (s3 << 4);
46 endfunction
47
48 task reset_w;
49 w = 0;
50 endtask
51
52 task add_to(output [7:0] out, input [7:0] in);
53 out = out + in;
54 endtask
55
56 always @(posedge clk) begin
57 x = sum_shift(a, b, c);
58 y = sum_shift(a[7:4], b[5:2], c[3:0]);
59 z = sum_shift(a[0], b[5:4], c >> 5) ^ sum_shift(1, 2, 3);
60
61 reset_w;
62 add_to(w, x);
63 add_to(w, y);
64 add_to(w, z);
65 end
66
67 endmodule
68
69 // -------------------------------------------------------------------
70
71 module task_func_test03(input [7:0] din_a, input [7:0] din_b, output [7:0] dout_a);
72 assign dout_a = test(din_a,din_b);
73 function [7:0] test;
74 input [7:0] a;
75 input [7:0] b;
76 begin : TEST
77 integer i;
78 for (i = 0; i <= 7; i = i + 1)
79 test[i] = a[i] & b[i];
80 end
81 endfunction
82 endmodule
83
84 // -------------------------------------------------------------------
85
86 module task_func_test04(input [7:0] in, output [7:0] out1, out2, out3, out4);
87 parameter p = 23;
88 parameter px = 42;
89 function [7:0] test1;
90 input [7:0] i;
91 parameter p = 42;
92 begin
93 test1 = i + p;
94 end
95 endfunction
96 function [7:0] test2;
97 input [7:0] i;
98 parameter p2 = p+42;
99 begin
100 test2 = i + p2;
101 end
102 endfunction
103 function [7:0] test3;
104 input [7:0] i;
105 begin
106 test3 = i + p;
107 end
108 endfunction
109 function [7:0] test4;
110 input [7:0] i;
111 parameter px = p + 13;
112 parameter p3 = px - 37;
113 parameter p4 = p3 ^ px;
114 begin
115 test4 = i + p4;
116 end
117 endfunction
118 assign out1 = test1(in);
119 assign out2 = test2(in);
120 assign out3 = test3(in);
121 assign out4 = test4(in);
122 endmodule
123
124 // -------------------------------------------------------------------
125
126 // https://github.com/YosysHQ/yosys/issues/857
127 module task_func_test05(data_in,data_out,clk);
128 output reg data_out;
129 input data_in;
130 input clk;
131
132 task myTask;
133 output out;
134 input in;
135 out = in;
136 endtask
137
138 always @(posedge clk) begin
139 myTask(data_out,data_in);
140 end
141 endmodule