Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / verif / env / fnx / vlib / XactorComponents / src / XactorHash.vr
CommitLineData
86530b38
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: XactorHash.vr
4// Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
5// 4150 Network Circle, Santa Clara, California 95054, U.S.A.
6//
7// * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8//
9// This program is free software; you can redistribute it and/or modify
10// it under the terms of the GNU General Public License as published by
11// the Free Software Foundation; version 2 of the License.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21//
22// For the avoidance of doubt, and except that if any non-GPL license
23// choice is available it will apply instead, Sun elects to use only
24// the General Public License version 2 (GPLv2) at this time for any
25// software where a choice of GPL license versions is made
26// available with the language indicating that GPLv2 or any later version
27// may be used, or where a choice of which version of the GPL is applied is
28// otherwise unspecified.
29//
30// Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
31// CA 95054 USA or visit www.sun.com if you need additional information or
32// have any questions.
33//
34// ========== Copyright Header End ============================================
35#include <vera_defines.vrh>
36#include "XactorBinTree.vrh"
37#include "XactorList.vrh"
38#include "XactorUtilities.vrh"
39
40#include "XactorBasePacket.vrh"
41#include "XactorBaseExpectDataStruct.vrh"
42#include "XactorBaseBuilder.vrh"
43#include "XactorDefines.vri"
44
45// Entries in the Hash Table
46#define XACT_CAM_ENTRIES 9
47
48typedef class XactorHash;
49
50class XactorHash extends XactorBaseExpectDataStruct {
51
52// bit [3:0] ai[4];
53
54 // Hash Data Structure. Each element could be any
55 // data structure with the interface defined in the
56 // XactorBaseExpectDataStruct base class.
57 XactorBaseExpectDataStruct Table[XACT_CAM_ENTRIES];
58
59
60 task new (XactorBaseBuilder Builder);
61
62 // Public method. Inserts a new node with the specified values.
63 virtual task Insert (XactorBasePacket Item,
64 var event e[XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS]
65 );
66
67 // Public method. Deletes a node with the specified values and returns
68 // Success = 1 if the node was found and deleted and Success = 0 otherwise.
69 virtual task Delete (XactorBasePacket Item,
70 var bit Success
71 );
72
73 // Deletes the node with the specified reference Item.
74 // Success = 1 if the node was found and deleted and Success = 0 otherwise.
75 virtual task RefDelete (XactorBasePacket Item,
76 var bit Success
77 );
78
79 // Public method.
80 virtual task WildCardDelete1 (XactorBasePacket Item,
81 var bit Success
82 );
83
84 // Public method. Will return the number of nodes in the hash data structure.
85 virtual function integer CountNodes();
86
87 // Public method. Returns 1 if Item is within the hash and
88 // 0 otherwise.
89 virtual function bit InStructure(XactorBasePacket Item);
90
91 // Public method. Prints all the nodes of the hash table.
92 // Each "compressed" expected value is decoded by
93 // a packet object. Once decoded, each field will be stored within the
94 // same packet and printed.
95 virtual task PrintNodes ();
96
97 // Public method. Returns 1 if the hash table is empty and 0 otherwise.
98 virtual function bit Empty();
99
100 // Public method. Triggers every node's remove event and then deletes the
101 // complete hash table
102 virtual task Reset();
103
104// virtual protected task GenerateHash();
105
106 // Local method. Returns an index based on the value of Item.
107 virtual protected function integer Hash (XactorBasePacket Item);
108
109}
110
111 ////////////////
112 // Definitions
113////////////////
114
115task XactorHash::new (XactorBaseBuilder Builder) {
116 integer Index;
117
118 for (Index=0; Index <= XACT_CAM_ENTRIES-1; ++Index)
119 Table[Index] = Builder.CreateHashElement();
120
121 // GenerateHash();
122}
123
124// Public method. Inserts a new node with the specified values.
125task XactorHash::Insert (XactorBasePacket Item,
126 var event e[XACT_EXPECT_DATA_STRUCT_REMOVE_EVENTS]
127 ) {
128
129 Table[Hash(Item)].Insert(Item, e);
130}
131
132// Public method. Deletes a node with the specified values and returns
133// Success = 1 if the node was found and deleted and Success = 0 otherwise.
134task XactorHash::Delete (XactorBasePacket Item,
135 var bit Success
136 ) {
137
138 Table[Hash(Item)].Delete(Item, Success);
139}
140
141// Deletes the node with the specified reference Item.
142// Success = 1 if the node was found and deleted and Success = 0 otherwise.
143task XactorHash::RefDelete (XactorBasePacket Item,
144 var bit Success
145 ) {
146
147 Table[Hash(Item)].RefDelete(Item, Success);
148}
149
150// Public method.
151task XactorHash::WildCardDelete1 (XactorBasePacket Item,
152 var bit Success
153 ) {
154 integer Index;
155 bit DeleteSuccess = 1'b0;
156
157 for (Index=0; Index <= XACT_CAM_ENTRIES-1; ++Index) {
158 Table[Index].WildCardDelete1(Item, DeleteSuccess);
159 if(DeleteSuccess)
160 Success = 1'b1;
161 }
162}
163
164// Public method. Will return the number of nodes in the hash data structure.
165function integer XactorHash::CountNodes() {
166
167 integer Index;
168 integer Counter = 0;
169
170 for (Index=0; Index <= XACT_CAM_ENTRIES-1; ++Index)
171 Counter = Counter + Table[Index].CountNodes();
172
173 CountNodes = Counter;
174}
175
176// Public method. Returns 1 if Item is within the hash and
177// 0 otherwise.
178function bit XactorHash::InStructure(XactorBasePacket Item) {
179 integer Result = 0;
180
181 if(Table[Hash(Item)].InStructure(Item) === 1'b1)
182 Result = 1;
183
184 InStructure = Result;
185}
186
187// Public method. Prints all the nodes of the hash table.
188// Each "compressed" expected value is decoded by
189// a packet object. Once decoded, each field will be stored within the
190// same packet and printed.
191task XactorHash::PrintNodes () {
192 integer Index;
193
194 for (Index=0; Index <= XACT_CAM_ENTRIES-1; ++Index) {
195 Table[Index].PrintNodes();
196 }
197}
198
199// Public method. Returns 1 if the hash table is empty and 0 otherwise.
200function bit XactorHash::Empty() {
201 integer Index = 0;
202 bit Result;
203
204 Result = 1'b1; // Assume empty
205 for(Index = 0; Index <= XACT_CAM_ENTRIES - 1; Index++) {
206 if(!Table[Index].Empty())
207 Result = 1'b0; // Not empty, since at least one element is not empty
208 }
209
210 Empty = Result;
211}
212
213// Public method. Triggers every node's remove event and then deletes the
214// complete hash table
215task XactorHash::Reset() {
216 integer Index;
217
218 for (Index=0; Index <= XACT_CAM_ENTRIES-1; ++Index) {
219 Table[Index].Reset();
220 }
221
222}
223
224// task XactorHash::GenerateHash() {
225// integer Index;
226//
227// for(Index=0; Index<=3; Index++) {
228// ai[Index] = random();
229// }
230// }
231
232// Local method. Returns an index based on the value of Item.
233function integer XactorHash::Hash (XactorBasePacket Item) {
234
235 // bit [63:0] a = 64'h0;
236 // integer Index;
237 // for(Index = 0; Index <= 3; Index++)
238 // a = a + ai[Index]*Item[(15-(Index*4)):((15-(Index*4))-3)];
239 // hash = a % XACT_CAM_ENTRIES;
240
241 Hash = Item.PktHash(XACT_CAM_ENTRIES);
242}
243
244