我是靠谱客的博主 跳跃钢笔,这篇文章主要介绍Verilog定义计算位宽的函数clogb2,现在分享给大家,希望可以做个参考。

在很多情况下要计算输入输出的位宽,比如你写一个8*8的ram,那么地址需要三位去表示,那么这个函数的方便就体现出来了,你需要使用函数定义就好了。

//位宽计算函数
function integer clogb2 (input integer depth);
begin
for (clogb2=0; depth>0; clogb2=clogb2+1)
depth = depth >>1;
end
endfunction

举个栗子

parameter p_cnt_max = p_rev_time*p_clk_fre*1000_000 - 1; //翻转时间内所需计数的最大值
//位宽计算函数
function integer clogb2 (input integer depth);
begin
for (clogb2=0; depth>0; clogb2=clogb2+1)
depth = depth >>1;
end
endfunction
wire [clogb2(p_cnt_max)-1:0] w_cnt_max;

 

以上。

转载于:https://www.cnblogs.com/kingstacker/p/7662364.html

最后

以上就是跳跃钢笔最近收集整理的关于Verilog定义计算位宽的函数clogb2的全部内容,更多相关Verilog定义计算位宽内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(101)

评论列表共有 0 条评论

立即
投稿
返回
顶部