gem5 v24.0.0.0
Loading...
Searching...
No Matches
regfile.hh
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google, Inc.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met: redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer;
8 * redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution;
11 * neither the name of the copyright holders nor the names of its
12 * contributors may be used to endorse or promote products derived from
13 * this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef __CPU_REGFILE_HH__
29#define __CPU_REGFILE_HH__
30
31#include <algorithm>
32#include <cassert>
33#include <cstring>
34#include <vector>
35
36#include "cpu/reg_class.hh"
37
38namespace gem5
39{
40
42{
43 private:
45 const size_t _size;
46 const size_t _regShift;
47 const size_t _regBytes;
48
49 public:
51
52 RegFile(const RegClass &info, const size_t new_size) :
53 data(new_size << info.regShift()), _size(new_size),
54 _regShift(info.regShift()), _regBytes(info.regBytes()),
55 regClass(info)
56 {}
57
58 RegFile(const RegClass &info) : RegFile(info, info.numRegs()) {}
59
60 size_t size() const { return _size; }
61 size_t regShift() const { return _regShift; }
62 size_t regBytes() const { return _regBytes; }
63
64 template <typename Reg=RegVal>
65 Reg &
66 reg(size_t idx)
67 {
68 assert(sizeof(Reg) == _regBytes && idx < _size);
69 return *reinterpret_cast<Reg *>(data.data() + (idx << _regShift));
70 }
71 template <typename Reg=RegVal>
72 const Reg &
73 reg(size_t idx) const
74 {
75 assert(sizeof(Reg) == _regBytes && idx < _size);
76 return *reinterpret_cast<const Reg *>(
77 data.data() + (idx << _regShift));
78 }
79
80 void *
81 ptr(size_t idx)
82 {
83 return data.data() + (idx << _regShift);
84 }
85
86 const void *
87 ptr(size_t idx) const
88 {
89 return data.data() + (idx << _regShift);
90 }
91
92 void
93 get(size_t idx, void *val) const
94 {
95 std::memcpy(val, ptr(idx), _regBytes);
96 }
97
98 void
99 set(size_t idx, const void *val)
100 {
101 std::memcpy(ptr(idx), val, _regBytes);
102 }
103
104 void clear() { std::fill(data.begin(), data.end(), 0); }
105};
106
107} // namespace gem5
108
109#endif // __CPU_REGFILE_HH__
size_t regShift() const
Definition regfile.hh:61
void set(size_t idx, const void *val)
Definition regfile.hh:99
void get(size_t idx, void *val) const
Definition regfile.hh:93
void * ptr(size_t idx)
Definition regfile.hh:81
const size_t _regBytes
Definition regfile.hh:47
RegFile(const RegClass &info)
Definition regfile.hh:58
RegFile(const RegClass &info, const size_t new_size)
Definition regfile.hh:52
size_t size() const
Definition regfile.hh:60
const Reg & reg(size_t idx) const
Definition regfile.hh:73
void clear()
Definition regfile.hh:104
std::vector< uint8_t > data
Definition regfile.hh:44
size_t regBytes() const
Definition regfile.hh:62
Reg & reg(size_t idx)
Definition regfile.hh:66
const size_t _size
Definition regfile.hh:45
const RegClass & regClass
Definition regfile.hh:50
const void * ptr(size_t idx) const
Definition regfile.hh:87
const size_t _regShift
Definition regfile.hh:46
STL vector class.
Definition stl.hh:37
Bitfield< 63 > val
Definition misc.hh:804
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36

Generated on Tue Jun 18 2024 16:24:02 for gem5 by doxygen 1.11.0