L14 Parameterized Models, Task and Function, Parameterized Simulation, and Testbenches

Prof. Ryan Robucci

Table of Contents

L14 Parameterized Models, Task and Function, Parameterized Simulation, and Testbenches

Common Types

Procedural Timing Control (review/repeated from earlier lecture)

References

Parameterized Modules

Common Types

Integer

Table 3-1: Integer data types

integer type description
shortint 2-state SystemVerilog data type, 16 bit signed integer
int 2-state SystemVerilog data type, 32 bit signed integer
longint 2-state SystemVerilog data type, 64 bit signed integer
byte 2-state SystemVerilog data type, 8 bit signed integer or ASCII character
bit 2-state SystemVerilog data type, user-defined vector size
logic 4-state SystemVerilog data type, user-defined vector size
reg 4-state Verilog-2001 data type, user-defined vector size
integer 4-state Verilog-2001 data type, 32 bit signed integer
time 4-state Verilog-2001 data type, 64-bit unsigned

String

string myName = "John Smith"

Parameterized Module Example

module vector_subtractor
  #(
    parameter N = 4
    )
   (

    clk,
    clk_en,
    input_valid,
    vec_a,
    vec_b,
    output_valid,
    result
    );
   

   localparam WIDTH = 32;
   

   input wire                    clk;
   input wire                    clk_en;
   input wire                    input_valid;
   input wire [N * WIDTH - 1:0]  vec_a;
   input wire [N * WIDTH - 1:0]  vec_b;
   output wire                   output_valid;
   output reg [N * WIDTH - 1:0]  result;

    // Internal registers
    reg [WIDTH - 1:0]  a[0:N-1];
    reg [WIDTH - 1:0]  b[0:N-1];
    wire [WIDTH - 1:0] r[0:N-1];
    wire [N-1:0] output_valid_;
    
   // Slice the vector into elements
   always_comb_ begin:slicer
      integer i;      
      for(i=0;i<N;i=i+1) begin
         a[i] = vec_a[i*WIDTH +:WIDTH];
         b[i] = vec_b[i*WIDTH +:WIDTH];
         result[i*WIDTH+:WIDTH] = r[i];
      end
   end
   
   assign output_valid = &output_valid_;
   
   // Instatiate floating point subtractors
   genvar i;
   generate 
      for (i=0;i<N;i=i+1) begin:subtractors         
         fp_subtractor sub_inst (
                                    .clk(clk),
                                    .clk_en(clk_en),
                                    .input_valid(input_valid),
                                    .a(a[i]),
                                    .b(b[i]),
                                    .output_valid(output_valid_[i]),
                                    .out(r[i])
                                    );         
      end // block: multiplers
   endgenerate                
endmodule

Example instatiation (passes paramter N from local module to submodule)

       vector_subtractor #(.N(N)) vsubstractor_inst (
                        .clk(clk),
                        .clk_en(clk_en),
                        .input_valid(scaler_output_valid),
                        .vec_a(vec_b),
                        .vec_b(row_product),
                        .output_valid(output_valid),
                        .result(vec_r)
                         );     

Parameterized Simulation Models

Parametrization modules are useful for creating simulation for simulation that takes much less time to simulate, involves
minimal differences from the code used for hardware synthesis, and maintains high functional test coverage.

Functions and Tasks

Procedural Timing Control (review/repeated from earlier lecture)

Procedural Timing Controls

event triggerName;
@(triggerName);
-> triggerName;

Event Control Operator

The event control operator may be provided with variable multiple variables using comma separation. (older syntax is to us or)

@(a,b,c)
@(a or b or c)

Negedge and posedge restrict sensitivity to the following
transitions

@(posedge clk or negedge en)

Level-sensitive event control using wait

Repeat

Any timing control may be modified so as to be repeated/multiplied, by using the keyword repeat

repeat (count) @ (event expression)

If count is positive, repeat the timing control that number of time. If count is equal or less than 0, skip

Wait fot 10 clk rising edges before proceeding execution:

repeat (10) @ (posedge clk);

Delay an assignment by 5 clk edges

a <= repeat(5) @(posedge clk) data;

Delay an assignment by 5 inverter delays:

parameter INV_DELAY = 4.5;
a <= repeat(5) #INV_DELAY data;

initial and always

The initial construct is used to denote code to be executed once at the beginning of the simulation.

The always construct causes code to run repeatedly in an infinite loop. It is only useful with a delay or control construct, otherwise will create a zero delay infinite loop that can block time progression in simulation

This would run infinitely and stall the simulation time:

always x=a&b;

This prints endlessly in the beginning
of the simulation:

always begin
  $display(“hello %0t”);
end
0 : hello
0 : hello
0 : hello
0 : hello
0 : hello ...

Time Unit and Resolution (also review)

VCD (Value Change Dump) File

VCD Control (review L07)

IEEE Std 1364™-2005 https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=1620780

Testbench (section hidden, time did not allow coverage)

L14 Parameterized Models, Task and Function, Parameterized Simulation, and Testbenches

Common Types

Procedural Timing Control (review/repeated from earlier lecture)