40 #ifndef __ARCH_GENERIC_VEC_PRED_REG_HH__ 41 #define __ARCH_GENERIC_VEC_PRED_REG_HH__ 50 template <
size_t NumBits,
bool Packed>
69 template <
typename VecElem,
size_t NumElems,
bool Packed,
bool Const>
74 static constexpr
size_t NUM_BITS = Packed ? NumElems :
79 using Container =
typename std::conditional<
82 VecPredRegContainer<NUM_BITS, Packed>>
::type;
94 template<
bool Condition = !Const>
99 template<
bool Condition = !Const>
101 set() { container.set(); }
103 template<
bool Condition = !Const>
114 return container[idx * (Packed ? 1 :
sizeof(
VecElem))];
117 template<
bool Condition = !Const>
121 return container[idx * (Packed ? 1 :
sizeof(
VecElem))];
129 return container.get_bits(idx * (Packed ? 1 :
sizeof(
VecElem)),
130 (Packed ? 1 :
sizeof(
VecElem)));
134 template<
bool Condition = !Const>
138 container.set_bits(idx * (Packed ? 1 :
sizeof(
VecElem)),
139 (Packed ? 1 :
sizeof(
VecElem)), val);
143 template<
typename VE2,
size_t NE2,
bool P2,
bool C2>
151 template<
typename VE2,
size_t NE2,
bool P2,
bool C2>
180 size_t actual_num_elems)
const 182 assert(actual_num_elems <= NumElems);
183 for (
int i = 0;
i < actual_num_elems; ++
i) {
198 size_t actual_num_elems)
const 200 assert(actual_num_elems <= NumElems);
201 for (
int i = 0;
i < actual_num_elems; ++
i) {
202 if (mask[
i] &&
operator[](
i)) {
216 size_t actual_num_elems)
const 218 assert(actual_num_elems <= NumElems);
219 for (
int i = actual_num_elems - 1;
i >= 0; --
i) {
234 template <
size_t NumBits,
bool Packed>
237 static_assert(NumBits > 0,
238 "Size of a predicate register must be > 0");
267 std::copy(that.begin(), that.end(), container.begin());
275 container.fill(
false);
282 container.fill(
true);
286 template<
size_t N2,
bool P2>
290 return NumBits == N2 && Packed == P2 && container == that.
container;
294 template<
size_t N2,
bool P2>
306 const bool&
operator[](
size_t idx)
const {
return container[idx]; }
313 assert(nbits > 0 && nbits <= 8 && (idx + nbits - 1) < NumBits);
315 idx = idx + nbits - 1;
316 for (
int i = 0;
i < nbits; ++
i, --idx) {
328 assert(nbits > 0 && nbits <= 8 && (idx + nbits - 1) < NumBits);
329 for (
int i = 0;
i < nbits; ++
i, ++idx) {
330 container[idx] = bval & 1;
355 size_t NumElems = (Packed ? NumBits : NumBits /
sizeof(
VecElem))>
358 static_assert((Packed && NumElems <= NumBits) ||
360 NumBits %
sizeof(
VecElem) == 0 &&
361 sizeof(
VecElem) * NumElems <= NumBits),
362 "Container size incompatible with view size");
367 size_t NumElems = (Packed ? NumBits : NumBits /
sizeof(
VecElem))>
370 static_assert((Packed && NumElems <= NumBits) ||
372 NumBits %
sizeof(
VecElem) == 0 &&
373 sizeof(
VecElem) * NumElems <= NumBits),
374 "Container size incompatible with view size");
381 template <
size_t NumBits,
bool Packed>
386 for (
const auto&
c: value) {
405 #endif // __ARCH_GENERIC_VEC_PRED_REG_HH__ void reset()
Resets the predicate register to an all-false register.
constexpr unsigned DummyNumVecElemPerVecReg
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.
uint32_t DummyVecElem
Dummy type aliases and constants for architectures that do not implement vector registers.
VecPredRegT(Container &c)
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.
MyClass & operator=(const MyClass &that)
std::enable_if< Condition, MyClass & >::type operator=(const MyClass &that)
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.
Container & container
Container corresponding to this view.
std::string csprintf(const char *format, const Args &...args)
const std::string print() const
Returns a string representation of the register content.
::DummyVecPredRegContainer VecPredRegContainer
std::array< bool, NumBits > Container
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.
VecPredRegT< VecElem, NumElems, Packed, false > as()
const std::string print() const
Returns a string representation of the register content.
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.
Vector Registers layout specification.
Generic predicate register container.
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.
bool & operator[](size_t idx)
Returns a reference to a specific element of the internal container.
const bool & operator[](size_t idx) const