Wednesday, November 13, 2013

Polymorphism in SystemVerilog - good

Polymorphism in SystemVerilog

Many forms of the same Method based on the execution of the method at Run Time.

program test_poly;

  class shape;
    int width, height;
 
    function new(int x=0, int y=0);
      width  = x;
      height =y;
    endfunction //new

    virtual function area ();
      $display("From Shape Class");
    endfunction //area
  endclass //shape


  class rectangle extends shape;
    function new(int x=0, int y=0);
      super.new(x,y);
    endfunction //new

    function area();
      $display ("Rectangle area:width:%0d height:%0d ",width,height, width * height);
      return(width * height);
    endfunction //area
  endclass //rectangle

  class triangle extends shape;
    function new(int x=0, int y=0);
      super.new(x,y);
    endfunction //new

    function area();
      $display ("Triangle area:width:%0d height:%0d ",width,height, (width * height/2));
      return(width * height);
    endfunction //area
  endclass //triangle

  initial begin
    shape shape[2];
    rectangle rect1 = new(10,20);
    triangle  tria1 = new(10,20);

    shape[0] = rect1;
    shape[1] = tria1;

    shape[0].area();
    shape[1].area();

    #10; $display("Test End");
  end //initial

endprogram //test_poly

The program output as follows,

WITHOUT "virtual" keyword in 'area' function in 'shape' class
From Shape Class

From Shape Class

WITH "virtual" keyword in 'area' function in 'shape' class
Rectangle area:width:10 height:20         200
Triangle area:width:10 height:20         100

Friday, November 8, 2013

SV Data type: Scope & Lifetime

will add it her .... later ... !!!

Queue in SystemVerilog - Very fancy

Power of Queues in System Verilog Test benches - 
- are very fancy to use in Test Benches - 
- Queue can increase/decrease the number of elements in it as per need basis.
- Methods Available - size(), insert(), delete(), push_front(), push_back(), pop_front(), pop_back()
- Check the usage of these methods in below program.
- Powerful to use as per need basis 
- Multiple ways to edit (to insert or delete) an element of a queue

Here is a sample code which explores the features of the Queue...!!!
#####################################################################
module test;

 integer IntQueue[$] = {0,1,2,3,4}; //Queue Declaration with initialization
 integer i, temp;
  
 initial begin
   $display("Size of the queue: %0d",IntQueue.size());       //Size of The Queue
   $display("First Element of the queue: %0d",IntQueue[0]); //1st Element Access
   $display("Last Element of the queue: %0d",IntQueue[$]); //Last Element Access
   
   print_queue("INITIAL QUEUE");
   
   IntQueue.push_front(9);     //Insert, push 9 in front of the queue - push_front()
   print_queue("PUSH_FRONT()");
   
   temp=IntQueue.pop_front();  //Get, pop 1st element of the queue - pop_front()
   print_queue("POP_FRONT()");
   
   IntQueue.insert(0,9);       //Insert 9 before 1st element of the queue - instert()
   print_queue("INSERT()");
   
   IntQueue.delete(0);         //Delete 1st element of the queue - delete()
   print_queue("DELETE()");
   
   IntQueue.push_back(9);      //Insert 9 at the end of the queue - push_back()
   print_queue("PUSH_BACK()");
   
   IntQueue.pop_back();        //Delete Last element of the queue - pop_back()
   print_queue("POP_BACK()");
 end

 //Task to Print Queue
 task print_queue(string fname);
   $display("IntQueue: After Operation:%s",fname);
   for (i=0; i<IntQueue.size(); i++)
     $display("I=%0d IntQueue[%0d]=%0d ",i,i,IntQueue[i]);
 endtask

endmodule //module test
#####################################################################
Run Log follows as ...:
#####################################################################
Size of the queue: 5
First Element of the queue: 0
Last Element of the queue: 4
Queue: From Function: After Operation:INITIAL QUEUE
I=0 IntQueue[0]=0 
I=1 IntQueue[1]=1 
I=2 IntQueue[2]=2 
I=3 IntQueue[3]=3 
I=4 IntQueue[4]=4 
Queue: From Function: After Operation:PUSH_FRONT()
I=0 IntQueue[0]=9 
I=1 IntQueue[1]=0 
I=2 IntQueue[2]=1 
I=3 IntQueue[3]=2 
I=4 IntQueue[4]=3 
I=5 IntQueue[5]=4 
Queue: From Function: After Operation:POP_FRONT()
I=0 IntQueue[0]=0 
I=1 IntQueue[1]=1 
I=2 IntQueue[2]=2 
I=3 IntQueue[3]=3 
I=4 IntQueue[4]=4 
Queue: From Function: After Operation:INSERT()
I=0 IntQueue[0]=9 
I=1 IntQueue[1]=0 
I=2 IntQueue[2]=1 
I=3 IntQueue[3]=2 
I=4 IntQueue[4]=3 
I=5 IntQueue[5]=4 
Queue: From Function: After Operation:DELETE()
I=0 IntQueue[0]=0 
I=1 IntQueue[1]=1 
I=2 IntQueue[2]=2 
I=3 IntQueue[3]=3 
I=4 IntQueue[4]=4 
Queue: From Function: After Operation:PUSH_BACK()
I=0 IntQueue[0]=0 
I=1 IntQueue[1]=1 
I=2 IntQueue[2]=2 
I=3 IntQueue[3]=3 
I=4 IntQueue[4]=4 
I=5 IntQueue[5]=9 
Queue: From Function: After Operation:POP_BACK()
I=0 IntQueue[0]=0 
I=1 IntQueue[1]=1 
I=2 IntQueue[2]=2 
I=3 IntQueue[3]=3 
I=4 IntQueue[4]=4 
#####################################################################

Yaa... seen above are multiple ways to add or delete an element from a queue. 
Here are some more operations on queues ... 

IntQueue = IntQueue[1:$];    //Delete 1st Element
IntQueue = IntQueue[0:$-1]; //Delete Last Element
IntQueue = IntQueue[1:$-1]; //Delete 1st & Last Elements


Hope with this you've got to know the SV Queues Usage ... !

Thursday, November 7, 2013

AboutMyCareer

Here is in brief about My career...
I have done my Bachelor of Engineering in Electronics and Communications Engineering. I am having 11+years of experience in ASIC Verification field.  I am presently working in Bayarea, USA for 6 months. I'm good in Verilog, SystemVerilog and UVM. 
Hands on experience of Processor based SoC verification
Sub-system and system level verification
Good knowledge of using AMBA protocols (AXI, APB & AHB)
For any kind of information you are more than welcome to contact ... drop a msg