В Verilog вы можете использовать Ternary Operator для достижения функциональности.
module test(i,len);
input wire [16:0] i;
output reg [16:0] len;
initial
begin
len = i> 32767 ? 16 :
i> 16383 ? 15 :
i> 8191 ? 14 :
i> 4095 ? 13 :
i> 2047 ? 12 :
i> 1023 ? 11 :
i> 511 ? 10 :
i> 255 ? 9 :
i> 127 ? 8 :
i> 63 ? 7 :
i> 31 ? 6 :
i> 15 ? 5 :
i> 7 ? 4 :
i> 3 ? 3 :
i> 1 ? 2 : 1 ;
$display(i,,,,,len);
end
endmodule
В System Verilog $ clog2 () поможет вам в этом
module test;
bit [16:0] i;
bit [5:0] b;
bit [16:0] len;
initial
begin
repeat(5)
begin
assert(std::randomize(i,b) with { b inside {[1:15]};
i == 2**b; });
len = $clog2(i)+1;
$display(i,,,,,len);
end
end
endmodule