summaryrefslogtreecommitdiff
path: root/src/base
diff options
context:
space:
mode:
authorGabe Black <gblack@eecs.umich.edu>2006-10-27 02:34:26 -0400
committerGabe Black <gblack@eecs.umich.edu>2006-10-27 02:34:26 -0400
commitf985b752d352b1f4bb253ad2372955f4caed72ea (patch)
tree209a3fc534dc357aa0217bffba70127cc7767874 /src/base
parent2f30c2b4c982b61b393a2888c022fbeac3225d59 (diff)
parentca34c62bf96b66fdb1aefc3b08cad8d969ee6bc9 (diff)
downloadgem5-f985b752d352b1f4bb253ad2372955f4caed72ea.tar.xz
Merge zizzer.eecs.umich.edu:/bk/newmem
into zeep.eecs.umich.edu:/home/gblack/m5/newmem --HG-- extra : convert_revision : ec35a9276ae21e0b9fe820bd700c020e4440a350
Diffstat (limited to 'src/base')
-rw-r--r--src/base/bitfield.hh24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/base/bitfield.hh b/src/base/bitfield.hh
index 879780d56..177279678 100644
--- a/src/base/bitfield.hh
+++ b/src/base/bitfield.hh
@@ -69,4 +69,28 @@ sext(uint64_t val)
return sign_bit ? (val | ~mask(N)) : val;
}
+/**
+ * Return val with bits first to last set to bit_val
+ */
+template <class T, class B>
+inline
+T
+insertBits(T val, int first, int last, B bit_val)
+{
+ T bmask = mask(first - last + 1) << last;
+ return ((bit_val << last) & bmask) | (val & ~bmask);
+}
+
+/**
+ * A convenience function to replace bits first to last of val with bit_val
+ * in place.
+ */
+template <class T, class B>
+inline
+void
+replaceBits(T& val, int first, int last, B bit_val)
+{
+ val = insertBits(val, first, last, bit_val);
+}
+
#endif // __BASE_BITFIELD_HH__