gem5  v22.0.0.2
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 
38 namespace gem5
39 {
40 
41 class RegFile
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__
gem5::MipsISA::fill
fill
Definition: pra_constants.hh:57
gem5::RegFile::_regBytes
const size_t _regBytes
Definition: regfile.hh:47
gem5::RegFile::ptr
void * ptr(size_t idx)
Definition: regfile.hh:81
gem5::RegFile::RegFile
RegFile(const RegClass &info)
Definition: regfile.hh:58
gem5::X86ISA::val
Bitfield< 63 > val
Definition: misc.hh:769
gem5::RegFile::get
void get(size_t idx, void *val) const
Definition: regfile.hh:93
std::vector< uint8_t >
gem5::copy_engine_reg::Reg
Definition: copy_engine_defs.hh:100
gem5::RegFile::RegFile
RegFile(const RegClass &info, const size_t new_size)
Definition: regfile.hh:52
gem5::RegFile::ptr
const void * ptr(size_t idx) const
Definition: regfile.hh:87
gem5::RegFile::regShift
size_t regShift() const
Definition: regfile.hh:61
gem5::RegFile
Definition: regfile.hh:41
gem5::RegFile::clear
void clear()
Definition: regfile.hh:104
gem5::RegFile::reg
Reg & reg(size_t idx)
Definition: regfile.hh:66
gem5::RegFile::regClass
const RegClass & regClass
Definition: regfile.hh:50
gem5::RegFile::reg
const Reg & reg(size_t idx) const
Definition: regfile.hh:73
gem5::RegClass
Definition: reg_class.hh:81
gem5::RegFile::regBytes
size_t regBytes() const
Definition: regfile.hh:62
gem5::RegFile::data
std::vector< uint8_t > data
Definition: regfile.hh:44
reg_class.hh
gem5::RegFile::set
void set(size_t idx, const void *val)
Definition: regfile.hh:99
gem5::RegFile::_size
const size_t _size
Definition: regfile.hh:45
gem5::RegFile::size
size_t size() const
Definition: regfile.hh:60
gem5::RegFile::_regShift
const size_t _regShift
Definition: regfile.hh:46
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37

Generated on Thu Jul 28 2022 13:32:28 for gem5 by doxygen 1.8.17