Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: src/utils.h

Issue 7787028: Use the BitField class for Code::Flags. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/stub-cache.cc ('k') | src/x64/ic-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils.h
diff --git a/src/utils.h b/src/utils.h
index edbace0bd7a422d458b2fe1b679e4ebf4ee55ac4..852a6ae26df81f198385f9afa9b89627a31f58c6 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -203,16 +203,17 @@ inline int StrLength(const char* string) {
template<class T, int shift, int size>
class BitField {
public:
+ // A uint32_t mask of bit field. To use all bits of a uint32 in a
+ // bitfield without compiler warnings we have to compute 2^32 without
+ // using a shift count of 32.
+ static const uint32_t kMask = ((1U << shift) << size) - (1U << shift);
+
+ // Value for the field with all bits set.
+ static const T kMax = static_cast<T>((1U << size) - 1);
+
// Tells whether the provided value fits into the bit field.
static bool is_valid(T value) {
- return (static_cast<uint32_t>(value) & ~((1U << (size)) - 1)) == 0;
- }
-
- // Returns a uint32_t mask of bit field.
- static uint32_t mask() {
- // To use all bits of a uint32 in a bitfield without compiler warnings we
- // have to compute 2^32 without using a shift count of 32.
- return ((1U << shift) << size) - (1U << shift);
+ return (static_cast<uint32_t>(value) & ~kMax) == 0;
}
// Returns a uint32_t with the bit field value encoded.
@@ -223,17 +224,12 @@ class BitField {
// Returns a uint32_t with the bit field value updated.
static uint32_t update(uint32_t previous, T value) {
- return (previous & ~mask()) | encode(value);
+ return (previous & ~kMask) | encode(value);
}
// Extracts the bit field from the value.
static T decode(uint32_t value) {
- return static_cast<T>((value & mask()) >> shift);
- }
-
- // Value for the field with all bits set.
- static T max() {
- return decode(mask());
+ return static_cast<T>((value & kMask) >> shift);
}
};
« no previous file with comments | « src/stub-cache.cc ('k') | src/x64/ic-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698