Quantcast
Channel: Cadence Functional Verification
Viewing all articles
Browse latest Browse all 653

e Templates – Cool Tool, Now Even Cooler

$
0
0

One of the reasons why verification engineers love e is the power it gives them as no other language can. The combination of macros,reflection and extension allows you to create high quality utilities that can be shared by verification teams all over your company.

Such utilities are an effective way to enhance the quality of the verification environment; the base type or template are created once by experts, and used all over the company.

Template types in e allow you to write generic code, where the same flow and logic applies to different types. Several teamspecman’s blogs already discussed this feature in the past years:

e Templates: A Nifty Way To Create Reusable Code

e Templates and Aspect Oriented Programming

e Templates and e Macros -- An Update for Specman Users

For example, you can implement a hash table – a struct containing a list of items – and then implement adding items to the list, searching the list, etc.

template struct hash of (<key’type>, <value’type>) {
   !items :  list of <value’type>;
   add(key : (<key’type>, item : <value’type>) is {
  };
};

After defining the hash template, you can instantiate a hash of any type, for example – below we create two hash tables, one of structs and one of integers :

extend env {
    // the key is integer, the items in this hash – pkt struct
    hashed_pkts : hash of (int, pkt);   

    // the key is integer, the items in this hash – an address
    hashed_address : hash of (int, uint (bits : 32);
};

Several enhancements to this feature in IES15.1, make the template even more useful.

As discussed in the “e templates and AOP” blog above, the unique combination of AOP nature e with templates allows you to refine a specific template instance, by extending it and adding or updating its members just as you do with regular e structs.

However, what was still missing (and this was even raised by one of the readers of the above blog) was the ability to extend the entire template definition and not just one specific instance. And dreams become reality - as promised in a reply to that user’s comment, we did consider this, and starting from Specman version 15.1 it is possible to extend the entire template. The syntax of extending a template is very similar to the syntax of defining a template, just replace the struct/unit with extend.

For example, we can extend the hash template defined above - 

template extend hash of (<key’type>, <value’type>) {
   size : uint;
   add(key : (<key’type>, item : <value’type>) is first {
   if  items.size() >= size {
      ///
    };

  };
};

The second enhancement we added is the option to define parameter boundaries– that is, enforce types when the template is used. For example, to support only tables in which the key is numeric (a number or enum):

template struct hash of (<key’type> : numeric, <value’type>) {
   !items :  list of <value’type>;
   add(key : (<key’type>, item : <value’type>) is {
   };
};

And, combining these two capabilities - it is now possible to make a template extension apply only to certain (but not all) instantiations of the template, depending on the actual type parameters, making template usage in e even more flexible.

For example, to extend the hash template defined above, defining special behavior for the hash table of structs, extend it as follows

template extend map of (<key’type>: numeric,
                        <value’type>: struct) {
   add(key : (<key’type>, item : <value’type>) is also {
   };
};

This extension of the add () method is only activated when the hash is of struct (hashed_pkts, in the code shown above), and will not be activated when the table is of any other type (the hashed_address in the example).

Using templates with the capability to extend it, including the option to extend per specific types, gives you the power to create a verification framework to be used throughout the company, by various teams handling different types.

Efrat Shneydor, Team Specman Solutions Architect

 

 

 

 


Viewing all articles
Browse latest Browse all 653

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>