Understand the role of SystemVerilog and select useful features for RTL design and verification.
SystemVerilog extends Verilog with types and constructs for both RTL and verification. An .sv file can contain a circuit or its testbench; the extension alone does not make code synthesizable.
Make intent visible
This counter uses explicit types and a specialized procedural block:
module
event_counter
#
(
parameter int unsigned WIDTH = 16
) (
input logic i_clk,
input logic i_rst,
input logic i_event,
output logic [WIDTH-1:0] o_count
);
always_ff @(posedge i_clk) begin
if (i_rst)
o_count <= '0;
else if (i_event)
o_count <= o_count + 1'b1;
end
endmodule
logic replaces the traditional reg usage here. always_ff declares clocked storage and enables driver checks. The counter holds its value without an event and returns to zero on reset.
WIDTH is an unsigned integer, but that does not guarantee a useful width. Zero is still possible, and converting a negative value to unsigned produces a very large value. Define supported configurations separately.
Choose constructs for their purpose
For hardware, the main additions are:
logic, integer types, and explicit conversions;
always_comb, always_ff, and always_latch;
enumerations, structures, arrays, and typedef;
packages, interfaces, modports, and value or type parameters.
Testbenches also use classes, objects, constrained randomization, temporal assertions, functional coverage, and task communication. Classes, randomization, and coverage generally verify hardware rather than describe its implementation.
Organize the project
Separate synthesizable RTL from verification code. Keep RTL within the subset supported by your synthesis tool. Use richer testbench features to prepare stimulus, observe the DUT, and compare results.
New keywords help tools find mistakes. Width choices, combinational/sequential separation, and timing analysis still remain your responsibility. Consult synthesis documentation when support for a construct depends on the tool.