OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [bench/] [sysc/] [src/] [MemCache.cpp] - Blame information for rev 194

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 63 julius
// ----------------------------------------------------------------------------
2
 
3
// Debug Unit memory cache: implementation
4
 
5
// Copyright (C) 2008  Embecosm Limited <info@embecosm.com>
6
 
7
// Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
// This file is part of the GDB interface to the cycle accurate model of the
10
// OpenRISC 1000 based system-on-chip, ORPSoC, built using Verilator.
11
 
12
// This program is free software: you can redistribute it and/or modify it
13
// under the terms of the GNU Lesser General Public License as published by
14
// the Free Software Foundation, either version 3 of the License, or (at your
15
// option) any later version.
16
 
17
// This program is distributed in the hope that it will be useful, but WITHOUT
18
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
20
// License for more details.
21
 
22
// You should have received a copy of the GNU Lesser General Public License
23
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 
25
// ----------------------------------------------------------------------------
26
 
27
// $Id: MemCache.cpp 326 2009-03-07 16:47:31Z jeremy $
28
 
29
#include <cstring>
30
 
31
#include "MemCache.h"
32
 
33
 
34
//! Constructor
35
 
36
//! Allocate a closed hash table of the specified size and clear it.
37
 
38
//! @param[in] _tableSize  The desire hash table size. A prime number is
39
//!                         recommended.
40
 
41
MemCache::MemCache (int  _tableSize) :
42
  tableSize (_tableSize)
43
{
44
  tabIsValid = new bool [tableSize];
45
  tabKeyAddr = new uint32_t [tableSize];
46
  tabValue   = new uint32_t [tableSize];
47
 
48
  clear ();
49
 
50
}       // MemCache ()
51
 
52
 
53
//! Destructor
54
 
55
//! Free the hash table arrays
56
 
57
MemCache::~MemCache ()
58
{
59
  delete [] tabIsValid;
60
  delete [] tabKeyAddr;
61
  delete [] tabValue;
62
 
63
}       // ~MemCache ()
64
 
65
 
66
//! Empty the hash table
67
 
68
//! Only need to worry about the validity field
69
void
70
MemCache::clear ()
71
{
72
  memset (tabIsValid, false, sizeof (tabIsValid));
73
 
74
}       // clear ()
75
 
76
 
77
//! Write a new value into the hash table
78
 
79
//! Will trash anything already there.
80
 
81
//! @param[in] addr   The address being written to
82
//! @param[in] value  The value to write
83
void
84
MemCache::write (uint32_t  addr,
85
                 uint32_t  value)
86
{
87
  int  keyAddr = addr % tableSize;
88
 
89
  tabIsValid[keyAddr] = true;
90
  tabKeyAddr[keyAddr] = addr;
91
  tabValue[keyAddr]   = value;
92
 
93
}       // write ()
94
 
95
 
96
//! Try to read a value from the hash table
97
 
98
//! The entry must be valid and the address must match
99
 
100
//! @param[in]  addr   The address being read from
101
//! @param[out] value  The value read, if there was one there
102
 
103
//! @return  True if the value was found in the hash table
104
 
105
bool
106
MemCache::read (uint32_t  addr,
107
                uint32_t &value)
108
{
109
  int  keyAddr = addr % tableSize;
110
 
111
  if (tabIsValid[keyAddr] & (tabKeyAddr[keyAddr] == addr))
112
    {
113
      value = tabValue[keyAddr];
114
      return  true;
115
    }
116
  else
117
    {
118
      return  false;
119
    }
120
}       // read ()

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.