How to for System Verilog


* Main Manual is :

  Manuals/sysVerilog_IEEE_2017.pdf


* I put examples in qccloc/vivado/uvm


  For example to run --> tb_string1.sv


  fastver.pxe   -t tb   tb_string1.sv -build -run
  fastver.pxe   -t tb   tb_string1.sv -build -run
  fastver.pxe   -t tb   tb_string1.sv        -run
  fastver.pxe   -t tb                        -run
  fastver.pxe                                -run

  
  (note first time takes a long time. Second time will
   use tar file and also turn webtalk off. Also, if you
   don't use -build, it will be even faster)


* You can get numerous examples from

  https://www.chipverify.com

  https://www.chipverify.com/verification/codehub

  https://verificationacademy.com/forums/systemverilog/constrained-random-stimulus-urandom

  
  https://www.verificationguide.com/p/systemveilog-randomization-methods.html

* ******************************************************************************
* Example of Random Number Generation
* ******************************************************************************
/ testRandom2.sv
// This code base on :
// https://www.verificationguide.com/p/systemveilog-randomization-methods.html
//
// howto : fastver.pxe -t rand_methods testRandom1.sv -run -build

class gpacket;
  rand  bit [7:0] gaddr;
  randc bit [7:0] gdata;

  real    shan;
  int     jack;

  bit     gwrite;
  string  pkt_type;


  function int getFastSeed();
    int    fp;

    int numr;
    int ival;
    longint lval;


    fp = $fopen("fastver.seed", "r");

    if (fp == 0) begin
      $display("ERROR ----- COUND NOT OPEN fastver.seed");
      lval = 0;
      ival = 0;
    end
    else begin

      numr = $fscanf(fp, "%d", lval);

      if (numr != 1) begin
        $display("ERROR ----- COULD NOT READ fastver.seed");
        lval = 0;
        ival = 0;
      end
      else begin
        ival = lval % 32'd2147483648;
      end

      $fclose(fp);

      $display("lval=%d ival=%d", lval, ival);

      getFastSeed = ival;
    end

  endfunction



  function new();

    shan = 10.0;
    jack = this.getFastSeed();

    gwrite = 1;
    pkt_type = "GOOD_PKT";

    // DOES NOT WORK CORRECTLY WITHOUT "this"
    this.srandom(jack);
  endfunction



  function void display();
    $display("---------------------------------------------------------");
    $display("  gaddr     = %0d", gaddr);
    $display("  gdata     = %0h", gdata);
    $display("  shan      = %e",  shan);
    $display("  jack      = %d",  jack);
    $display("  gwrite    = %0d", gwrite);
    $display("  pkt_type  = %0s", pkt_type);
    $display("---------------------------------------------------------");
    $display("");
    $display("");
  endfunction



  //pre randomization function
  function void pre_randomize();
    $display("Inside pre_randomize --> %d", getFastSeed());
    $display("  value of gaddr = %0d, gdata = %0d", gaddr, gdata);
  endfunction

  //post randomization function
  function void post_randomize();
    $display("Inside post_randomize");
    $display("  value of gaddr = %0d, gdata = %0d", gaddr, gdata);
  endfunction

endclass

module rand_methods;
  initial begin
    gpacket pkt;

    $display("ONE");
    pkt = new();
    pkt.display();

    $display("TWO");
    pkt.randomize();
    pkt.display();

    $display("THREE");
    pkt.randomize();
    pkt.display();

  end
endmodule


* ******************************************************************************