gem5  v21.1.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
inst_res.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2017 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef __CPU_INST_RES_HH__
39 #define __CPU_INST_RES_HH__
40 
41 #include <type_traits>
42 
43 #include "arch/generic/types.hh"
44 #include "arch/generic/vec_reg.hh"
45 
46 namespace gem5
47 {
48 
50 {
51  public:
53  {
54  uint64_t integer;
55  double dbl;
60  };
61 
62  enum class ResultType
63  {
64  Scalar,
65  VecElem,
66  VecReg,
67  VecPredReg,
69  Invalid
70  };
71 
72  private:
75 
76  public:
79  InstResult(const InstResult &) = default;
81  template<typename T>
82  explicit InstResult(T i, const ResultType& t) : type(t) {
83  static_assert(std::is_integral<T>::value ^
84  std::is_floating_point<T>::value,
85  "Parameter type is neither integral nor fp, or it is both");
86  if (std::is_integral<T>::value) {
87  result.integer = i;
88  } else if (std::is_floating_point<T>::value) {
89  result.dbl = i;
90  }
91  }
93  explicit InstResult(const TheISA::VecRegContainer& v, const ResultType& t)
94  : type(t) { result.vector = v; }
97  const ResultType& t)
98  : type(t) { result.pred = v; }
99 
101  type = that.type;
102  switch (type) {
103  /* Given that misc regs are not written to, there may be invalids in
104  * the result stack. */
105  case ResultType::Invalid:
106  break;
107  case ResultType::Scalar:
108  result.integer = that.result.integer;
109  break;
110  case ResultType::VecElem:
111  result.vecElem = that.result.vecElem;
112  break;
113  case ResultType::VecReg:
114  result.vector = that.result.vector;
115  break;
117  result.pred = that.result.pred;
118  break;
119 
120  default:
121  panic("Assigning result from unknown result type");
122  break;
123  }
124  return *this;
125  }
130  bool operator==(const InstResult& that) const {
131  if (this->type != that.type)
132  return false;
133  switch (type) {
134  case ResultType::Scalar:
135  return result.integer == that.result.integer;
136  case ResultType::VecElem:
137  return result.vecElem == that.result.vecElem;
138  case ResultType::VecReg:
139  return result.vector == that.result.vector;
141  return result.pred == that.result.pred;
142  case ResultType::Invalid:
143  return false;
144  default:
145  panic("Unknown type of result: %d\n", (int)type);
146  }
147  }
148 
149  bool operator!=(const InstResult& that) const {
150  return !operator==(that);
151  }
152 
156  bool isScalar() const { return type == ResultType::Scalar; }
158  bool isVector() const { return type == ResultType::VecReg; }
160  bool isVecElem() const { return type == ResultType::VecElem; }
162  bool isPred() const { return type == ResultType::VecPredReg; }
164  bool isValid() const { return type != ResultType::Invalid; }
169  const uint64_t&
170  asInteger() const
171  {
172  assert(isScalar());
173  return result.integer;
174  }
175 
180  const uint64_t&
182  {
183  return result.integer;
184  }
186  asVector() const
187  {
188  panic_if(!isVector(), "Converting scalar (or invalid) to vector!!");
189  return result.vector;
190  }
191  const TheISA::VecElem&
192  asVectorElem() const
193  {
194  panic_if(!isVecElem(), "Converting scalar (or invalid) to vector!!");
195  return result.vecElem;
196  }
197 
199  asPred() const
200  {
201  panic_if(!isPred(), "Converting scalar (or invalid) to predicate!!");
202  return result.pred;
203  }
204 
206 };
207 
208 } // namespace gem5
209 
210 #endif // __CPU_INST_RES_HH__
gem5::InstResult::InstResult
InstResult(const TheISA::VecPredRegContainer &v, const ResultType &t)
Predicate result.
Definition: inst_res.hh:96
gem5::InstResult::isVector
bool isVector() const
Is this a vector result?.
Definition: inst_res.hh:158
gem5::InstResult::ResultType::Invalid
@ Invalid
gem5::InstResult::MultiResult::dbl
double dbl
Definition: inst_res.hh:55
gem5::ArmISA::VecPredRegContainer
VecPredReg::Container VecPredRegContainer
Definition: vec.hh:68
gem5::InstResult::ResultType::NumResultTypes
@ NumResultTypes
gem5::MipsISA::Invalid
@ Invalid
Definition: float.hh:65
gem5::InstResult::ResultType::Scalar
@ Scalar
gem5::InstResult::isPred
bool isPred() const
Is this a predicate result?.
Definition: inst_res.hh:162
gem5::InstResult::operator!=
bool operator!=(const InstResult &that) const
Definition: inst_res.hh:149
gem5::InstResult::operator==
bool operator==(const InstResult &that) const
Result comparison Two invalid results always differ.
Definition: inst_res.hh:130
gem5::InstResult::isScalar
bool isScalar() const
Checks.
Definition: inst_res.hh:156
gem5::InstResult::InstResult
InstResult()
Default constructor creates an invalid result.
Definition: inst_res.hh:78
gem5::InstResult::asVectorElem
const TheISA::VecElem & asVectorElem() const
Definition: inst_res.hh:192
gem5::InstResult::result
MultiResult result
Definition: inst_res.hh:73
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::InstResult::MultiResult::vector
TheISA::VecRegContainer vector
Definition: inst_res.hh:56
gem5::InstResult::MultiResult::integer
uint64_t integer
Definition: inst_res.hh:54
gem5::InstResult::type
ResultType type
Definition: inst_res.hh:74
gem5::InstResult::MultiResult::vecElem
TheISA::VecElem vecElem
Definition: inst_res.hh:57
gem5::InstResult::isValid
bool isValid() const
Is this a valid result?.
Definition: inst_res.hh:164
gem5::ArmISA::v
Bitfield< 28 > v
Definition: misc_types.hh:54
gem5::InstResult::MultiResult::pred
TheISA::VecPredRegContainer pred
Definition: inst_res.hh:58
gem5::InstResult::MultiResult::MultiResult
MultiResult()
Definition: inst_res.hh:59
gem5::ArmISA::VecRegContainer
gem5::VecRegContainer< NumVecElemPerVecReg *sizeof(VecElem)> VecRegContainer
Definition: vec.hh:62
gem5::ArmISA::t
Bitfield< 5 > t
Definition: misc_types.hh:70
gem5::InstResult::ResultType::VecReg
@ VecReg
gem5::InstResult::ResultType::VecPredReg
@ VecPredReg
gem5::InstResult::asInteger
const uint64_t & asInteger() const
Explicit cast-like operations.
Definition: inst_res.hh:170
vec_reg.hh
gem5::InstResult::operator=
InstResult & operator=(const InstResult &that)
Definition: inst_res.hh:100
gem5::InstResult::ResultType::VecElem
@ VecElem
types.hh
gem5::InstResult::asPred
const TheISA::VecPredRegContainer & asPred() const
Definition: inst_res.hh:199
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:203
gem5::InstResult::ResultType
ResultType
Definition: inst_res.hh:62
gem5::InstResult::asIntegerNoAssert
const uint64_t & asIntegerNoAssert() const
Cast to integer without checking type.
Definition: inst_res.hh:181
gem5::ArmISA::VecElem
uint32_t VecElem
Definition: vec.hh:60
gem5::InstResult::asVector
const TheISA::VecRegContainer & asVector() const
Definition: inst_res.hh:186
gem5::InstResult::MultiResult
Definition: inst_res.hh:52
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::InstResult::isVecElem
bool isVecElem() const
Is this a vector element result?.
Definition: inst_res.hh:160
gem5::InstResult::InstResult
InstResult(T i, const ResultType &t)
Scalar result from scalar.
Definition: inst_res.hh:82
gem5::InstResult
Definition: inst_res.hh:49
gem5::InstResult::InstResult
InstResult(const TheISA::VecRegContainer &v, const ResultType &t)
Vector result.
Definition: inst_res.hh:93
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177

Generated on Wed Jul 28 2021 12:10:23 for gem5 by doxygen 1.8.17