RAM 深度的地址宽度
我正在实现一个可配置的 DPRAM,其中 RAM DEPTH 是参数。
如何根据 RAM 深度确定地址宽度?
我知道关系 RAM DEPTH = 2 ^ (ADDRESS WIDTH)
即 ADDRESS WIDTH = log (base 2) RAM DEPTH。
如何在Verilog中实现log(以2为底)函数?
I am implementing a configurable DPRAM where RAM DEPTH is the parameter.
How to determine ADDRESS WIDTH from RAM DEPTH?
I know the relation RAM DEPTH = 2 ^ (ADDRESS WIDTH)
i.e ADDRESS WIDTH = log (base 2) RAM DEPTH.
How to implement the log (base 2) function in Verilog?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$clog2
系统任务已添加到 Verilog (IEEE Std 1800-2005) 的 SystemVerilog 扩展中。这将返回一个整数,其值为对数底数 2 的上限。深度不必是 2 的幂。运行模拟将显示以下内容:
但是,我不知道支持
$ 的综合工具堵塞2。如果您需要综合代码,可以使用
函数
。这是从 IEEE 1364-2001 Std 复制的,但网络上还流传着其他版本:我的经验是,使用
function
对于可合成代码来说,使用function
带来的麻烦比其价值更大。它给设计流程中的其他工具(linter、等价检查器等)带来了问题。The
$clog2
system task was added to the SystemVerilog extension to Verilog (IEEE Std 1800-2005). This returns an integer which has the value of the ceiling of the log base 2. The DEPTH need not be a power of 2.Running a simulation will display this:
However, I do not know of a synthesis tool which supports
$clog2
. If you need to synthesize your code, you can use afunction
. This was copied from the IEEE 1364-2001 Std, but there are other versions floating around the web:My experience has been that using the
function
is more trouble than it's worth for synthesizable code. It has caused problems for other tools in the design flow (linters, equivalence checkers, etc.).虽然 $clog2 是正确的答案,但在工具供应商赶上之前,您可以将自己的 clog2 函数实现为 verilog-2001 宏,它将与所有综合和仿真工具一起使用。
例如:
当最后的“-1”用于产生非法值时,模拟器应进行标记。
(后期编辑:哎呀,修复了我的差一错误!)
While $clog2 is the correct answer, until the tool vendors catch up, you can implement your own clog2 function as a verilog-2001 macro, which will work with all synthesis and simulation tools.
Such as:
Where the final "-1" is used to produce an illegal value the the simulator should flag.
(late edit: oops, fixed my off-by-one error!)