Gabe Black has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/24964 )

Change subject: arch: Convert the static constexpr SIZE in vec_reg to a function.
......................................................................

arch: Convert the static constexpr SIZE in vec_reg to a function.

When defining a static constexpr variable in C++11, it is still
required to have a separate definition someplace, something that can
be particularly problematic in template classes. C++17 fixes this
problem by adding inline variables which don't, but in the mean time
having a static constexpr value with no backing store will, if the
compiler decides to not fold away the storage location, cause linking
errors.

This happened to me when trying to build the debug build of ARM just
now.

By turning these expressions into static inline functions, then they
no longer need definitions elsewhere, still fold away to nothing, and
are compliant with C++11 which is currently the standard gem5 expects
to be using.

Change-Id: I647d7cf4a1e8de98251ee9ef116f007e08eac1f3
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24964
Tested-by: kokoro <noreply+kok...@google.com>
Reviewed-by: Chun-Chen TK Hsu <chunchen...@google.com>
Maintainer: Giacomo Travaglini <giacomo.travagl...@arm.com>
---
M src/arch/arm/fastmodel/iris/thread_context.cc
M src/arch/generic/vec_reg.hh
2 files changed, 18 insertions(+), 14 deletions(-)

Approvals:
  Chun-Chen TK Hsu: Looks good to me, approved
  Giacomo Travaglini: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/arch/arm/fastmodel/iris/thread_context.cc b/src/arch/arm/fastmodel/iris/thread_context.cc
index 98fc09e..85171fc 100644
--- a/src/arch/arm/fastmodel/iris/thread_context.cc
+++ b/src/arch/arm/fastmodel/iris/thread_context.cc
@@ -589,7 +589,7 @@
     iris::ResourceReadResult result;
     call().resource_read(_instId, result, vecRegIds.at(idx));
     size_t data_size = result.data.size() * (sizeof(*result.data.data()));
-    size_t size = std::min(data_size, reg.SIZE);
+    size_t size = std::min(data_size, reg.size());
     memcpy(reg.raw_ptr<void>(), (void *)result.data.data(), size);

     return reg;
diff --git a/src/arch/generic/vec_reg.hh b/src/arch/generic/vec_reg.hh
index 8b9bea1..4156ac5 100644
--- a/src/arch/generic/vec_reg.hh
+++ b/src/arch/generic/vec_reg.hh
@@ -170,12 +170,16 @@
 class VecRegT
 {
     /** Size of the register in bytes. */
-    static constexpr size_t SIZE = sizeof(VecElem) * NumElems;
+    static constexpr inline size_t
+    size()
+    {
+        return sizeof(VecElem) * NumElems;
+    }
   public:
     /** Container type alias. */
     using Container = typename std::conditional<Const,
-                                              const VecRegContainer<SIZE>,
-                                              VecRegContainer<SIZE>>::type;
+ const VecRegContainer<size()>, + VecRegContainer<size()>>::type;
   private:
     /** My type alias. */
     using MyClass = VecRegT<VecElem, NumElems, Const>;
@@ -238,7 +242,7 @@
     {
         /* 0-sized is not allowed */
         os << "[" << std::hex << (uint32_t)vr[0];
-        for (uint32_t e = 1; e < vr.SIZE; e++)
+        for (uint32_t e = 1; e < vr.size(); e++)
             os << " " << std::hex << (uint32_t)vr[e];
         os << ']';
         return os;
@@ -264,16 +268,16 @@
  * portion through the method 'as
  * @tparam Sz Size of the container in bytes.
  */
-template <size_t Sz>
+template <size_t SIZE>
 class VecRegContainer
 {
-  static_assert(Sz > 0,
+  static_assert(SIZE > 0,
           "Cannot create Vector Register Container of zero size");
-  static_assert(Sz <= MaxVecRegLenInBytes,
+  static_assert(SIZE <= MaxVecRegLenInBytes,
           "Vector Register size limit exceeded");
   public:
-    static constexpr size_t SIZE = Sz;
-    using Container = std::array<uint8_t,Sz>;
+    static constexpr inline size_t size() { return SIZE; };
+    using Container = std::array<uint8_t, SIZE>;
   private:
     Container container;
     using MyClass = VecRegContainer<SIZE>;
@@ -377,7 +381,7 @@
      * @tparam NumElem Amount of elements in the view.
      */
     /** @{ */
-    template <typename VecElem, size_t NumElems = SIZE/sizeof(VecElem)>
+    template <typename VecElem, size_t NumElems=(SIZE / sizeof(VecElem))>
     VecRegT<VecElem, NumElems, true> as() const
     {
         static_assert(SIZE % sizeof(VecElem) == 0,
@@ -387,7 +391,7 @@
         return VecRegT<VecElem, NumElems, true>(*this);
     }

-    template <typename VecElem, size_t NumElems = SIZE/sizeof(VecElem)>
+    template <typename VecElem, size_t NumElems=(SIZE / sizeof(VecElem))>
     VecRegT<VecElem, NumElems, false> as()
     {
         static_assert(SIZE % sizeof(VecElem) == 0,
@@ -638,10 +642,10 @@
 inline bool
 to_number(const std::string& value, VecRegContainer<Sz>& v)
 {
-    fatal_if(value.size() > 2 * VecRegContainer<Sz>::SIZE,
+    fatal_if(value.size() > 2 * VecRegContainer<Sz>::size(),
              "Vector register value overflow at unserialize");

-    for (int i = 0; i < VecRegContainer<Sz>::SIZE; i++) {
+    for (int i = 0; i < VecRegContainer<Sz>::size(); i++) {
         uint8_t b = 0;
         if (2 * i < value.size())
             b = stoul(value.substr(i * 2, 2), nullptr, 16);

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/24964
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I647d7cf4a1e8de98251ee9ef116f007e08eac1f3
Gerrit-Change-Number: 24964
Gerrit-PatchSet: 9
Gerrit-Owner: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Chun-Chen TK Hsu <chunchen...@google.com>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Jason Lowe-Power <ja...@lowepower.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to