summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins/Process/Utility/InstructionUtils.h
diff options
context:
space:
mode:
authorJohnny Chen <johnny.chen@apple.com>2011-01-26 01:00:55 +0000
committerJohnny Chen <johnny.chen@apple.com>2011-01-26 01:00:55 +0000
commit74889b29a8a070b40d6584f6a4c95fa4fb196d27 (patch)
tree8ca3c82cd3b03a86e129917853517bda7cf8dc31 /lldb/source/Plugins/Process/Utility/InstructionUtils.h
parent9312fcc2d397f05d942c8b678725ab1942e6f8f9 (diff)
downloadbcm5719-llvm-74889b29a8a070b40d6584f6a4c95fa4fb196d27.tar.gz
bcm5719-llvm-74889b29a8a070b40d6584f6a4c95fa4fb196d27.zip
Move the generic instruction bits manipulation routines into a newly created file
named InstructionUtils.h and modify some existing code to use them. llvm-svn: 124259
Diffstat (limited to 'lldb/source/Plugins/Process/Utility/InstructionUtils.h')
-rw-r--r--lldb/source/Plugins/Process/Utility/InstructionUtils.h78
1 files changed, 78 insertions, 0 deletions
diff --git a/lldb/source/Plugins/Process/Utility/InstructionUtils.h b/lldb/source/Plugins/Process/Utility/InstructionUtils.h
new file mode 100644
index 00000000000..1dc3febb866
--- /dev/null
+++ b/lldb/source/Plugins/Process/Utility/InstructionUtils.h
@@ -0,0 +1,78 @@
+//===-- lldb_InstructionUtils.h ---------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef lldb_InstructionUtils_h_
+#define lldb_InstructionUtils_h_
+
+// Common utilities for manipulating instruction bit fields.
+
+namespace lldb_private {
+
+static inline uint32_t
+Bits32 (const uint32_t value, const uint32_t msbit, const uint32_t lsbit)
+{
+ assert(msbit < 32 && lsbit <= msbit);
+ return (value >> lsbit) & ((1u << (msbit - lsbit + 1)) - 1);
+}
+
+// Create a mask that starts at bit zero and includes "bit"
+static inline uint64_t
+MaskUpToBit (const uint64_t bit)
+{
+ return (1ull << (bit + 1ull)) - 1ull;
+}
+
+// Returns an integer result equal to the number of bits of x that are ones.
+static inline uint32_t
+BitCount (uint64_t x)
+{
+ // c accumulates the total bits set in x
+ uint32_t c;
+ for (c = 0; x; ++c)
+ {
+ x &= x - 1; // clear the least significant bit set
+ }
+ return c;
+}
+
+static inline bool
+BitIsSet (const uint64_t value, const uint64_t bit)
+{
+ return (value & (1ull << bit)) != 0;
+}
+
+static inline bool
+BitIsClear (const uint64_t value, const uint64_t bit)
+{
+ return (value & (1ull << bit)) == 0;
+}
+
+static inline uint64_t
+UnsignedBits (const uint64_t value, const uint64_t msbit, const uint64_t lsbit)
+{
+ uint64_t result = value >> lsbit;
+ result &= MaskUpToBit (msbit - lsbit);
+ return result;
+}
+
+static inline int64_t
+SignedBits (const uint64_t value, const uint64_t msbit, const uint64_t lsbit)
+{
+ uint64_t result = UnsignedBits (value, msbit, lsbit);
+ if (BitIsSet(value, msbit))
+ {
+ // Sign extend
+ result |= ~MaskUpToBit (msbit - lsbit);
+ }
+ return result;
+}
+
+} // namespace lldb_private
+
+#endif // lldb_InstructionUtils_h_
OpenPOWER on IntegriCloud