"普通"开端块有什么意义?

Ran*_*lue 6 verilog system-verilog

我正在读一些第三方Verilog,发现这个:

function [31:0] factorial;
    input [3:0] operand;
    reg [3:0] index;

    begin
        factorial = operand ? 1 : 0;
        for(index = 2; index <= operand; index = index + 1)
        factorial = index * factorial;
    end
endfunction
Run Code Online (Sandbox Code Playgroud)

似乎beginend关键字在这里是多余的.是吗?它们的用途是什么?

Tim*_*Tim 8

我不知道一般情况,但在这个具体情况下:

If a function contains more than one statement, the statements must be
enclosed in a begin-end or fork-join block. 
Run Code Online (Sandbox Code Playgroud)

资料来源:Verilog Golden参考指南


Cli*_*ngs 7

两个答案都是正确的.如果Verilog任务或函数有多个语句,则还要求它们具有begin-end语句.从SystemVerilog-2005开始,我们删除了将begin-end放在已经有一个开始端的东西的要求.我们委员会中的大多数人都认为要求一个已经具有endfunction/endtask的东西的开端内容是愚蠢的.我的意思是,来吧!难道你不认为编译器可以弄清楚当它得到endtask/endfunction语句时它是在任务或函数的末尾?从任务和函数中删除开始端会减少大量无用的代码.为SystemVerilog评分另一分!

问候 - Cliff Cummings - Verilog&SystemVerilog Guru