Anthony Gutierrez has uploaded this change for review. ( https://gem5-review.googlesource.com/10462

Change subject: base: add some useful functions to bitfield.hh
......................................................................

base: add some useful functions to bitfield.hh

Some GCN3 operations do sign extension for 32b or bit
reversal. This change adds these bit manipulation
functions to bitfield.hh for general use.

The sext_32 function is derived from the 64b version
that already exists. The bit reversal algorithms
were taken from the bit twiddling hacks page:

http://graphics.stanford.edu/~seander/bithacks.html

Change-Id: Icfd6f20c5c2b57d9d85d8d2013e5cd3c1632facc
---
M src/base/bitfield.hh
1 file changed, 47 insertions(+), 1 deletion(-)



diff --git a/src/base/bitfield.hh b/src/base/bitfield.hh
index 23c8b4b..64145aa 100644
--- a/src/base/bitfield.hh
+++ b/src/base/bitfield.hh
@@ -117,6 +117,18 @@
 }

 /**
+ * Sign-extend an N-bit value to 32 bits.
+ */
+template <int N>
+inline
+uint32_t
+sext_32(uint32_t val)
+{
+    int sign_bit = bits(val, N-1, N-1);
+    return sign_bit ? (val | ~mask(N)) : val;
+}
+
+/**
  * Return val with bits first to last set to bit_val
  */
 template <class T, class B>
@@ -280,6 +292,40 @@
     val++;

     return val;
-};
+}
+
+/**
+ * Reverse the bits.
+ *
+ * This code has been modified from the following:
+ * http://graphics.stanford.edu/~seander/bithacks.html#ReverseParallel
+ */
+inline uint32_t
+bitReverse(uint32_t val)
+{
+    val = (((val & 0xaaaaaaaa) >> 1) | ((val & 0x55555555) << 1));
+    val = (((val & 0xcccccccc) >> 2) | ((val & 0x33333333) << 2));
+    val = (((val & 0xf0f0f0f0) >> 4) | ((val & 0x0f0f0f0f) << 4));
+    val = (((val & 0xff00ff00) >> 8) | ((val & 0x00ff00ff) << 8));
+
+    return ((val >> 16) | (val << 16));
+}
+
+inline uint64_t
+bitReverse(uint64_t val)
+{
+    val = (((val & 0xaaaaaaaaaaaaaaaa) >> 1)
+        | ((val & 0x5555555555555555) << 1));
+    val = (((val & 0xcccccccccccccccc) >> 2)
+        | ((val & 0x3333333333333333) << 2));
+    val = (((val & 0xf0f0f0f0f0f0f0f0) >> 4)
+        | ((val & 0x0f0f0f0f0f0f0f0f) << 4));
+    val = (((val & 0xff00ff00ff00ff00) >> 8)
+        | ((val & 0x00ff00ff00ff00ff) << 8));
+    val = (((val & 0xffff0000ffff0000) >> 16)
+        | ((val & 0x0000ffff0000ffff) << 16));
+
+    return ((val >> 32) | (val << 32));
+}

 #endif // __BASE_BITFIELD_HH__

--
To view, visit https://gem5-review.googlesource.com/10462
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: Icfd6f20c5c2b57d9d85d8d2013e5cd3c1632facc
Gerrit-Change-Number: 10462
Gerrit-PatchSet: 1
Gerrit-Owner: Anthony Gutierrez <anthony.gutier...@amd.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to