The next revision of the SystemVerilog standard IEEE Std 1800™-2023 was approved on December 6.
SV23 adds various enhancements, not just bug fixes. In this post, I summarize the main ones for the basic design language. In an upcoming post, I will summarize the testbench enhancements, such as Java-style weak references.
Update state variables by passing them to a task or function with ‘ref static’ arguments.
The next state in a SystemVerilog finite-state machine (FSM) is specified with a nonblocking assignment (NBA) that defers the assignment until late in the time step.
Until SV23 an FSM couldn’t be factored into manageable levels with tasks and functions, because a state variable passed as an argument couldn’t be the target of an NBA. This restriction was to prevent the potential mistake of passing an automatic variable.
In SV23 a task/function formal can have direction ‘ref static‘ and be passed a state variable to schedule a nonblocking assignment for it.
You can also refer to a ‘ref static’ argument from a fork-join_any or fork-join_none block in a function because it’s guaranteed that nothing automatic will be passed in so the argument will outlive the the fork block.
The BNF change is tf_port_direction in Syntax 13-1, from “const ref” to “[const] ref [static]”.
Associative array parameters for modules, classes and interfaces
A constant associative array can represent a lookup table keyed by strings, enums, integers, and so on. It can also represent a set by using an associative array of bits.
For example, #(.WEIGHT(‘{ HIGH:5, MEDIUM:3:, LOW:1 })) or #(.WEIGHT(my_weights())) where my_weights() is a function that returns an associative array.
The BNF change is param_assignment in Syntax 6-6 from “unpacked_dimension” to “variable_dimension”.
Python-style multiline string literals using triple quotes.
By bracketing the string with quotation marks three times instead of once, such as “””this”””, there is no need to escape newlines or quotation marks. See 5.9.
C-like conditional compilation with logical operators.
An ifdef/ifndef directive can now use the logical operators !, &&, ||, -> and <->. See Syntax 22-5.
‘Soft’ packed unions aren’t restricted to equal-sized members.
Now with the ‘soft’ qualfier, the size of the union is the size of the longest member. For details of the changes, including new Figure 7-1, see the proposal here.
Type parameters can declare the same restrictions as typedefs.
Now a type parameter can be declared as specifically “type enum”, “type struct”, “type class”, and so on. For details of the new BNF and examples, see the proposal here.
Expressions on unpacked arrays with new “map” method
For example, instead of declaring a temp array, doing
foreach (A[i]) temp[i] = A[i] + B[i];
and calling f( temp ), you can directly call
f( A.map with (item + B[item.index]) )
There is no BNF change for this. It’s a new built-in array manipulation method described in 7.12.5. The examples there use an overly complicated syntax. I would recommend the style of 7.12.4, where the example is “q = arr.find with (item == item.index);”. There are no parentheses after the method name and no declaration of a new variable name instead of the default “item”.