144 #ifndef __ARCH_GENERIC_VEC_REG_HH__ 145 #define __ARCH_GENERIC_VEC_REG_HH__ 151 #include <type_traits> 173 template <
typename VecElem,
size_t NumElems,
bool Const>
180 using Container =
typename std::conditional<Const,
194 template<
bool Condition = !Const>
198 template<
bool Condition = !Const>
209 return container.template raw_ptr<VecElem>()[idx];
213 template<
bool Condition = !Const>
217 return container.template raw_ptr<VecElem>()[idx];
223 template<
typename VE2,
size_t NE2,
bool C2>
232 template<
typename VE2,
size_t NE2,
bool C2>
244 os <<
"[" << std::hex << (uint32_t)vr[0];
245 for (uint32_t
e = 1;
e < vr.
SIZE;
e++)
246 os <<
" " << std::hex << (uint32_t)vr[
e];
261 template <
typename VecElem,
bool Const>
274 static_assert(Sz > 0,
275 "Cannot create Vector Register Container of zero size");
277 "Vector Register size limit exceeded");
279 static constexpr
size_t SIZE = Sz;
291 assert(that.size() >=
SIZE);
292 std::memcpy(container.data(), &that[0],
SIZE);
312 std::memcpy(container.data(), that.data(),
SIZE);
321 assert(that.size() >=
SIZE);
322 std::memcpy(container.data(), that.data(),
SIZE);
332 std::memcpy(dst.data(), container.data(),
SIZE);
341 std::memcpy(dst.data(), container.data(),
SIZE);
367 template <
typename Ret>
368 const Ret*
raw_ptr()
const {
return (
const Ret*)container.data(); }
370 template <
typename Ret>
371 Ret*
raw_ptr() {
return (Ret*)container.data(); }
384 template <
typename VecElem,
size_t NumElems = SIZE/
sizeof(
VecElem)>
387 static_assert(SIZE %
sizeof(
VecElem) == 0,
388 "VecElem does not evenly divide the register size");
389 static_assert(
sizeof(
VecElem) * NumElems <= SIZE,
390 "Viewing VecReg as something bigger than it is");
394 template <
typename VecElem,
size_t NumElems = SIZE/
sizeof(
VecElem)>
397 static_assert(SIZE %
sizeof(
VecElem) == 0,
398 "VecElem does not evenly divide the register size");
399 static_assert(
sizeof(
VecElem) * NumElems <= SIZE,
400 "Viewing VecReg as something bigger than it is");
404 template <
typename VecElem,
int LaneIdx>
406 template <
typename VecElem,
int LaneIdx>
408 template <
typename VecElem>
410 template <
typename VecElem>
456 template <LaneSize LS>
476 template <
typename T>
explicit 480 template <
typename T>
490 return *
static_cast<const T*
>(&_val);
495 template <LaneSize LS>
497 operator<<(std::ostream& os, const LaneData<LS>&
d)
499 return os << static_cast<typename LaneData<LS>::UnderlyingType>(
d);
510 template <
typename VecElem,
bool Const>
534 using Cont =
typename std::conditional<Const,
537 static_assert(!std::is_const<VecElem>::value || Const,
538 "Asked for non-const lane of const type!");
539 static_assert(std::is_integral<VecElem>::value,
540 "VecElem type is not integral!");
553 template <
bool Assignable = !Const>
564 template <
bool Assignable = !Const,
typename T>
567 static_assert(
sizeof(T) >=
sizeof(VecElem),
568 "Attempt to perform widening bitwise copy.");
569 static_assert(
sizeof(T) <=
sizeof(VecElem),
570 "Attempt to perform narrowing bitwise copy.");
571 container =
static_cast<VecElem
>(that);
587 template<
typename T,
bool Const>
593 template <
typename VecElem,
int LaneIdx>
602 template <
typename VecElem,
int LaneIdx>
611 template <
typename VecElem>
620 template <
typename VecElem>
646 "Vector register value overflow at unserialize");
648 for (
int i = 0; i < VecRegContainer<Sz>::SIZE;
i++) {
650 if (2 *
i < value.size())
651 b = stoul(value.substr(
i * 2, 2),
nullptr, 16);
652 v.template raw_ptr<uint8_t>()[
i] = b;
std::enable_if< Condition, VecElem & >::type operator[](size_t idx)
Index operator.
void zero()
Zero the container.
typename std::conditional< LS==LaneSize::EightByte, uint64_t, typename std::conditional< LS==LaneSize::FourByte, uint32_t, typename std::conditional< LS==LaneSize::TwoByte, uint16_t, typename std::conditional< LS==LaneSize::Byte, uint8_t, void >::type >::type >::type >::type UnderlyingType
Alias to the native type of the appropriate size.
LaneData(typename std::enable_if< sizeof(T)==ByteSz, const T &>::type t)
VecRegT< VecElem, NumElems, true > as() const
View interposers.
VecRegT(Container &cnt)
Constructor.
VecRegContainer(const std::vector< uint8_t > &that)
constexpr unsigned DummyNumVecElemPerVecReg
Vector Register Abstraction This generic class is the model in a particularization of MVC...
bool operator==(const VecRegContainer< S2 > &that) const
Equality operator.
const VecElem & operator[](size_t idx) const
Index operator.
static constexpr size_t SIZE
Size of the register in bytes.
LaneSize
We define an auxiliary abstraction for LaneData.
friend std::ostream & operator<<(std::ostream &os, const MyClass &vr)
Output stream operator.
const Ret * raw_ptr() const
Get pointer to bytes.
Overload hash function for BasicBlockRange type.
std::enable_if< Condition, void >::type zero()
Zero the container.
uint32_t DummyVecElem
Dummy type aliases and constants for architectures that do not implement vector registers.
VecLaneT(Cont &cont)
Constructor.
std::enable_if< sizeof(T)==ByteSz, MyClass & >::type operator=(const T &that)
typename std::conditional< Const, const VecRegContainer< SIZE >, VecRegContainer< SIZE > >::type Container
Container type alias.
friend std::ostream & operator<<(std::ostream &os, const MyClass &v)
Output operator.
bool to_number(const std::string &value, VecRegContainer< Sz > &v)
Calls required for serialization/deserialization.
void copyTo(Container &dst) const
Copy the contents into the input buffer.
LaneSize is an abstraction of a LS byte value for the execution and thread contexts to handle values ...
std::string csprintf(const char *format, const Args &...args)
std::enable_if< Assignable, MyClass & >::type operator=(const T &that)
Generic.
::DummyVecRegContainer VecRegContainer
std::enable_if< Assignable, MyClass & >::type operator=(const VecElem &that)
Assignment operators.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Container & container
Reference to container.
DummyVecReg::Container DummyVecRegContainer
void copyTo(std::vector< uint8_t > &dst) const
To vector<uint8_t> This is required for serialisation.
bool operator!=(const VecRegT< VE2, NE2, C2 > &that) const
Inequality operator.
constexpr unsigned MaxVecRegLenInBytes
MyClass & operator=(const Container &that)
From appropriately sized uint8_t[].
const std::string print() const
std::enable_if< Condition, MyClass & >::type operator=(const MyClass &that)
MyClass & operator=(const std::vector< uint8_t > &that)
From vector<uint8_t>.
Cont & container
Reference to data.
MyClass & operator=(const MyClass &that)
Assignment operators.
typename std::conditional< Const, const VecElem, VecElem >::type Cont
VecLaneT< VecElem, false > laneView()
View as the Nth lane of type VecElem.
Vector Register Abstraction This generic class is a view in a particularization of MVC...
VecRegT< VecElem, NumElems, false > as()
bool operator==(const VecRegT< VE2, NE2, C2 > &that) const
Equality operator.
bool operator!=(const VecRegContainer< S2 > &that) const
Inequality operator.
Vector Lane abstraction Another view of a container.
std::array< uint8_t, Sz > Container
constexpr size_t DummyVecRegSizeBytes
const std::string print() const