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

Change subject: base: Introduce versions of mul(Uns|S)igned which return two values.
......................................................................

base: Introduce versions of mul(Uns|S)igned which return two values.

This makes code which needs to call lots of different sized multiplications.

Change-Id: Id0d28be4c304214171840e7916c2e90ecfcd3840
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/42360
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
Reviewed-by: Daniel Carvalho <[email protected]>
---
M src/base/intmath.hh
M src/base/intmath.test.cc
2 files changed, 32 insertions(+), 0 deletions(-)

Approvals:
  Daniel Carvalho: Looks good to me, approved
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/base/intmath.hh b/src/base/intmath.hh
index 7acb889..4be4a3b 100644
--- a/src/base/intmath.hh
+++ b/src/base/intmath.hh
@@ -44,6 +44,7 @@
 #include <cassert>
 #include <cstdint>
 #include <type_traits>
+#include <utility>

 #include "base/bitfield.hh"

@@ -223,6 +224,24 @@
 #endif
 }

+template <typename T>
+static constexpr std::pair<std::make_unsigned_t<T>, std::make_unsigned_t<T>>
+mulUnsigned(std::make_unsigned_t<T> val_a, std::make_unsigned_t<T> val_b)
+{
+    std::make_unsigned_t<T> hi, low;
+    mulUnsigned<T>(hi, low, val_a, val_b);
+    return {hi, low};
+};
+
+template <typename T>
+static constexpr std::pair<std::make_signed_t<T>, std::make_signed_t<T>>
+mulSigned(std::make_signed_t<T> val_a, std::make_signed_t<T> val_b)
+{
+    std::make_signed_t<T> hi, low;
+    mulSigned<T>(hi, low, val_a, val_b);
+    return {hi, low};
+};
+
 /**
  * This function is used to align addresses in memory.
  *
diff --git a/src/base/intmath.test.cc b/src/base/intmath.test.cc
index b7fb34a..e42a9a8 100644
--- a/src/base/intmath.test.cc
+++ b/src/base/intmath.test.cc
@@ -38,6 +38,7 @@
  */

 #include <gtest/gtest.h>
+#include <tuple>

 #include "base/intmath.hh"

@@ -220,6 +221,12 @@
     EXPECT_EQ(hi, 0x1);
     EXPECT_EQ(low, 0xfffffffffffffffe);

+    hi = 0;
+    low = 0;
+    std::tie(hi, low) = mulUnsigned<uint64_t>(a, b);
+    EXPECT_EQ(hi, 0x1);
+    EXPECT_EQ(low, 0xfffffffffffffffe);
+
     a = 0;
     b = 0x5555555555555555;
     mulUnsigned<uint64_t>(hi, low, a, b);
@@ -243,6 +250,12 @@
     EXPECT_EQ(hi, 0x3fffffffffffffff);
     EXPECT_EQ(low, -0x8000000000000000);

+    hi = 0;
+    low = 0;
+    std::tie(hi, low) = mulSigned<int64_t>(a, b);
+    EXPECT_EQ(hi, 0x3fffffffffffffff);
+    EXPECT_EQ(low, -0x8000000000000000);
+
     a = 0;
     b = -0x5555555555555555;
     mulSigned<int64_t>(hi, low, a, b);



7 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted one.
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/42360
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: Id0d28be4c304214171840e7916c2e90ecfcd3840
Gerrit-Change-Number: 42360
Gerrit-PatchSet: 9
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Daniel Carvalho <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to