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

Subversion Repositories openrisc

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

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
//! Constructor
34
 
35
//! Allocate a closed hash table of the specified size and clear it.
36
 
37
//! @param[in] _tableSize  The desire hash table size. A prime number is
38
//!                         recommended.
39
 
40 462 julius
MemCache::MemCache(int _tableSize):tableSize(_tableSize)
41 63 julius
{
42 462 julius
        tabIsValid = new bool[tableSize];
43
        tabKeyAddr = new uint32_t[tableSize];
44
        tabValue = new uint32_t[tableSize];
45 63 julius
 
46 462 julius
        clear();
47 63 julius
 
48 462 julius
}                               // MemCache ()
49 63 julius
 
50
//! Destructor
51
 
52
//! Free the hash table arrays
53
 
54 462 julius
MemCache::~MemCache()
55 63 julius
{
56 462 julius
        delete[]tabIsValid;
57
        delete[]tabKeyAddr;
58
        delete[]tabValue;
59 63 julius
 
60 462 julius
}                               // ~MemCache ()
61 63 julius
 
62
//! Empty the hash table
63
 
64
//! Only need to worry about the validity field
65
void
66 462 julius
 MemCache::clear()
67 63 julius
{
68 462 julius
        memset(tabIsValid, false, sizeof(tabIsValid));
69 63 julius
 
70 462 julius
}                               // clear ()
71 63 julius
 
72
//! Write a new value into the hash table
73
 
74
//! Will trash anything already there.
75
 
76
//! @param[in] addr   The address being written to
77
//! @param[in] value  The value to write
78 462 julius
void MemCache::write(uint32_t addr, uint32_t value)
79 63 julius
{
80 462 julius
        int keyAddr = addr % tableSize;
81 63 julius
 
82 462 julius
        tabIsValid[keyAddr] = true;
83
        tabKeyAddr[keyAddr] = addr;
84
        tabValue[keyAddr] = value;
85 63 julius
 
86 462 julius
}                               // write ()
87 63 julius
 
88
//! Try to read a value from the hash table
89
 
90
//! The entry must be valid and the address must match
91
 
92
//! @param[in]  addr   The address being read from
93
//! @param[out] value  The value read, if there was one there
94
 
95
//! @return  True if the value was found in the hash table
96
 
97 462 julius
bool MemCache::read(uint32_t addr, uint32_t & value)
98 63 julius
{
99 462 julius
        int keyAddr = addr % tableSize;
100
 
101
        if (tabIsValid[keyAddr] & (tabKeyAddr[keyAddr] == addr)) {
102
                value = tabValue[keyAddr];
103
                return true;
104
        } else {
105
                return false;
106
        }
107
}                               // read ()

powered by: WebSVN 2.1.0

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