直接复制即可
/**************************************************
* 位宽计算函数 *
**************************************************/
function integer zhm_clogb2(input integer depth);
begin
for(zhm_clogb2=1; depth>1; zhm_clogb2=zhm_clogb2+1)
depth = depth>>1;
end
endfunction
仿真结果
`timescale 1ns / 1ps
module zhm_clogb2;
/**************************************************
* 位宽计算函数 *
**************************************************/
function integer zhm_clogb2(input integer depth);
begin
for(zhm_clogb2=1; depth>1; zhm_clogb2=zhm_clogb2+1)
depth = depth>>1;
end
endfunction
parameter C0 = zhm_clogb2(0 );
parameter C1 = zhm_clogb2(1 );
parameter C2 = zhm_clogb2(2 );
parameter C3 = zhm_clogb2(3 );
parameter C4 = zhm_clogb2(4 );
parameter C5 = zhm_clogb2(5 );
parameter C6 = zhm_clogb2(6 );
parameter C7 = zhm_clogb2(7 );
parameter C8 = zhm_clogb2(8 );
parameter C9 = zhm_clogb2(9 );
parameter C10 = zhm_clogb2(10);
parameter C11 = zhm_clogb2(11);
parameter C12 = zhm_clogb2(12);
parameter C13 = zhm_clogb2(13);
parameter C14 = zhm_clogb2(14);
parameter C15 = zhm_clogb2(15);
parameter C16 = zhm_clogb2(16);
parameter C17 = zhm_clogb2(17);
parameter C18 = zhm_clogb2(18);
parameter C19 = zhm_clogb2(19);
parameter C20 = zhm_clogb2(20);
parameter C21 = zhm_clogb2(21);
endmodule
输入 | zhm_clogb2 | |
0 | 1 | |
1 | 2^0 | 1 |
2 | 2^1 | 2 |
3 | 2 | |
4 | 2^2 | 3 |
5 | 3 | |
6 | 3 | |
7 | 3 | |
8 | 2^3 | 4 |
9 | 4 | |
10 | 4 | |
11 | 4 | |
12 | 4 | |
13 | 4 | |
14 | 4 | |
15 | 4 | |
16 | 2^4 | 5 |
17 | 5 | |
18 | 5 | |
19 | 5 | |
20 | 5 | |
21 | 5 |