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

Change subject: arch-x86: Use the new multiplication helpers in the mul uops.
......................................................................

arch-x86: Use the new multiplication helpers in the mul uops.

Change-Id: Ib12b2e357fae19455a1a11dd890dda6602a6dc41
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/42361
Reviewed-by: Daniel Carvalho <oda...@yahoo.com.br>
Maintainer: Gabe Black <gabe.bl...@gmail.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/arch/x86/isa/includes.isa
M src/arch/x86/isa/microops/regop.isa
2 files changed, 37 insertions(+), 60 deletions(-)

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



diff --git a/src/arch/x86/isa/includes.isa b/src/arch/x86/isa/includes.isa
index 71225ce..0136624 100644
--- a/src/arch/x86/isa/includes.isa
+++ b/src/arch/x86/isa/includes.isa
@@ -102,6 +102,7 @@
 output exec {{
 #include <cmath>
 #include <limits>
+#include <tuple>

 #include "arch/generic/debugfaults.hh"
 #include "arch/x86/cpuid.hh"
@@ -112,6 +113,7 @@
 #include "arch/x86/tlb.hh"
 #include "base/compiler.hh"
 #include "base/condcodes.hh"
+#include "base/logging.hh"
 #include "cpu/base.hh"
 #include "cpu/exetrace.hh"
 #include "debug/X86.hh"
diff --git a/src/arch/x86/isa/microops/regop.isa b/src/arch/x86/isa/microops/regop.isa
index fb0bea1..a634c48 100644
--- a/src/arch/x86/isa/microops/regop.isa
+++ b/src/arch/x86/isa/microops/regop.isa
@@ -584,43 +584,26 @@

     class Mul1s(WrRegOp):
         op_class = 'IntMultOp'
-
- # Multiply two values Aa and Bb where Aa = A << p + a, then correct for
-        # negative operands.
-        #   Aa * Bb
-        # = (A << p + a) * (B << p + b)
-        # = (A * B) << 2p + (A * b + a * B) << p + a * b
         code = '''
-            ProdLow = psrc1 * op2;
-
-            int p = (dataSize * 8) / 2;
-            uint64_t A = bits(psrc1, 2 * p - 1, p);
-            uint64_t a = bits(psrc1, p - 1, 0);
-            uint64_t B = bits<uint64_t>(op2, 2 * p - 1, p);
-            uint64_t b = bits<uint64_t>(op2, p - 1, 0);
-
-            uint64_t c1, c2; // Carry between place values.
-            uint64_t ab = a * b, Ab = A * b, aB = a * B, AB = A * B;
-
-            c1 = ab >> p;
-
-            // Be careful to avoid overflow if p is large.
-            if (p == 32) {
-                c2 = (c1 >> 1) + (Ab >> 1) + (aB >> 1);
-                c2 += ((c1 & 0x1) + (Ab & 0x1) + (aB & 0x1)) >> 1;
-                c2 >>= (p - 1);
-            } else {
-                c2 = (c1 + Ab + aB) >> p;
+            int64_t hi, low;
+            switch (dataSize) {
+              case 8:
+                std::tie(hi, low) = mulSigned<int64_t>(psrc1, op2);
+                break;
+              case 4:
+                std::tie(hi, low) = mulSigned<int32_t>(psrc1, op2);
+                break;
+              case 2:
+                std::tie(hi, low) = mulSigned<int16_t>(psrc1, op2);
+                break;
+              case 1:
+                std::tie(hi, low) = mulSigned<int8_t>(psrc1, op2);
+                break;
+              default:
+                panic("Unrecognized data size %d.", dataSize);
             }
-
-            uint64_t hi = AB + c2;
-
-            if (bits(psrc1, dataSize * 8 - 1))
-                hi -= op2;
-            if (bits(op2, dataSize * 8 - 1))
-                hi -= psrc1;
-
             ProdHi = hi;
+            ProdLow = low;
             '''
         flag_code = '''
             if ((-ProdHi & mask(dataSize * 8)) !=
@@ -636,34 +619,26 @@
     class Mul1u(WrRegOp):
         op_class = 'IntMultOp'

-        # Multiply two values Aa and Bb where Aa = A << p + a.
-        #   Aa * Bb
-        # = (A << p + a) * (B << p + b)
-        # = (A * B) << 2p + (A * b + a * B) << p + a * b
         code = '''
-            ProdLow = psrc1 * op2;
-
-            int p = (dataSize * 8) / 2;
-            uint64_t A = bits(psrc1, 2 * p - 1, p);
-            uint64_t a = bits(psrc1, p - 1, 0);
-            uint64_t B = bits<uint64_t>(op2, 2 * p - 1, p);
-            uint64_t b = bits<uint64_t>(op2, p - 1, 0);
-
-            uint64_t c1, c2; // Carry between place values.
-            uint64_t ab = a * b, Ab = A * b, aB = a * B, AB = A * B;
-
-            c1 = ab >> p;
-
-            // Be careful to avoid overflow if p is large.
-            if (p == 32) {
-                c2 = (c1 >> 1) + (Ab >> 1) + (aB >> 1);
-                c2 += ((c1 & 0x1) + (Ab & 0x1) + (aB & 0x1)) >> 1;
-                c2 >>= (p - 1);
-            } else {
-                c2 = (c1 + Ab + aB) >> p;
+            uint64_t hi, low;
+            switch (dataSize) {
+              case 8:
+                std::tie(hi, low) = mulUnsigned<uint64_t>(psrc1, op2);
+                break;
+              case 4:
+                std::tie(hi, low) = mulUnsigned<uint32_t>(psrc1, op2);
+                break;
+              case 2:
+                std::tie(hi, low) = mulUnsigned<uint16_t>(psrc1, op2);
+                break;
+              case 1:
+                std::tie(hi, low) = mulUnsigned<uint8_t>(psrc1, op2);
+                break;
+              default:
+                panic("Unrecognized data size %d.", dataSize);
             }
-
-            ProdHi = AB + c2;
+            ProdHi = hi;
+            ProdLow = low;
             '''
         flag_code = '''
             if (ProdHi) {

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/42361
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: Ib12b2e357fae19455a1a11dd890dda6602a6dc41
Gerrit-Change-Number: 42361
Gerrit-PatchSet: 11
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Andreas Sandberg <andreas.sandb...@arm.com>
Gerrit-Reviewer: Daniel Carvalho <oda...@yahoo.com.br>
Gerrit-Reviewer: Gabe Black <gabe.bl...@gmail.com>
Gerrit-Reviewer: Giacomo Travaglini <giacomo.travagl...@arm.com>
Gerrit-Reviewer: Tong Shen <endlessr...@google.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
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

Reply via email to