[gem5-dev] Change in gem5/gem5[develop]: base: Introduce versions of mul(Uns|S)igned which return two values.

2021-04-22 Thread Gabe Black (Gerrit) via gem5-dev
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

[gem5-dev] Change in gem5/gem5[develop]: base: Introduce versions of mul(Uns|S)igned which return two values.

2021-03-06 Thread Gabe Black (Gerrit) via gem5-dev
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 
 #include 
 #include 
+#include 

 #include "base/logging.hh"
 #include "base/types.hh"
@@ -213,6 +214,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};
+};
+
 /**
  * @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 
+#include 

 #include "base/intmath.hh"

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

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

 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 
Gerrit-MessageType: newchange
___
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