Welcome ! This website will help YOU (recent graduates/professionals) learn verification languages like SystemVerilog and UVM. Register for free and access more content !
1 minute reading time (159 words)

about the let construct in System Verilog ?

about the let construct in System Verilog ?

Many a time I have written functions that end up having only a single line of code in it and wished for a better alternative. System Verilog (1800-2009) has a construct called let that defines a template expression that can be used for customization and text replacement.

The let construct is supposed to be safer since it has a local scope and will not interfere with the global compiler directives. It can also be used as shortcuts for identifiers and expressions.

package my_expressions;
  let sum (a, b) = a + b;
  let max (a, b) = (a > b) ? a : b;
module tb;
  import my_expressions::*;
  bit [7:0] a, b;
  initial begin
    a = $random;
    b = $random;
    $display ("a=%0d b=%0d", a, b);
    $display ("sum = %0d", sum(a, b));
    $display ("Max = %0d", max(a, b));
Simulation Output
ncsim> run
a=36 b=129
sum = 165
Max = 129
ncsim: *W,RNQUIE: Simulation is complete.
how to randomize selected variables only
that you have to reset your register model ?


No comments made yet. Be the first to submit a comment
Already Registered? Login Here
Monday, 18 June 2018

We use cookies to personalize content and ads, to provide social media features and to analyze our traffic. You consent to our cookies if you continue to use our website. To find out more about the cookies we use and how to delete them, see our privacy policy.

  I accept cookies from this site.
EU Cookie Directive plugin by www.channeldigital.co.uk