Ready-to-run snippets

Code Examples

Ready-to-run Verilog, SystemVerilog, and UVM examples. Click any to open it live in the IDE.

← All examples

Clocking Blocks Part 2: Input Skew in Detail

SystemVerilog Interfaces & Modports

Runnable example from the SystemVerilog Clocking Blocks Part 2 tutorial (Input Skew in Detail)

Open in IDE
design.sv
module des (output logic [3:0] gnt);
  always #1 gnt <= $random;
endmodule

interface _if (input logic clk);
  logic [3:0] gnt;

  clocking cb_0 @(posedge clk);
    input #0     gnt;      // sample at posedge, in Observed region
  endclocking

  clocking cb_1 @(posedge clk);
    input #1step gnt;      // sample in Preponed region (just before posedge)
  endclocking

  clocking cb_2 @(posedge clk);
    input #1ns   gnt;      // sample 1ns before posedge
  endclocking

  clocking cb_3 @(posedge clk);
    input #2ns   gnt;      // sample 2ns before posedge
  endclocking
endinterface
testbench.sv
module tb;
  logic clk;

  initial clk = 0;
  always #5 clk = ~clk;   // 10ns period

  _if    vif (.clk(clk));
  des    dut (.gnt(vif.gnt));

  initial begin
    fork
      begin @(vif.cb_0); $display("cb_0 (#0    ): gnt = 0x%0h", vif.cb_0.gnt); end
      begin @(vif.cb_1); $display("cb_1 (#1step): gnt = 0x%0h", vif.cb_1.gnt); end
      begin @(vif.cb_2); $display("cb_2 (#1ns  ): gnt = 0x%0h", vif.cb_2.gnt); end
      begin @(vif.cb_3); $display("cb_3 (#2ns  ): gnt = 0x%0h", vif.cb_3.gnt); end
    join
    #10 $finish;
  end
endmodule
Admin mode — edit and delete controls are visible on each row. Use the IDE to add new snippets via File → Save as Snippet.