gem5  v22.1.0.0
utility.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 ARM Limited
3  * Copyright (c) 2014-2015 Sven Karlsson
4  * Copyright (c) 2018 TU Dresden
5  * Copyright (c) 2020 Barkhausen Institut
6  * All rights reserved
7  *
8  * The license below extends only to copyright in the software and shall
9  * not be construed as granting a license to any other intellectual
10  * property including but not limited to intellectual property relating
11  * to a hardware implementation of the functionality of the software
12  * licensed hereunder. You may use the software subject to the license
13  * terms below provided that you ensure that this notice is replicated
14  * unmodified and in its entirety in all distributions of the software,
15  * modified or unmodified, in source code or in binary form.
16  *
17  * Copyright (c) 2016-2017 The University of Virginia
18  * All rights reserved.
19  *
20  * Redistribution and use in source and binary forms, with or without
21  * modification, are permitted provided that the following conditions are
22  * met: redistributions of source code must retain the above copyright
23  * notice, this list of conditions and the following disclaimer;
24  * redistributions in binary form must reproduce the above copyright
25  * notice, this list of conditions and the following disclaimer in the
26  * documentation and/or other materials provided with the distribution;
27  * neither the name of the copyright holders nor the names of its
28  * contributors may be used to endorse or promote products derived from
29  * this software without specific prior written permission.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  */
43 
44 #ifndef __ARCH_RISCV_UTILITY_HH__
45 #define __ARCH_RISCV_UTILITY_HH__
46 
47 #include <cmath>
48 #include <cstdint>
49 #include <sstream>
50 #include <string>
51 
52 #include "arch/riscv/regs/float.hh"
53 #include "arch/riscv/regs/int.hh"
54 #include "base/types.hh"
55 #include "cpu/reg_class.hh"
56 #include "cpu/static_inst.hh"
57 #include "cpu/thread_context.hh"
58 #include "rvk.hh"
59 
60 namespace gem5
61 {
62 
63 namespace RiscvISA
64 {
65 
66 template<typename T> inline bool
68 {
69  return false;
70 }
71 
72 template<> inline bool
74 {
75  return std::isnan(val)
76  && (reinterpret_cast<uint32_t&>(val)&0x00400000);
77 }
78 
79 template<> inline bool
80 isquietnan<double>(double val)
81 {
82  return std::isnan(val)
83  && (reinterpret_cast<uint64_t&>(val)&0x0008000000000000ULL);
84 }
85 
86 template<typename T> inline bool
88 {
89  return false;
90 }
91 
92 template<> inline bool
94 {
95  return std::isnan(val)
96  && (reinterpret_cast<uint32_t&>(val)&0x00200000);
97 }
98 
99 template<> inline bool
101 {
102  return std::isnan(val)
103  && (reinterpret_cast<uint64_t&>(val)&0x0004000000000000ULL);
104 }
105 
106 inline std::string
108 {
109  if (reg.is(IntRegClass)) {
110  if (reg.index() >= int_reg::NumArchRegs) {
111  /*
112  * This should only happen if a instruction is being speculatively
113  * executed along a not-taken branch, and if that instruction's
114  * width was incorrectly predecoded (i.e., it was predecoded as a
115  * full instruction rather than a compressed one or vice versa).
116  * It also should only happen if a debug flag is on that prints
117  * disassembly information, so rather than panic the incorrect
118  * value is printed for debugging help.
119  */
120  std::stringstream str;
121  str << "?? (x" << reg.index() << ')';
122  return str.str();
123  }
124  return int_reg::RegNames[reg.index()];
125  } else if (reg.is(FloatRegClass)) {
126  if (reg.index() >= float_reg::NumRegs) {
127  std::stringstream str;
128  str << "?? (f" << reg.index() << ')';
129  return str.str();
130  }
131  return float_reg::RegNames[reg.index()];
132  } else {
133  /* It must be an InvalidRegClass, in RISC-V we should treat it as a
134  * zero register for the disassembler to work correctly.
135  */
136  return int_reg::RegNames[reg.index()];
137  }
138 }
139 
140 } // namespace RiscvISA
141 } // namespace gem5
142 
143 #endif // __ARCH_RISCV_UTILITY_HH__
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Register ID: describe an architectural register with its class and index.
Definition: reg_class.hh:91
const std::vector< std::string > RegNames
Definition: float.hh:201
const std::vector< std::string > RegNames
Definition: int.hh:125
bool issignalingnan< double >(double val)
Definition: utility.hh:100
bool isquietnan< double >(double val)
Definition: utility.hh:80
bool issignalingnan(T val)
Definition: utility.hh:87
bool isquietnan< float >(float val)
Definition: utility.hh:73
std::string registerName(RegId reg)
Definition: utility.hh:107
bool issignalingnan< float >(float val)
Definition: utility.hh:93
bool isquietnan(T val)
Definition: utility.hh:67
Bitfield< 5, 3 > reg
Definition: types.hh:92
Bitfield< 63 > val
Definition: misc.hh:776
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
@ FloatRegClass
Floating-point register.
Definition: reg_class.hh:61
@ IntRegClass
Integer register.
Definition: reg_class.hh:60

Generated on Wed Dec 21 2022 10:22:27 for gem5 by doxygen 1.9.1