Gabe Black has uploaded this change for review. ( 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
---
M src/base/intmath.hh
M src/base/intmath.test.cc
2 files changed, 32 insertions(+), 0 deletions(-)



diff --git a/src/base/intmath.hh b/src/base/intmath.hh
index b88e41c..3014460 100644
--- a/src/base/intmath.hh
+++ b/src/base/intmath.hh
@@ -32,6 +32,7 @@
 #include <cassert>
 #include <cstdint>
 #include <type_traits>
+#include <utility>

 #include "base/logging.hh"
 #include "base/types.hh"
@@ -213,6 +214,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};
+};
+
 /**
  * @ingroup api_base_utils
  */
diff --git a/src/base/intmath.test.cc b/src/base/intmath.test.cc
index 707d5cb..9d94716 100644
--- a/src/base/intmath.test.cc
+++ b/src/base/intmath.test.cc
@@ -27,6 +27,7 @@
  */

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

 #include "base/intmath.hh"

@@ -145,6 +146,12 @@
     mulUnsignedManual<uint64_t>(hi, low, a, b);
     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);
 }

 TEST(IntMathTest, mulSignedWide)
@@ -162,6 +169,12 @@
     mulSignedManual<int64_t>(hi, low, a, b);
     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);
 }

 TEST(IntmathTest, roundUp)

--
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: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
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