[gem5-dev] Change in gem5/gem5[develop]: arch: Simplify and correct style of VecReg types.
Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/41993 ) Change subject: arch: Simplify and correct style of VecReg types. .. arch: Simplify and correct style of VecReg types. Change-Id: Ib15d2e03c3e9cabcf56b316d5c57d2e892ad255d Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/41993 Reviewed-by: Giacomo Travaglini Maintainer: Giacomo Travaglini Tested-by: kokoro --- M src/arch/generic/vec_reg.hh 1 file changed, 23 insertions(+), 63 deletions(-) Approvals: Giacomo Travaglini: Looks good to me, approved; Looks good to me, approved kokoro: Regressions pass diff --git a/src/arch/generic/vec_reg.hh b/src/arch/generic/vec_reg.hh index 3091034..379de28 100644 --- a/src/arch/generic/vec_reg.hh +++ b/src/arch/generic/vec_reg.hh @@ -125,12 +125,14 @@ template class VecRegT { + private: /** Size of the register in bytes. */ static constexpr inline size_t size() { return sizeof(VecElem) * NumElems; } + public: /** Container type alias. */ using Container = typename std::conditional -typename std::enable_if_t -zero() { container.zero(); } - -template -typename std::enable_if_t -operator=(const MyClass& that) -{ -container = that.container; -return *this; -} - /** Index operator. */ -const VecElem& operator[](size_t idx) const +const VecElem & +operator[](size_t idx) const { return container.template raw_ptr()[idx]; } @@ -173,25 +163,6 @@ return container.template raw_ptr()[idx]; } -/** Equality operator. - * Required to compare thread contexts. - */ -template -bool -operator==(const VecRegT& that) const -{ -return container == that.container; -} -/** Inequality operator. - * Required to compare thread contexts. - */ -template -bool -operator!=(const VecRegT& that) const -{ -return !operator==(that); -} - /** Output stream operator. */ friend std::ostream& operator<<(std::ostream& os, const MyClass& vr) @@ -205,6 +176,7 @@ } const std::string print() const { return csprintf("%s", *this); } + /** * Cast to VecRegContainer& * It is useful to get the reference to the container for ISA tricks, @@ -223,10 +195,11 @@ template class VecRegContainer { - static_assert(SIZE > 0, - "Cannot create Vector Register Container of zero size"); - static_assert(SIZE <= MaxVecRegLenInBytes, - "Vector Register size limit exceeded"); + private: +static_assert(SIZE > 0, +"Cannot create Vector Register Container of zero size"); +static_assert(SIZE <= MaxVecRegLenInBytes, +"Vector Register size limit exceeded"); public: static constexpr inline size_t size() { return SIZE; }; using Container = std::array; @@ -251,16 +224,17 @@ /** Assignment operators. */ /** @{ */ /** From VecRegContainer */ -MyClass& operator=(const MyClass& that) +MyClass& +operator=(const MyClass& that) { if ( == this) return *this; -memcpy(container.data(), that.container.data(), SIZE); -return *this; +return *this = that.container; } /** From appropriately sized uint8_t[]. */ -MyClass& operator=(const Container& that) +MyClass& +operator=(const Container& that) { std::memcpy(container.data(), that.data(), SIZE); return *this; @@ -269,7 +243,8 @@ /** From vector. * This is required for de-serialisation. * */ -MyClass& operator=(const std::vector& that) +MyClass& +operator=(const std::vector& that) { assert(that.size() >= SIZE); std::memcpy(container.data(), that.data(), SIZE); @@ -277,24 +252,6 @@ } /** @} */ -/** Copy the contents into the input buffer. */ -/** @{ */ -/** To appropriately sized uint8_t[] */ -void copyTo(Container& dst) const -{ -std::memcpy(dst.data(), container.data(), SIZE); -} - -/** To vector - * This is required for serialisation. - * */ -void copyTo(std::vector& dst) const -{ -dst.resize(SIZE); -std::memcpy(dst.data(), container.data(), SIZE); -} -/** @} */ - /** Equality operator. * Required to compare thread contexts. */ @@ -335,7 +292,8 @@ */ /** @{ */ template -VecRegT as() const +VecRegT +as() const { static_assert(SIZE % sizeof(VecElem) == 0, "VecElem does not evenly divide the register size"); @@ -345,7 +303,8 @@ } template -VecRegT as() +VecRegT +as() { static_assert(SIZE % sizeof(VecElem) == 0, "VecElem does not evenly divide the register size"); @@ -359,7 +318,8 @@ *
[gem5-dev] Change in gem5/gem5[develop]: arch: Simplify and correct style of VecReg types.
Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/41993 ) Change subject: arch: Simplify and correct style of VecReg types. .. arch: Simplify and correct style of VecReg types. Change-Id: Ib15d2e03c3e9cabcf56b316d5c57d2e892ad255d --- M src/arch/generic/vec_reg.hh 1 file changed, 23 insertions(+), 63 deletions(-) diff --git a/src/arch/generic/vec_reg.hh b/src/arch/generic/vec_reg.hh index 7828108..c8e7938 100644 --- a/src/arch/generic/vec_reg.hh +++ b/src/arch/generic/vec_reg.hh @@ -125,12 +125,14 @@ template class VecRegT { + private: /** Size of the register in bytes. */ static constexpr inline size_t size() { return sizeof(VecElem) * NumElems; } + public: /** Container type alias. */ using Container = typename std::conditional -typename std::enable_if_t -zero() { container.zero(); } - -template -typename std::enable_if_t -operator=(const MyClass& that) -{ -container = that.container; -return *this; -} - /** Index operator. */ -const VecElem& operator[](size_t idx) const +const VecElem & +operator[](size_t idx) const { return container.template raw_ptr()[idx]; } @@ -173,25 +163,6 @@ return container.template raw_ptr()[idx]; } -/** Equality operator. - * Required to compare thread contexts. - */ -template -bool -operator==(const VecRegT& that) const -{ -return container == that.container; -} -/** Inequality operator. - * Required to compare thread contexts. - */ -template -bool -operator!=(const VecRegT& that) const -{ -return !operator==(that); -} - /** Output stream operator. */ friend std::ostream& operator<<(std::ostream& os, const MyClass& vr) @@ -205,6 +176,7 @@ } const std::string print() const { return csprintf("%s", *this); } + /** * Cast to VecRegContainer& * It is useful to get the reference to the container for ISA tricks, @@ -223,10 +195,11 @@ template class VecRegContainer { - static_assert(SIZE > 0, - "Cannot create Vector Register Container of zero size"); - static_assert(SIZE <= MaxVecRegLenInBytes, - "Vector Register size limit exceeded"); + private: +static_assert(SIZE > 0, +"Cannot create Vector Register Container of zero size"); +static_assert(SIZE <= MaxVecRegLenInBytes, +"Vector Register size limit exceeded"); public: static constexpr inline size_t size() { return SIZE; }; using Container = std::array; @@ -251,16 +224,17 @@ /** Assignment operators. */ /** @{ */ /** From VecRegContainer */ -MyClass& operator=(const MyClass& that) +MyClass& +operator=(const MyClass& that) { if ( == this) return *this; -memcpy(container.data(), that.container.data(), SIZE); -return *this; +return *this = that.container; } /** From appropriately sized uint8_t[]. */ -MyClass& operator=(const Container& that) +MyClass& +operator=(const Container& that) { std::memcpy(container.data(), that.data(), SIZE); return *this; @@ -269,7 +243,8 @@ /** From vector. * This is required for de-serialisation. * */ -MyClass& operator=(const std::vector& that) +MyClass& +operator=(const std::vector& that) { assert(that.size() >= SIZE); std::memcpy(container.data(), that.data(), SIZE); @@ -277,24 +252,6 @@ } /** @} */ -/** Copy the contents into the input buffer. */ -/** @{ */ -/** To appropriately sized uint8_t[] */ -void copyTo(Container& dst) const -{ -std::memcpy(dst.data(), container.data(), SIZE); -} - -/** To vector - * This is required for serialisation. - * */ -void copyTo(std::vector& dst) const -{ -dst.resize(SIZE); -std::memcpy(dst.data(), container.data(), SIZE); -} -/** @} */ - /** Equality operator. * Required to compare thread contexts. */ @@ -335,7 +292,8 @@ */ /** @{ */ template -VecRegT as() const +VecRegT +as() const { static_assert(SIZE % sizeof(VecElem) == 0, "VecElem does not evenly divide the register size"); @@ -345,7 +303,8 @@ } template -VecRegT as() +VecRegT +as() { static_assert(SIZE % sizeof(VecElem) == 0, "VecElem does not evenly divide the register size"); @@ -359,7 +318,8 @@ * Output operator. * Used for serialization. */ -friend std::ostream& operator<<(std::ostream& os, const MyClass& v) +friend std::ostream& +operator<<(std::ostream& os, const MyClass& v) { for (auto& b: v.container) {