SyoSil ApS UVM Scoreboard  1.0.3.0
cl_syoscb_hash_aa_wrapper.svh
1 /// A wrapper around an associative array, used for storing hash queues.
2 /// Supports all of the same functions that an ordinary AA supports
3 class cl_syoscb_hash_aa_wrapper #(int unsigned HASH_DIGEST_WIDTH = 1) extends uvm_object;
4  ///Typedef for hash algorithm digests
5  typedef cl_syoscb_hash_base#(HASH_DIGEST_WIDTH)::tp_hash_digest tp_digest;
6 
7  //-------------------------------------
8  // Non randomizable variables
9  //-------------------------------------
10  ///Queue implemented as assoc array
12 
13  //-------------------------------------
14  // UVM Macros
15  //-------------------------------------
16  `uvm_object_param_utils_begin(cl_syoscb_hash_aa_wrapper#(HASH_DIGEST_WIDTH))
17  // No Macro exists for assoc arrays with user defined keys
18  `uvm_object_utils_end
19 
20  //-------------------------------------
21  // Constructor
22  //-------------------------------------
23  function new(string name = "cl_syoscb_hash_aa_wrapper");
24  super.new(name);
25  endfunction: new
26 
27  //-------------------------------------
28  // Functions
29  //-------------------------------------
30  extern function int size();
31  extern function int get_size(tp_digest digest);
32  extern function void insert(tp_digest digest, cl_syoscb_item item);
33  extern function cl_syoscb_item get_item(tp_digest digest, int unsigned idx = 0);
34  extern function cl_syoscb_hash_item get_hash_item(tp_digest digest);
35  extern function void delete(tp_digest digest, int unsigned idx = 0);
36  extern function void delete_all();
37  extern function bit exists(tp_digest digest);
38  extern function bit first(ref tp_digest digest);
39  extern function bit last(ref tp_digest digest);
40  extern function bit next(ref tp_digest digest);
41  extern function bit prev(ref tp_digest digest);
42 
43  extern function void do_print(uvm_printer printer);
44  extern function bit do_compare(uvm_object rhs, uvm_comparer comparer);
45 
47 
48 
49 
50 /// Returns the size (number of entries) in the wrapped assoc array
51 /// \note This does not necessarily match the size of the contained queue,
52 /// as a hash item may have multiple entries
54  return this.hash.size();
55 endfunction: size
56 
57 /// Return the size of a hash item in the wrapped assoc array
58 /// \param digest The digest of the hash item to retrieve
59 /// \return The size of that hash item, 0 if none exists
61  if(this.hash.exists(digest)) begin
62  return this.hash[digest].get_size();
63  end
64  return 0;
65 endfunction: get_size
66 
67 /// Inserts an item into the wrapped assoc array.
68 /// \param digest The hash digest of the item to insert
69 /// \param item The item to insert
71  if(!this.hash.exists(digest)) begin
72  cl_syoscb_hash_item hash_item;
73  hash_item = cl_syoscb_hash_item::type_id::create($sformatf("hash-item-%s",digest));
74  this.hash[digest] = hash_item;
75  end
76  this.hash[digest].add_item(item);
77 endfunction: insert
78 
79 ///Gets a hash item in the wrapped assoc array
80 /// \param digest The hash digest of the item to get
81 /// \return The hash item at that digest, or null if none exists
83  if(this.hash.exists(digest)) begin
84  return this.hash[digest];
85  end
86  return null;
87 endfunction: get_hash_item
88 
89 /// Gets the scoreboard item at an index with a given hash value
90 /// \param digest The hash value of the item to get
91 /// \param idx The index in the hash item. Defaults to 0.
92 /// \return That item, or null if no item with that hash exists or idx was too large
93 function cl_syoscb_item cl_syoscb_hash_aa_wrapper::get_item(tp_digest digest, int unsigned idx = 0);
94  if(this.hash.exists(digest)) begin
95  return this.hash[digest].get_item(idx);
96  end
97  return null;
98 endfunction: get_item
99 
100 /// Deletes a sequence item with a given hash value
101 /// \param digest The hash digest of the item to delete
102 /// \param idx The index in the hash item of the sequence item to delete. Defaults to 0.
103 function void cl_syoscb_hash_aa_wrapper::delete(tp_digest digest, int unsigned idx = 0);
104  this.hash[digest].delete_item(idx);
105  ///Must remove to avoid iterating over empty hash items
106  if(this.hash[digest].get_size() == 0) begin
107  this.hash.delete(digest);
108  end
109 endfunction: delete
110 
111 /// Deletes all items in the assoc array
113  this.hash.delete();
114 endfunction: delete_all
115 
116 /// Checks if an entry exists with the given hash value
117 /// \param digest The hash value to check for
118 /// \return 1 if an item with that hash exists, 0 otherwise
120  return this.hash.exists(digest);
121 endfunction: exists
122 
123 /// Retrieves the hash of the first item in the wrapped AA
124 /// The first item is not necessarily the item first inserted, but the item
125 /// that comes first "alphabetically"
126 /// \param digest A reference to a digest, where the digest of the first entry is returned
127 /// \return 1 if the digest is valid, 0 otherwise
129  return this.hash.first(digest);
130 endfunction: first
131 
132 /// Retrieves the hash of the last item in the wrapped AA
133 /// The last item is not necessarily the item last inserted, but the item
134 /// that comes last "alphabetically"
135 /// \param digest A reference to a digest, where the digest of the last entry is returned
136 /// \return 1 if the digest is valid, 0 otherwise
138  return this.hash.last(digest);
139 endfunction: last
140 
141 /// Retrieves the hash of the next item in the wrapped AA
142 /// The first item is not necessarily the next item in insertion order,
143 /// but the item that comes next "alphabetically"
144 /// \param digest A reference to the digest of the current value. The digest of the next entry is returned here
145 /// \return 1 if the digest is valid, 0 otherwise
147  return this.hash.next(digest);
148 endfunction: next
149 
150 /// Retrieves the hash of the previous item in the wrapped AA
151 /// The previous item is not necessarily the previous item in insertion order,
152 /// but the prevoius item "alphabetically"
153 /// \param digest A reference to the digest of the current value. The digest of the previous entry is returned here
154 /// \return 1 if the digest is valid, 0 otherwise
156  return this.hash.prev(digest);
157 endfunction: prev
158 
159 
160 // Implements do_print for the hash AA to print all items contained in it
161 function void cl_syoscb_hash_aa_wrapper::do_print(uvm_printer printer);
162  tp_digest digest;
163  int unsigned idx;
164 
165  if(this.hash.first(digest)) begin
166  printer.print_generic("hash", "-", this.hash.size(), "-");
167  do begin
168  printer.print_object(.name($sformatf("hash[%0d]", idx)), .value(this.hash[digest]));
169  idx++;
170  end while(this.hash.next(digest));
171  end
172 endfunction: do_print
173 
174 //Implements do_compare to verify if two hash AA's have the same contents
175 function bit cl_syoscb_hash_aa_wrapper::do_compare(uvm_object rhs, uvm_comparer comparer);
176  cl_syoscb_hash_aa_wrapper#(HASH_DIGEST_WIDTH) rhs_aa;
177  tp_digest digest;
178 
179  bit compare_result = super.do_compare(rhs, comparer);
180 
181  if(!$cast(rhs_aa, rhs)) begin
182  `uvm_fatal("TYPECAST", $sformatf("Unable to cast RHS to cl_syoscb_hash_aa_wrapper#(%0d), it is %0s", this.HASH_DIGEST_WIDTH, rhs.get_type_name()))
183  end
184  if(rhs_aa.size() != this.hash.size()) begin
185  return 0; //Uneven sizies, definitely not a match
186  end else begin
187  if(this.hash.first(digest)) begin
188  do begin
189  compare_result &= comparer.compare_object(
190  this.get_hash_item(digest).get_name(),
191  this.get_hash_item(digest),
192  rhs_aa.get_hash_item(digest));
193  end while(this.hash.next(digest));
194  end
195  end
196 endfunction: do_compare
int get_size(tp_digest digest)
Return the size of a hash item in the wrapped assoc array.
bit exists(tp_digest digest)
Checks if an entry exists with the given hash value.
The UVM scoreboard item which wraps uvm_sequence_item .
int size()
Returns the size (number of entries) in the wrapped assoc array.
bit next(ref tp_digest digest)
Retrieves the hash of the next item in the wrapped AA The first item is not necessarily the next item...
void insert(tp_digest digest, cl_syoscb_item item)
Inserts an item into the wrapped assoc array.
cl_syoscb_item get_item(tp_digest digest, int unsigned idx=0)
Gets the scoreboard item at an index with a given hash value.
void delete_all()
Deletes all items in the assoc array.
virtual void add_item(cl_syoscb_item item)
Item API: Adds an item to this hash item
cl_syoscb_hash_item get_hash_item(tp_digest digest)
Gets a hash item in the wrapped assoc array.
cl_syoscb_hash_item hash[tp_digest]
Queue implemented as assoc array.
bit first(ref tp_digest digest)
Retrieves the hash of the first item in the wrapped AA The first item is not necessarily the item fir...
bit prev(ref tp_digest digest)
Retrieves the hash of the previous item in the wrapped AA The previous item is not necessarily the pr...
virtual void delete_item(int unsigned idx=0)
Item API: Deletes an item from this hash item
Class which defines the base concept of a hash algorithm.
A wrapper around an associative array, used for storing hash queues.
void delete(tp_digest digest, int unsigned idx=0)
Deletes a sequence item with a given hash value.
bit last(ref tp_digest digest)
Retrieves the hash of the last item in the wrapped AA The last item is not necessarily the item last ...
A utility class used to wrap cl_syoscb_item objects when when using hash queues.
cl_syoscb_hash_base< HASH_DIGEST_WIDTH >::tp_hash_digest tp_digest
Typedef for hash algorithm digests.

Project: SyoSil ApS UVM Scoreboard, Revision: 1.0.3.0

Copyright 2014-2022 SyoSil ApS
All Rights Reserved Worldwide

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
doxygen
Doxygen Version: 1.8.14
Generated with IDV SV Filter Version: 2.6.3
Fri Sep 2 2022 14:39:11
Find a documentation bug? Report bugs to: scoreboard@syosil.com