quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Data Structures

The SystemC Verification Standard contains several generic data structures. One of the main data types is sparse_array, this is used for modelling memories at very high of abstraction. When I say memories, it can be a simple memory or it can be used as scoreboard.

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Example : sparse_array
   

space.gif


   1 #include "scv.h"
   2 
   3 // Define a packet with a variable size payload
   4 class packetT {
   5   public:
   6     packetT () {}
   7     virtual ~packetT() {}
   8     // Packet's data
   9     sc_uint<16> src;
  10     sc_uint<16> dest;
  11     sc_uint<16> length; // Number of items in the payload
  12     sc_uint<16> payload[1024];
  13     // Define an equal operator
  14     packetT& operator=(const packetT& rhs) {
  15       src=rhs.src; dest=rhs.dest; length=rhs.length;
  16       for(unsigned int i=0; (i<length) && (i<1024); i++)
  17         payload[i]=rhs.payload[i];
  18       return *this;
  19     }
  20     // Define a comparison operator
  21     friend bool operator==(const packetT& a, const packetT& b) {
  22       if (a.src  ! = b.src) {return false;}
  23       if (a.dest  ! = b.dest) {return false;}
  24       if (a.length  ! = b.length) {return false;}
  25       for(unsigned int i=0; (i<a.length) && (i<1024); i++)
  26         if (a.payload[i]  ! = b.payload[i]) {return false;}
  27       return true;
  28     }
  29     // Define a not-equal operator (some compilers do not
  30     // automatically create this from operator=)
  31     friend bool operator ! =(const packetT& a, const packetT& b) {
  32       if (a.src  ! = b.src) {return true;}
  33       if (a.dest  ! = b.dest) {return true;}
  34       if (a.length  ! = b.length) {return true;}
  35       for(unsigned int i=0; (i<a.length) && (i<1024); i++)
  36         if (a.payload[i]  ! = b.payload[i]) {return true;}
  37       return false;
  38     }
  39     // Define ostream method to print data
  40     friend ostream& operator<< (ostream& os, const packetT& p) {
  41       os << "  src: "     <<  p.src
  42          << "  dest: "    <<  p.dest
  43          << "  length: "  <<  p.length 
  44          << "  payload: " <<  p.payload[0]
  45          << " .. "        <<  p.payload[p.length-1];
  46       return os;
  47     }
  48 };
  49 
  50 // Extensions to packetT
  51 template<>
  52 class scv_extensions<packetT> : public scv_extensions_base<packetT> {
  53 public:
  54   scv_extensions< sc_uint<16>       > src;
  55   scv_extensions< sc_uint<16>       > dest;
  56   scv_extensions< sc_uint<16>       > length;
  57   scv_extensions< sc_uint<16>[1024] > payload;
  58   SCV_EXTENSIONS_CTOR(packetT) {
  59     //must be in order
  60     SCV_FIELD(src);
  61     SCV_FIELD(dest);
  62     SCV_FIELD(length);
  63     SCV_FIELD(payload);
  64   }
  65 };
  66 
  67 SC_MODULE(sctop) {
  68   SC_CTOR(sctop);
  69 };
  70 
  71 sctop::sctop(sc_module_name name) : sc_module(name)
  72 {
  73   // Create a sparse packet array
  74   packetT defaultPacket;
  75   sc_int<64> upper_bound;
  76   upper_bound = ( ( (long long) 1 ) << 63 ) - 1;
  77   const sc_int<64> lower_bound = -(upper_bound+1);
  78   scv_sparse_array< sc_int<64>, packetT >
  79     packets("packets", defaultPacket,
  80             lower_bound, upper_bound);
  81   // Create an index to the sparse packet array
  82   scv_smart_ptr< sc_int<64> > index;
  83   const sc_int<64> low = sc_int<64>(-1e3);
  84   const sc_int<64> high = sc_int<64>(-1e2);
  85   index->keep_only(low, high);  // Only 901 possible values
  86   // Create packets and copy into array
  87   scv_smart_ptr<packetT> packet;
  88   packet->length.keep_only(10,1024);
  89   for (unsigned int i=0; i<10; ++i) {
  90     packet->src.next();
  91     packet->dest.next();
  92     packet->length.next();
  93     for(unsigned int j=0; j<packet->length; j++) {
  94       packet->payload[j].next();
  95     }
  96     index->next();
  97     packets[index->read()] = *packet;  // Uses equal operator
  98   }
  99   // Iterate through the range looking for packets in the
 100   // sparse array
 101   const unsigned int packetsPerLine = 50;
 102   unsigned int count = 0;
 103   for (sc_int<64> i=low; i<=high; i++) {
 104     if (count == 0) {
 105       scv_out << i << ": ";
 106     }
 107     if (packets[i] == defaultPacket) { // uses packetT == operator
 108       scv_out << ".";
 109     } else {
 110       scv_out << "*";
 111     }
 112     if (++count == packetsPerLine) {
 113       scv_out << endl;
 114       count = 0;
 115     }
 116   }
 117   // Iterate through again, this time printing each packet
 118   scv_out << endl << endl;
 119   for (sc_int<64> i=low; i<=high; i++) {
 120     if (packets[i]  ! = defaultPacket) { // uses packetT == operator
 121       // Uses output operator
 122       scv_out <<  i << ": " << packets[i] << endl;
 123     }
 124   }
 125   scv_out << endl;
 126 }
 127 
 128 int sc_main(int argc, char** argv) {
 129   sctop top("top"); 
 130   sc_start();
 131   return 0;
 132 }
You could download file scv_sparse_array.cpp here
   

space.gif

  ../images/main/bulllet_4dots_orange.gif Simulation Output : sparse_array
   

space.gif

 -1000: ..................................................
 -950: ..................................................
 -900: ..*...............................................
 -850: ..................................................
 -800: ..................................................
 -750: ...................*..............................
 -700: ..................................................
 -650: ..................................................
 -600: ...*..............................................
 -550: .........................................*..*.....
 -500: ..................................................
 -450: ................*.................................
 -400: ..................................................
 -350: ..................................................
 -300: ...............*..........*.......................
 -250: ...*..............................................
 -200: ..................................................
 -150: ..............................*...................
 -100: .
 
 -898:   src: 30647  dest: 53470  length: 645  payload: 61322 .. 62578
 -731:   src: 39872  dest: 21287  length: 683  payload: 35080 .. 11127
 -597:   src: 62834  dest: 2159  length: 269  payload: 5185 .. 59927
 -509:   src: 52136  dest: 10724  length: 503  payload: 65374 .. 26834
 -506:   src: 6141  dest: 31750  length: 497  payload: 2051 .. 42399
 -434:   src: 44323  dest: 53372  length: 642  payload: 5639 .. 64545
 -285:   src: 62314  dest: 20677  length: 720  payload: 5151 .. 41977
 -274:   src: 43723  dest: 10721  length: 957  payload: 50179 .. 15361
 -247:   src: 4870  dest: 558  length: 880  payload: 28238 .. 18869
 -120:   src: 46226  dest: 10373  length: 872  payload: 20120 .. 35604
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com