Loops 我可以在verilog`define语句中使用for循环吗?
我需要在verilog宏中包含一个相当复杂的计算。我可以在宏定义中使用for循环吗?下面是我的代码示例Loops 我可以在verilog`define语句中使用for循环吗?,loops,for-loop,macros,verilog,definition,Loops,For Loop,Macros,Verilog,Definition,我需要在verilog宏中包含一个相当复杂的计算。我可以在宏定义中使用for循环吗?下面是我的代码示例 `define CLOGB2(depth) \ integer width \ for(width=0;depth>0;width=width+1) \ depth = depth >> 1; \ return width module test #(parameter MEMDEPTH = 16)
`define CLOGB2(depth) \
integer width \
for(width=0;depth>0;width=width+1) \
depth = depth >> 1; \
return width
module test #(parameter MEMDEPTH = 16)
(
// Input-output port declaration
);
parameter MEMWIDTH = `CLOGB2(MEMDEPTH);
$display("Calculated width : %d\n",MEMWIDTH);
...
...
endmodule
行吗 我认为这个问题在很大程度上是重复的 在这个问题中使用多行定义或任务的原因似乎是为了天花板log2功能,该功能可通过其他方式使用 SystemVerilog&Verilog-2005 内置的
$clog2()
函数可用
Verilog
如果$clog2
不可用,则包含您自己的功能可能更简单:
function integer CLog2;
input [31:0] depth;
integer i;
begin
i = depth;
for(CLog2 = 0; i > 0; CLog2 = CLog2 + 1)
i = i >> 1;
end
endfunction