k0b0's record.

Computer Engineering, Arts and Books

SystemVerilogのlogic型

 VerilogHDLでは記述する回路によってreg型とwire型を使い分ける必要がある。SystemVerilogでは新たにlogic型が導入されており、reg型とwire型を使い分けることなく全ての信号をlogic型で宣言することが出来る。これにより、reg型、wire型の使い分けのミスによって生じるバグを緩和できる。

従来のwire、reg型を使った記述例

module example(input sel, a, ck, reset,d,
                 output o);

/* Definition of wire and reg */
wire s1;
reg q;

always @(negedge ck or negedge reset)
begin
    if(!reset)
        q <= 1'b0;
    else
        q <= d;
end

assign s1 = a & d;
assign o  = (sel==1'b1) ? q:s1;
endmodule

SystemVerilogのlogic型を使った記述例

module example2(input sel, a, ck, reset,d,
                 output o);

/* Definition of logic */
logic s1;
logic q;

always_ff @(negedge ck or negedge reset)
begin
    if(!reset)
        q <= 1'b0;
    else
        q <= d;
end

assign s1 = a & d;
assign o  = (sel==1'b1) ? q:s1;
endmodule