Sandipan Das has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/40921 )

Change subject: arch-power: Add population count instructions
......................................................................

arch-power: Add population count instructions

This adds the following instructions.
  * Population Count Bytes (popcntb)
  * Population Count Words (popcntw)
  * Population Count Doubleword (popcntd)

Change-Id: Id15188482b45552735c1d960418d5d6ba1f2ede8
Signed-off-by: Sandipan Das <[email protected]>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/40921
Reviewed-by: Boris Shingarov <[email protected]>
Maintainer: Boris Shingarov <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/arch/power/isa/decoder.isa
1 file changed, 42 insertions(+), 1 deletion(-)

Approvals:
  Boris Shingarov: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/arch/power/isa/decoder.isa b/src/arch/power/isa/decoder.isa
index 15ad7ad..fdb86f9 100644
--- a/src/arch/power/isa/decoder.isa
+++ b/src/arch/power/isa/decoder.isa
@@ -288,7 +288,23 @@
         }

         119: LoadIndexUpdateOp::lbzux({{ Rt = Mem_ub; }});
-        124: IntLogicOp::nor({{ Ra = ~(Rs | Rb); }}, true);
+
+        format IntLogicOp {
+            122: popcntb({{
+                // Based on "Counting bits set, in parallel"
+ // from https://graphics.stanford.edu/~seander/bithacks.html
+                const uint64_t m1 = 0x5555555555555555ULL;
+                const uint64_t m2 = 0x3333333333333333ULL;
+                const uint64_t m4 = 0x0f0f0f0f0f0f0f0fULL;
+                uint64_t res = Rs;
+                res = (res & m1) + ((res >> 1) & m1);
+                res = (res & m2) + ((res >> 2) & m2);
+                res = (res & m4) + ((res >> 4) & m4);
+                Ra = res;
+            }});
+
+            124: nor({{ Ra = ~(Rs | Rb); }}, true);
+        }

         format StoreIndexOp {
             149: stdx({{ Mem = Rs }});
@@ -403,6 +419,30 @@
             375: lhaux({{ Rt = Mem_sh; }});
         }

+        378: IntLogicOp::popcntw({{
+        #if defined(__GNUC__) || (defined(__clang__) && \
+                __has_builtin(__builtin_popcount))
+            uint64_t src = Rs;
+            uint64_t res = __builtin_popcount(src >> 32);
+            res = (res << 32) | __builtin_popcount(src);
+        #else
+            // Based on "Counting bits set, in parallel"
+            // from https://graphics.stanford.edu/~seander/bithacks.html
+            const uint64_t m1 = 0x5555555555555555ULL;
+            const uint64_t m2 = 0x3333333333333333ULL;
+            const uint64_t m4 = 0x0f0f0f0f0f0f0f0fULL;
+            const uint64_t m8 = 0x00ff00ff00ff00ffULL;
+            const uint64_t m16 = 0x0000ffff0000ffffULL;
+            uint64_t res = Rs;
+            res = (res & m1) + ((res >> 1) & m1);
+            res = (res & m2) + ((res >> 2) & m2);
+            res = (res & m4) + ((res >> 4) & m4);
+            res = (res & m8) + ((res >> 8) & m8);
+            res = (res & m16) + ((res >> 16) & m16);
+        #endif
+            Ra = res;
+        }});
+
         407: StoreIndexOp::sthx({{ Mem_uh = Rs_uh; }});
         412: IntLogicOp::orc({{ Ra = Rs | ~Rb; }}, true);
         439: StoreIndexUpdateOp::sthux({{ Mem_uh = Rs_uh; }});
@@ -410,6 +450,7 @@
         format IntLogicOp {
             444: or({{ Ra = Rs | Rb; }}, true);
             476: nand({{ Ra = ~(Rs & Rb); }}, true);
+            506: popcntd({{ Ra = popCount(Rs); }});

             508: cmpb({{
                 uint64_t mask = 0xff;

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/40921
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: Id15188482b45552735c1d960418d5d6ba1f2ede8
Gerrit-Change-Number: 40921
Gerrit-PatchSet: 8
Gerrit-Owner: Sandipan Das <[email protected]>
Gerrit-Reviewer: Boris Shingarov <[email protected]>
Gerrit-Reviewer: Sandipan Das <[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