gem5  v21.0.1.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 
47 {
48  public:
49  union MultiResult {
50  uint64_t integer;
51  double dbl;
56  };
57 
58  enum class ResultType {
59  Scalar,
60  VecElem,
61  VecReg,
62  VecPredReg,
64  Invalid
65  };
66 
67  private:
70 
71  public:
73  InstResult() : type(ResultType::Invalid) { }
74  InstResult(const InstResult &) = default;
76  template<typename T>
77  explicit InstResult(T i, const ResultType& t) : type(t) {
78  static_assert(std::is_integral<T>::value ^
79  std::is_floating_point<T>::value,
80  "Parameter type is neither integral nor fp, or it is both");
81  if (std::is_integral<T>::value) {
82  result.integer = i;
83  } else if (std::is_floating_point<T>::value) {
84  result.dbl = i;
85  }
86  }
88  explicit InstResult(const TheISA::VecRegContainer& v, const ResultType& t)
89  : type(t) { result.vector = v; }
92  const ResultType& t)
93  : type(t) { result.pred = v; }
94 
96  type = that.type;
97  switch (type) {
98  /* Given that misc regs are not written to, there may be invalids in
99  * the result stack. */
100  case ResultType::Invalid:
101  break;
102  case ResultType::Scalar:
103  result.integer = that.result.integer;
104  break;
105  case ResultType::VecElem:
106  result.vecElem = that.result.vecElem;
107  break;
108  case ResultType::VecReg:
109  result.vector = that.result.vector;
110  break;
112  result.pred = that.result.pred;
113  break;
114 
115  default:
116  panic("Assigning result from unknown result type");
117  break;
118  }
119  return *this;
120  }
125  bool operator==(const InstResult& that) const {
126  if (this->type != that.type)
127  return false;
128  switch (type) {
129  case ResultType::Scalar:
130  return result.integer == that.result.integer;
131  case ResultType::VecElem:
132  return result.vecElem == that.result.vecElem;
133  case ResultType::VecReg:
134  return result.vector == that.result.vector;
136  return result.pred == that.result.pred;
137  case ResultType::Invalid:
138  return false;
139  default:
140  panic("Unknown type of result: %d\n", (int)type);
141  }
142  }
143 
144  bool operator!=(const InstResult& that) const {
145  return !operator==(that);
146  }
147 
151  bool isScalar() const { return type == ResultType::Scalar; }
153  bool isVector() const { return type == ResultType::VecReg; }
155  bool isVecElem() const { return type == ResultType::VecElem; }
157  bool isPred() const { return type == ResultType::VecPredReg; }
159  bool isValid() const { return type != ResultType::Invalid; }
164  const uint64_t&
165  asInteger() const
166  {
167  assert(isScalar());
168  return result.integer;
169  }
170 
175  const uint64_t&
177  {
178  return result.integer;
179  }
181  asVector() const
182  {
183  panic_if(!isVector(), "Converting scalar (or invalid) to vector!!");
184  return result.vector;
185  }
186  const TheISA::VecElem&
187  asVectorElem() const
188  {
189  panic_if(!isVecElem(), "Converting scalar (or invalid) to vector!!");
190  return result.vecElem;
191  }
192 
194  asPred() const
195  {
196  panic_if(!isPred(), "Converting scalar (or invalid) to predicate!!");
197  return result.pred;
198  }
199 
201 };
202 
203 #endif // __CPU_INST_RES_HH__
InstResult
Definition: inst_res.hh:46
InstResult::asVector
const TheISA::VecRegContainer & asVector() const
Definition: inst_res.hh:181
InstResult::isScalar
bool isScalar() const
Checks.
Definition: inst_res.hh:151
InstResult::MultiResult::dbl
double dbl
Definition: inst_res.hh:51
InstResult::MultiResult::MultiResult
MultiResult()
Definition: inst_res.hh:55
ArmISA::VecRegContainer
VecReg::Container VecRegContainer
Definition: registers.hh:63
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
InstResult::ResultType::NumResultTypes
@ NumResultTypes
InstResult::ResultType::VecElem
@ VecElem
InstResult::MultiResult::pred
TheISA::VecPredRegContainer pred
Definition: inst_res.hh:54
ArmISA::VecPredRegContainer
VecPredReg::Container VecPredRegContainer
Definition: registers.hh:69
InstResult::InstResult
InstResult(T i, const ResultType &t)
Scalar result from scalar.
Definition: inst_res.hh:77
InstResult::ResultType::VecReg
@ VecReg
InstResult::isVecElem
bool isVecElem() const
Is this a vector element result?.
Definition: inst_res.hh:155
InstResult::MultiResult::vecElem
TheISA::VecElem vecElem
Definition: inst_res.hh:53
InstResult::result
MultiResult result
Definition: inst_res.hh:68
InstResult::ResultType
ResultType
Definition: inst_res.hh:58
ArmISA::VecElem
uint32_t VecElem
Definition: registers.hh:60
InstResult::isValid
bool isValid() const
Is this a valid result?.
Definition: inst_res.hh:159
InstResult::ResultType::Invalid
@ Invalid
InstResult::isPred
bool isPred() const
Is this a predicate result?.
Definition: inst_res.hh:157
InstResult::MultiResult::integer
uint64_t integer
Definition: inst_res.hh:50
InstResult::ResultType::Scalar
@ Scalar
InstResult::asIntegerNoAssert
const uint64_t & asIntegerNoAssert() const
Cast to integer without checking type.
Definition: inst_res.hh:176
InstResult::asInteger
const uint64_t & asInteger() const
Explicit cast-like operations.
Definition: inst_res.hh:165
InstResult::operator!=
bool operator!=(const InstResult &that) const
Definition: inst_res.hh:144
InstResult::InstResult
InstResult(const TheISA::VecPredRegContainer &v, const ResultType &t)
Predicate result.
Definition: inst_res.hh:91
InstResult::MultiResult::vector
TheISA::VecRegContainer vector
Definition: inst_res.hh:52
vec_reg.hh
types.hh
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:197
ArmISA::t
Bitfield< 5 > t
Definition: miscregs_types.hh:67
InstResult::ResultType::VecPredReg
@ VecPredReg
InstResult::operator=
InstResult & operator=(const InstResult &that)
Definition: inst_res.hh:95
InstResult::asPred
const TheISA::VecPredRegContainer & asPred() const
Definition: inst_res.hh:194
InstResult::operator==
bool operator==(const InstResult &that) const
Result comparison Two invalid results always differ.
Definition: inst_res.hh:125
InstResult::InstResult
InstResult()
Default constructor creates an invalid result.
Definition: inst_res.hh:73
InstResult::asVectorElem
const TheISA::VecElem & asVectorElem() const
Definition: inst_res.hh:187
InstResult::MultiResult
Definition: inst_res.hh:49
InstResult::isVector
bool isVector() const
Is this a vector result?.
Definition: inst_res.hh:153
InstResult::InstResult
InstResult(const TheISA::VecRegContainer &v, const ResultType &t)
Vector result.
Definition: inst_res.hh:88
ArmISA::v
Bitfield< 28 > v
Definition: miscregs_types.hh:51
InstResult::type
ResultType type
Definition: inst_res.hh:69
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171

Generated on Tue Jun 22 2021 15:28:26 for gem5 by doxygen 1.8.17