gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vec_pred_reg.hh
Go to the documentation of this file.
1 // Copyright (c) 2017 ARM Limited
2 // All rights reserved
3 //
4 // The license below extends only to copyright in the software and shall
5 // not be construed as granting a license to any other intellectual
6 // property including but not limited to intellectual property relating
7 // to a hardware implementation of the functionality of the software
8 // licensed hereunder. You may use the software subject to the license
9 // terms below provided that you ensure that this notice is replicated
10 // unmodified and in its entirety in all distributions of the software,
11 // modified or unmodified, in source code or in binary form.
12 //
13 // Redistribution and use in source and binary forms, with or without
14 // modification, are permitted provided that the following conditions are
15 // met: redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer;
17 // redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution;
20 // neither the name of the copyright holders nor the names of its
21 // contributors may be used to endorse or promote products derived from
22 // this software without specific prior written permission.
23 //
24 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 //
36 // Authors: Giacomo Gabrielli
37 // Rekai Gonzalez
38 // Javier Setoain
39 
40 #ifndef __ARCH_GENERIC_VEC_PRED_REG_HH__
41 #define __ARCH_GENERIC_VEC_PRED_REG_HH__
42 
43 #include <array>
44 #include <cassert>
45 #include <vector>
46 
47 #include "arch/generic/vec_reg.hh"
48 #include "base/cprintf.hh"
49 
50 template <size_t NumBits, bool Packed>
52 
69 template <typename VecElem, size_t NumElems, bool Packed, bool Const>
71 {
72  protected:
74  static constexpr size_t NUM_BITS = Packed ? NumElems :
75  sizeof(VecElem) * NumElems;
76 
77  public:
79  using Container = typename std::conditional<
80  Const,
82  VecPredRegContainer<NUM_BITS, Packed>>::type;
83 
84  protected:
85  // Alias for this type
89 
90  public:
91  VecPredRegT(Container& c) : container(c) {}
92 
94  template<bool Condition = !Const>
96  reset() { container.reset(); }
97 
99  template<bool Condition = !Const>
101  set() { container.set(); }
102 
103  template<bool Condition = !Const>
105  operator=(const MyClass& that)
106  {
107  container = that.container;
108  return *this;
109  }
110 
111  const bool&
112  operator[](size_t idx) const
113  {
114  return container[idx * (Packed ? 1 : sizeof(VecElem))];
115  }
116 
117  template<bool Condition = !Const>
119  operator[](size_t idx)
120  {
121  return container[idx * (Packed ? 1 : sizeof(VecElem))];
122  }
123 
126  uint8_t
127  get_raw(size_t idx) const
128  {
129  return container.get_bits(idx * (Packed ? 1 : sizeof(VecElem)),
130  (Packed ? 1 : sizeof(VecElem)));
131  }
132 
134  template<bool Condition = !Const>
136  set_raw(size_t idx, uint8_t val)
137  {
138  container.set_bits(idx * (Packed ? 1 : sizeof(VecElem)),
139  (Packed ? 1 : sizeof(VecElem)), val);
140  }
141 
143  template<typename VE2, size_t NE2, bool P2, bool C2>
144  bool
146  {
147  return container == that.container;
148  }
149 
151  template<typename VE2, size_t NE2, bool P2, bool C2>
152  bool
154  {
155  return !operator==(that);
156  }
157 
158  friend std::ostream&
159  operator<<(std::ostream& os, const MyClass& p)
160  {
161  // 0-sized is not allowed
162  os << '[' << p.container[0];
163  for (int i = 0; i < p.NUM_BITS; ++i) {
164  os << " " << (p.container[i] ? 1 : 0);
165  }
166  os << ']';
167  return os;
168  }
169 
171  const std::string print() const { return csprintf("%s", *this); }
172 
177  template <bool MC>
178  bool
180  size_t actual_num_elems) const
181  {
182  assert(actual_num_elems <= NumElems);
183  for (int i = 0; i < actual_num_elems; ++i) {
184  if (mask[i]) {
185  return (*this)[i];
186  }
187  }
188  return false;
189  }
190 
195  template <bool MC>
196  bool
198  size_t actual_num_elems) const
199  {
200  assert(actual_num_elems <= NumElems);
201  for (int i = 0; i < actual_num_elems; ++i) {
202  if (mask[i] && operator[](i)) {
203  return false;
204  }
205  }
206  return true;
207  }
208 
213  template <bool MC>
214  bool
216  size_t actual_num_elems) const
217  {
218  assert(actual_num_elems <= NumElems);
219  for (int i = actual_num_elems - 1; i >= 0; --i) {
220  if (mask[i]) {
221  return operator[](i);
222  }
223  }
224  return false;
225  }
226 };
227 
234 template <size_t NumBits, bool Packed>
236 {
237  static_assert(NumBits > 0,
238  "Size of a predicate register must be > 0");
239 
240  public:
241  static constexpr size_t NUM_BITS = NumBits;
242  using Container = std::array<bool, NumBits>;
243 
244  private:
246  // Alias for this type
248 
249  public:
251  VecPredRegContainer(const VecPredRegContainer &) = default;
252 
253  MyClass&
254  operator=(const MyClass& that)
255  {
256  if (&that == this)
257  return *this;
258  container = that.container;
259  return *this;
260  }
261 
263  MyClass&
265  {
266  assert(that.size() == NUM_BITS);
267  std::copy(that.begin(), that.end(), container.begin());
268  return *this;
269  }
270 
272  void
274  {
275  container.fill(false);
276  }
277 
279  void
280  set()
281  {
282  container.fill(true);
283  }
284 
286  template<size_t N2, bool P2>
287  inline bool
289  {
290  return NumBits == N2 && Packed == P2 && container == that.container;
291  }
292 
294  template<size_t N2, bool P2>
295  bool
297  {
298  return !operator==(that);
299  }
300 
302  bool& operator[](size_t idx) { return container[idx]; }
303 
306  const bool& operator[](size_t idx) const { return container[idx]; }
307 
310  uint8_t
311  get_bits(size_t idx, uint8_t nbits) const
312  {
313  assert(nbits > 0 && nbits <= 8 && (idx + nbits - 1) < NumBits);
314  uint8_t v = 0;
315  idx = idx + nbits - 1;
316  for (int i = 0; i < nbits; ++i, --idx) {
317  v <<= 1;
318  v |= container[idx];
319  }
320  return v;
321  }
322 
325  void
326  set_bits(size_t idx, uint8_t nbits, uint8_t bval)
327  {
328  assert(nbits > 0 && nbits <= 8 && (idx + nbits - 1) < NumBits);
329  for (int i = 0; i < nbits; ++i, ++idx) {
330  container[idx] = bval & 1;
331  bval >>= 1;
332  }
333  }
334 
336  const std::string print() const { return csprintf("%s", *this); }
337 
338  friend std::ostream&
339  operator<<(std::ostream& os, const MyClass& v)
340  {
341  for (auto b: v.container) {
342  os << csprintf("%d", b);
343  }
344  return os;
345  }
346 
354  template <typename VecElem,
355  size_t NumElems = (Packed ? NumBits : NumBits / sizeof(VecElem))>
357  {
358  static_assert((Packed && NumElems <= NumBits) ||
359  (!Packed &&
360  NumBits % sizeof(VecElem) == 0 &&
361  sizeof(VecElem) * NumElems <= NumBits),
362  "Container size incompatible with view size");
364  }
365 
366  template <typename VecElem,
367  size_t NumElems = (Packed ? NumBits : NumBits / sizeof(VecElem))>
369  {
370  static_assert((Packed && NumElems <= NumBits) ||
371  (!Packed &&
372  NumBits % sizeof(VecElem) == 0 &&
373  sizeof(VecElem) * NumElems <= NumBits),
374  "Container size incompatible with view size");
376  }
378 };
379 
381 template <size_t NumBits, bool Packed>
382 inline bool
384 {
385  int i = 0;
386  for (const auto& c: value) {
387  p[i] = (c == '1');
388  }
389  return true;
390 }
391 
395 constexpr bool DummyVecPredRegHasPackedRepr = false;
402 constexpr size_t DummyVecPredRegSizeBits = 8;
404 
405 #endif // __ARCH_GENERIC_VEC_PRED_REG_HH__
void reset()
Resets the predicate register to an all-false register.
Bitfield< 28 > v
Bitfield< 7 > i
constexpr unsigned DummyNumVecElemPerVecReg
Definition: vec_reg.hh:664
bool noneActive(const VecPredRegT< VecElem, NumElems, Packed, MC > &mask, size_t actual_num_elems) const
Returns true if there are no active elements in the register.
friend std::ostream & operator<<(std::ostream &os, const MyClass &p)
constexpr bool DummyVecPredRegHasPackedRepr
Dummy type aliases and constants for architectures that do not implement vector predicate registers...
static constexpr size_t NUM_BITS
Size of the register in bits.
Definition: vec_pred_reg.hh:74
uint32_t DummyVecElem
Dummy type aliases and constants for architectures that do not implement vector registers.
Definition: vec_reg.hh:663
VecPredRegT(Container &c)
Definition: vec_pred_reg.hh:91
bool lastActive(const VecPredRegT< VecElem, NumElems, Packed, MC > &mask, size_t actual_num_elems) const
Returns true if the last active element of the register is true.
DummyVecPredReg::Container DummyVecPredRegContainer
constexpr size_t DummyVecPredRegSizeBits
uint8_t get_bits(size_t idx, uint8_t nbits) const
Returns a subset of bits starting from a specific element in the container.
Bitfield< 17 > os
Definition: misc.hh:805
MyClass & operator=(const MyClass &that)
Bitfield< 63 > val
Definition: misc.hh:771
std::enable_if< Condition, MyClass & >::type operator=(const MyClass &that)
Predicate register view.
Definition: vec_pred_reg.hh:70
Bitfield< 7 > b
void set_bits(size_t idx, uint8_t nbits, uint8_t bval)
Set a subset of bits starting from a specific element in the container.
uint8_t type
Definition: inet.hh:333
Container & container
Container corresponding to this view.
Definition: vec_pred_reg.hh:88
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:162
const std::string print() const
Returns a string representation of the register content.
::DummyVecPredRegContainer VecPredRegContainer
Definition: registers.hh:60
bool firstActive(const VecPredRegT< VecElem, NumElems, Packed, MC > &mask, size_t actual_num_elems) const
Returns true if the first active element of the register is true.
bool operator==(const VecPredRegT< VE2, NE2, P2, C2 > &that) const
Equality operator, required to compare thread contexts.
bool operator!=(const VecPredRegT< VE2, NE2, P2, C2 > &that) const
Inequality operator, required to compare thread contexts.
bool to_number(const std::string &value, VecPredRegContainer< NumBits, Packed > &p)
Helper functions used for serialization/de-serialization.
std::enable_if< Condition, bool & >::type operator[](size_t idx)
const bool & operator[](size_t idx) const
Returns a const reference to a specific element of the internal container.
VecPredRegT< VecElem, NumElems, Packed, true > as() const
Create a view of this container.
std::enable_if< Condition, void >::type set_raw(size_t idx, uint8_t val)
Write a raw value in an element of the predicate register.
MyClass & operator=(const std::vector< uint8_t > &that)
Required for de-serialization.
typename std::conditional< Const, const VecPredRegContainer< NUM_BITS, Packed >, VecPredRegContainer< NUM_BITS, Packed > >::type Container
Container type alias.
Definition: vec_pred_reg.hh:82
VecPredRegT< VecElem, NumElems, Packed, false > as()
const std::string print() const
Returns a string representation of the register content.
Bitfield< 29 > c
uint8_t get_raw(size_t idx) const
Return an element of the predicate register as it appears in the raw (untyped) internal representatio...
std::enable_if< Condition, void >::type reset()
Reset the register to an all-false value.
Definition: vec_pred_reg.hh:96
Vector Registers layout specification.
Generic predicate register container.
Definition: vec_pred_reg.hh:51
bool operator!=(const VecPredRegContainer< N2, P2 > &that) const
Inequality operator, required to compare thread contexts.
bool operator==(const VecPredRegContainer< N2, P2 > &that) const
Equality operator, required to compare thread contexts.
Bitfield< 3, 0 > mask
Definition: types.hh:64
::DummyVecElem VecElem
Definition: registers.hh:50
bool & operator[](size_t idx)
Returns a reference to a specific element of the internal container.
const bool & operator[](size_t idx) const
Bitfield< 0 > p

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