* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: VCache.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* ========== Copyright Header End ============================================
#ifndef INCLUDED_VALUECACHE_H
#define INCLUDED_VALUECACHE_H
VCEntry() : valid( false ), counter( 0 )
void invalidate() { valid
= false; }
void incCounter() { ++counter
; }
bool hit( uint64_t v
) { ++counter
; return valid
&& value
== v
; }
void insert( uint64_t d
) { value
= d
; valid
= true; counter
= 1; }
class InvalidIndexException
{
InvalidIndexException( int i
) : idx( i
)
enum { VALUE_NOT_FOUND
= -1 };
VCache( unsigned size
= 65535 ) : evictions(0), vcacheSize(size
)
cache
= new VCEntry
[vcacheSize
];
for( IdxT i
= 0; i
< vcacheSize
; ++i
){
bool hit( uint64_t d
, IdxT
&idx
)
return cache
[idx
].hit( d
);
// compatability w/ existing code
IdxT
insert( uint64_t d
)
//return (d ^ (d & 0x0FUL)) % vcacheSize;
return (IdxT
)(d
% vcacheSize
);
uint64_t operator[](IdxT idx
)
assert( idx
>= 0 && idx
< vcacheSize
);
if ( !cache
[idx
].valid
) {
throw InvalidIndexException( idx
);
int conflicts(){ return evictions
; }
#endif /* INCLUDED_VALUECACHE_H */