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
Tested-by: kokoro
Reviewed-by: Daniel Carvalho
---
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
#include
#include
+#include
#include "base/bitfield.hh"
@@ -223,6 +224,24 @@
#endif
}
+template
+static constexpr std::pair,
std::make_unsigned_t>
+mulUnsigned(std::make_unsigned_t val_a, std::make_unsigned_t val_b)
+{
+std::make_unsigned_t hi, low;
+mulUnsigned(hi, low, val_a, val_b);
+return {hi, low};
+};
+
+template
+static constexpr std::pair, std::make_signed_t>
+mulSigned(std::make_signed_t val_a, std::make_signed_t val_b)
+{
+std::make_signed_t hi, low;
+mulSigned(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
+#include
#include "base/intmath.hh"
@@ -220,6 +221,12 @@
EXPECT_EQ(hi, 0x1);
EXPECT_EQ(low, 0xfffe);
+hi = 0;
+low = 0;
+std::tie(hi, low) = mulUnsigned(a, b);
+EXPECT_EQ(hi, 0x1);
+EXPECT_EQ(low, 0xfffe);
+
a = 0;
b = 0x;
mulUnsigned(hi, low, a, b);
@@ -243,6 +250,12 @@
EXPECT_EQ(hi, 0x3fff);
EXPECT_EQ(low, -0x8000);
+hi = 0;
+low = 0;
+std::tie(hi, low) = mulSigned(a, b);
+EXPECT_EQ(hi, 0x3fff);
+EXPECT_EQ(low, -0x8000);
+
a = 0;
b = -0x;
mulSigned(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
Gerrit-Reviewer: Bobby R. Bruce
Gerrit-Reviewer: Daniel Carvalho
Gerrit-Reviewer: Gabe Black
Gerrit-Reviewer: kokoro
Gerrit-MessageType: merged
___
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s