Files
iverilog/ivtest/ivltests/function7.v
T
Stephen Williams cea237b407 Add ivtest to the iverilog source tree
By adding ivtest to the iverilog source tree, it is easier to keep
the regression test synchronized with the source that is being tested.
This should be especially helpful for PRs that add a new feature, and
have a matching ivtest PR with the regression test for that feature.
2022-01-15 10:18:50 -08:00

29 lines
704 B
Verilog

module test;
parameter BYTES = 2;
localparam mxbit = BYTES*8-1;
function integer clog2;
input value;
integer value;
for (clog2=0; value>0; clog2=clog2+1) value = value >> 1;
endfunction
// This is not recognized as a constant function call!
localparam cntrw = clog2(mxbit);
integer tmp;
initial begin
tmp = mxbit;
$display("The maximum bit is %0d and uses a %0d bit counter", mxbit, cntrw);
$display("clog2 does works here! Got %0d, should be %0d.", clog2(mxbit), clog2(tmp));
if (cntrw !== clog2(tmp)) begin
$display("FAILED -- cntrw=%0d", cntrw);
$finish;
end
$display("PASSED");
$finish;
end
endmodule