gem5  v19.0.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  * Authors: Nathanael Premillieu
38  */
39 
40 #ifndef __CPU_INST_RES_HH__
41 #define __CPU_INST_RES_HH__
42 
43 #include <type_traits>
44 
45 #include "arch/generic/types.hh"
46 #include "arch/generic/vec_reg.hh"
47 
48 class InstResult {
52  public:
53  union MultiResult {
54  uint64_t integer;
55  double dbl;
60  };
61 
62  enum class ResultType {
63  Scalar,
64  VecElem,
65  VecReg,
66  VecPredReg,
67  NumResultTypes,
68  Invalid
69  };
70 
71  private:
74 
75  public:
77  InstResult() : type(ResultType::Invalid) { }
78  InstResult(const InstResult &) = default;
80  template<typename T>
81  explicit InstResult(T i, const ResultType& t) : type(t) {
82  static_assert(std::is_integral<T>::value ^
83  std::is_floating_point<T>::value,
84  "Parameter type is neither integral nor fp, or it is both");
85  if (std::is_integral<T>::value) {
86  result.integer = i;
87  } else if (std::is_floating_point<T>::value) {
88  result.dbl = i;
89  }
90  }
92  explicit InstResult(const VecRegContainer& v, const ResultType& t)
93  : type(t) { result.vector = v; }
95  explicit InstResult(const VecPredRegContainer& v, const ResultType& t)
96  : type(t) { result.pred = v; }
97 
99  type = that.type;
100  switch (type) {
101  /* Given that misc regs are not written to, there may be invalids in
102  * the result stack. */
103  case ResultType::Invalid:
104  break;
105  case ResultType::Scalar:
106  result.integer = that.result.integer;
107  break;
108  case ResultType::VecElem:
109  result.vecElem = that.result.vecElem;
110  break;
111  case ResultType::VecReg:
112  result.vector = that.result.vector;
113  break;
115  result.pred = that.result.pred;
116  break;
117 
118  default:
119  panic("Assigning result from unknown result type");
120  break;
121  }
122  return *this;
123  }
128  bool operator==(const InstResult& that) const {
129  if (this->type != that.type)
130  return false;
131  switch (type) {
132  case ResultType::Scalar:
133  return result.integer == that.result.integer;
134  case ResultType::VecElem:
135  return result.vecElem == that.result.vecElem;
136  case ResultType::VecReg:
137  return result.vector == that.result.vector;
139  return result.pred == that.result.pred;
140  case ResultType::Invalid:
141  return false;
142  default:
143  panic("Unknown type of result: %d\n", (int)type);
144  }
145  }
146 
147  bool operator!=(const InstResult& that) const {
148  return !operator==(that);
149  }
150 
154  bool isScalar() const { return type == ResultType::Scalar; }
156  bool isVector() const { return type == ResultType::VecReg; }
158  bool isVecElem() const { return type == ResultType::VecElem; }
160  bool isPred() const { return type == ResultType::VecPredReg; }
162  bool isValid() const { return type != ResultType::Invalid; }
167  const uint64_t&
168  asInteger() const
169  {
170  assert(isScalar());
171  return result.integer;
172  }
173 
178  const uint64_t&
180  {
181  return result.integer;
182  }
183  const VecRegContainer&
184  asVector() const
185  {
186  panic_if(!isVector(), "Converting scalar (or invalid) to vector!!");
187  return result.vector;
188  }
189  const VecElem&
190  asVectorElem() const
191  {
192  panic_if(!isVecElem(), "Converting scalar (or invalid) to vector!!");
193  return result.vecElem;
194  }
195 
196  const VecPredRegContainer&
197  asPred() const
198  {
199  panic_if(!isPred(), "Converting scalar (or invalid) to predicate!!");
200  return result.pred;
201  }
202 
204 };
205 
206 #endif // __CPU_INST_RES_HH__
const uint64_t & asInteger() const
Explicit cast-like operations.
Definition: inst_res.hh:168
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:167
const VecElem & asVectorElem() const
Definition: inst_res.hh:190
Bitfield< 28 > v
Bitfield< 7 > i
Vector Register Abstraction This generic class is the model in a particularization of MVC...
Definition: vec_reg.hh:160
bool operator==(const InstResult &that) const
Result comparison Two invalid results always differ.
Definition: inst_res.hh:128
InstResult()
Default constructor creates an invalid result.
Definition: inst_res.hh:77
InstResult & operator=(const InstResult &that)
Definition: inst_res.hh:98
VecRegContainer vector
Definition: inst_res.hh:56
bool isVector() const
Is this a vector result?.
Definition: inst_res.hh:156
::DummyVecPredRegContainer VecPredRegContainer
Definition: registers.hh:60
::DummyVecRegContainer VecRegContainer
Definition: registers.hh:53
ResultType type
Definition: inst_res.hh:73
TheISA::VecElem VecElem
Definition: inst_res.hh:50
bool isScalar() const
Checks.
Definition: inst_res.hh:154
InstResult(const VecPredRegContainer &v, const ResultType &t)
Predicate result.
Definition: inst_res.hh:95
const VecRegContainer & asVector() const
Definition: inst_res.hh:184
InstResult(const VecRegContainer &v, const ResultType &t)
Vector result.
Definition: inst_res.hh:92
VecPredRegContainer pred
Definition: inst_res.hh:58
Vector Registers layout specification.
Generic predicate register container.
Definition: vec_pred_reg.hh:51
InstResult(T i, const ResultType &t)
Scalar result from scalar.
Definition: inst_res.hh:81
bool isVecElem() const
Is this a vector element result?.
Definition: inst_res.hh:158
::DummyVecElem VecElem
Definition: registers.hh:50
bool isValid() const
Is this a valid result?.
Definition: inst_res.hh:162
Bitfield< 5 > t
const VecPredRegContainer & asPred() const
Definition: inst_res.hh:197
bool isPred() const
Is this a predicate result?.
Definition: inst_res.hh:160
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:185
MultiResult result
Definition: inst_res.hh:72
bool operator!=(const InstResult &that) const
Definition: inst_res.hh:147
const uint64_t & asIntegerNoAssert() const
Cast to integer without checking type.
Definition: inst_res.hh:179

Generated on Fri Feb 28 2020 16:26:59 for gem5 by doxygen 1.8.13