aboutsummaryrefslogtreecommitdiffstats
path: root/tests/simple/func_recurse.v
blob: 02cfbcddf55b3bb4a3ce770e693d2dc3233da8f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module func_recurse_top(
	input wire [3:0] inp,
	output wire [3:0] out1, out2
);
	function automatic [3:0] pow_a;
		input [3:0] base, exp;
		begin
			pow_a = 1;
			if (exp > 0)
				pow_a = base * pow_a(base, exp - 1);
		end
	endfunction

	function automatic [3:0] pow_b;
		input [3:0] base, exp;
		begin
			pow_b = 1;
			if (exp > 0)
				pow_b = base * pow_b(base, exp - 1);
		end
	endfunction

	assign out1 = pow_a(inp, 3);
	assign out2 = pow_b(2, 2);
endmodule