Aurelian Ionel Munteanu

Gotcha: Using SystemVerilog Expressions as Array Indices

Using expressions in arrays indices may lead to unexpected behavior. For example: module top; initial begin automatic int array[10] = {0,1,2,3,4,5,6,7,8,9}; automatic bit idx1 = 1; automatic bit[1:0] idx2 = 3; // Is idx1+idx2 equal to 4 ? if (array[idx1+idx2] != array[4]) begin $error($sformatf(“array[%0d] != array[4]”,idx1+idx2)); end end endmodule OUTPUT: Error: array[0] != array[4] In […]

AMIQ Consulting

Gotcha: Using “rand” Modifier for Object Handles is not enough!

SystemVerilog allows rand modifier to be used for object handles and the object will be randomized only if it is not null. The “gotcha” is that, depending on the simulator, no error or warning will be issued if you forget to initialize the randomized object. Here is an example that illustrates the gotcha: class item; […]

Recommended Articles

Recommended Articles – March 2015

The Spring is here! We offer you a nice, hand-picked, bouquet of articles. Sean Eron Anderson saves us from the marsh of bitwise operations. He compiled a list of techniques, algorithms, operations, functions that one could do to pull oneself up: Standford: Bit Twiddling Hacks The Gentleman presents his view on the good, ol’ topic […]

AMIQ Consulting

Gotcha: Function Calls in SystemVerilog Constraints

SystemVerilog allows to call functions inside constraints, although, as I found out, it is a sensitive topic. Here is an example: class constraint_container; rand int unsigned a, b, c; function int unsigned get_a(); return a; endfunction function int unsigned value_of(int unsigned value); return value; endfunction constraint a_constraint { a == 5; // I expect “b” […]

AMIQ Consulting

Gotcha: SystemVerilog’s post_randomize() is Called Top-Down Not Bottom-Up

SystemVerilog classes contain the pre-defined function post_randomize(), which is automatically called at the end of the randomization. One can override this function to do extra processing after randomization. In SystemVerilog post_randomize() is called top-down and not bottom-up! The top-down call of post_randomize() is counter-intuitive, especially for those of you in love with e-Language, and it […]