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

Constraint blocks are class members just like variables, functions and tasks and have unique names within a class. These blocks of expressions are typically used to limit the values of random variables within certain values as specified within the constraint block.


  constraint  [name_of_constraint] {  [expression 1];
                                      [expression N]; }

Expressions listed within the curly braces specify the conditions a solver has to take into account when assigning random values for the variables. It is not necessary to have a single constraint for every variable nor is it required to restrict a constraint block to have conditions pertaining only to a single variable. However you cannot have conflicting constraints spread out in multiple blocks, unless they are turned off using constraint_mode() method which we'll see later.

  constraint  valid_addr {    addr [1:0] == 2'b0;
                              addr <= 32'hfaceface;
                              addr >= 32'hf0000000; }
  constraint  fast_burst {    burst >= 3;
                              len   >= 64;
                              size  >= 128; }
  // Error - valid_addr already declared
  constraint valid_addr { ... }
  // Runtime error - solver fails due to conflict on addr
  constraint valid { addr >= 32'hfaceffff; }
  // Valid because solver can find an address that satisfies all conditions
  // eg :-  f200_0000 is below f400_0000 and face_face; and above f000_0000
  constraint valid2 { addr <= 32'hf4000000; }

There are some restraints on these blocks because of their declarative nature. Note that constraint blocks are enclosed within curly braces { } instead of the begin end keywords of procedural statements.

Was this article helpful ?

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