• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. generate of specman (vs) randomize of systemverilog

Stats

  • Locked Locked
  • Replies 4
  • Subscribers 65
  • Views 15336
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

generate of specman (vs) randomize of systemverilog

onkarkk
onkarkk over 16 years ago

Hi,

Could any one please explain me clearly steps of generate and randomize and their significance.

i.e ., in generate it is told there is pre-generate and post-generate methods i could not understand clearly why they required.

In the same way in randomize() also there are pre_randomize() and post_randomize() methods will be invoked , i didnt get sufficient clarity on their explanation .. could any 

one please clarify the significance of those methods.

Thanks in advance,

regards

Krishna Kishore 

  • Cancel
Parents
  • StephenH
    StephenH over 16 years ago

    Hi Krishna.

    In both e and SV, the pre_ and post_ methods are used as procedural hooks to do things that cannot or should not be done with constraints. Both methods are called automatically by the randomisation engine, either side of the actual randomisation process.

    The pre_ method is less commonly needed in Specman, because Specman's generate action actually allocates memory for the objects as it does the randomisation, unlike SV which (unhelpfully) forces the user to new() every object before randomisation can take place. This becomes important when you are randomising a nested object (e.g. a burst class that contains a list of transfer class objects). In SV you might use pre_randomize() to allocate the nested classes so that they can also be randomised.

    The post_ method is more commonly used. A typical problem is to generate a valid CRC  for the object.
    It can be hard and inefficient to do this with constraints especially if your object has many optional fields, so we typically use a post_generate method to do this. I'll illustrate with e because I prefer it to SV, but the principle applies to both:

    struct packet {
      %address : byte;
      %length : uint;
      %payload[length] : list of byte;
      crc_error: bool;
      %crc;
      post_generate() is also {
        if !crc_error {
          crc = crc8(%{address,length,payload});
        };
      };
    };

    This code would generate a random crc value when you randomise the struct. The post_generate method then computes the correct crc if the crc_error control field is not set.

    Hope this helps. I would strongly recommend that you open the Specman docs (type "sn_help.sh" at the Unix prompt) and search for post_generate. The docs give a lot of guidance about how to use these methods properly, to avoid over-constraining your tests.
    A little biased note: Specman's documentation is fantastic, and has loads of great info for actually building your testbench; it's almost a proper book in its own right. By contrast, SystemVerilog is just a dry LRM spec which leaves you try to work out how and why you should do things. This is just one of the many reasons I prefer Specman to SV, it's so much easier to use!

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • StephenH
    StephenH over 16 years ago

    Hi Krishna.

    In both e and SV, the pre_ and post_ methods are used as procedural hooks to do things that cannot or should not be done with constraints. Both methods are called automatically by the randomisation engine, either side of the actual randomisation process.

    The pre_ method is less commonly needed in Specman, because Specman's generate action actually allocates memory for the objects as it does the randomisation, unlike SV which (unhelpfully) forces the user to new() every object before randomisation can take place. This becomes important when you are randomising a nested object (e.g. a burst class that contains a list of transfer class objects). In SV you might use pre_randomize() to allocate the nested classes so that they can also be randomised.

    The post_ method is more commonly used. A typical problem is to generate a valid CRC  for the object.
    It can be hard and inefficient to do this with constraints especially if your object has many optional fields, so we typically use a post_generate method to do this. I'll illustrate with e because I prefer it to SV, but the principle applies to both:

    struct packet {
      %address : byte;
      %length : uint;
      %payload[length] : list of byte;
      crc_error: bool;
      %crc;
      post_generate() is also {
        if !crc_error {
          crc = crc8(%{address,length,payload});
        };
      };
    };

    This code would generate a random crc value when you randomise the struct. The post_generate method then computes the correct crc if the crc_error control field is not set.

    Hope this helps. I would strongly recommend that you open the Specman docs (type "sn_help.sh" at the Unix prompt) and search for post_generate. The docs give a lot of guidance about how to use these methods properly, to avoid over-constraining your tests.
    A little biased note: Specman's documentation is fantastic, and has loads of great info for actually building your testbench; it's almost a proper book in its own right. By contrast, SystemVerilog is just a dry LRM spec which leaves you try to work out how and why you should do things. This is just one of the many reasons I prefer Specman to SV, it's so much easier to use!

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information