Revision: 3910
Author: [email protected]
Date: Fri Feb 19 02:02:04 2010
Log: Make class BitField able to use 32 bits of a uint32.
Although algorithmically correct, the compiler would not allow to
instantiate
a BitField that uses all 32 bits without warnings about a too large shift
count. As a consequence we were limited to 31 bit values when using
BitField.
This happened when instantiating a bitfield BitField<T, shift, size> with
[shift=0, size=32] or [shift=31, size=1] or more general any
[shift=X, size=32-X]
As side-effect of the new implementation the compiler now warns if we ever
try instantiating a bitfield with size 0.
Review URL: http://codereview.chromium.org/606063
http://code.google.com/p/v8/source/detail?r=3910
Modified:
/branches/bleeding_edge/src/codegen.h
/branches/bleeding_edge/src/frame-element.h
/branches/bleeding_edge/src/objects.h
/branches/bleeding_edge/src/register-allocator.h
/branches/bleeding_edge/src/utils.h
=======================================
--- /branches/bleeding_edge/src/codegen.h Tue Feb 16 05:03:16 2010
+++ /branches/bleeding_edge/src/codegen.h Fri Feb 19 02:02:04 2010
@@ -518,14 +518,14 @@
}
#endif
- // Minor key encoding in 31 bits AAAAAAAAAAAAAAAAAAAAAFI
A(rgs)F(lag)I(nloop).
+ // Minor key encoding in 32 bits with Bitfield <Type, shift, size>.
class InLoopBits: public BitField<InLoopFlag, 0, 1> {};
class FlagBits: public BitField<CallFunctionFlags, 1, 1> {};
- class ArgcBits: public BitField<int, 2, 29> {};
+ class ArgcBits: public BitField<int, 2, 32 - 2> {};
Major MajorKey() { return CallFunction; }
int MinorKey() {
- // Encode the parameters in a unique 31 bit value.
+ // Encode the parameters in a unique 32 bit value.
return InLoopBits::encode(in_loop_)
| FlagBits::encode(flags_)
| ArgcBits::encode(argc_);
=======================================
--- /branches/bleeding_edge/src/frame-element.h Tue Feb 16 05:03:16 2010
+++ /branches/bleeding_edge/src/frame-element.h Fri Feb 19 02:02:04 2010
@@ -250,7 +250,7 @@
class CopiedField: public BitField<bool, 3, 1> {};
class SyncedField: public BitField<bool, 4, 1> {};
class NumberInfoField: public BitField<NumberInfo::Type, 5, 3> {};
- class DataField: public BitField<uint32_t, 8, 32 - 9> {};
+ class DataField: public BitField<uint32_t, 8, 32 - 8> {};
friend class VirtualFrame;
};
=======================================
--- /branches/bleeding_edge/src/objects.h Thu Feb 18 09:30:32 2010
+++ /branches/bleeding_edge/src/objects.h Fri Feb 19 02:02:04 2010
@@ -179,7 +179,7 @@
class TypeField: public BitField<PropertyType, 0, 3> {};
class AttributesField: public BitField<PropertyAttributes, 3, 3> {};
class DeletedField: public BitField<uint32_t, 6, 1> {};
- class IndexField: public BitField<uint32_t, 7, 31-7> {};
+ class IndexField: public BitField<uint32_t, 7, 32-7> {};
static const int kInitialIndex = 1;
private:
=======================================
--- /branches/bleeding_edge/src/register-allocator.h Mon Feb 15 06:24:38
2010
+++ /branches/bleeding_edge/src/register-allocator.h Fri Feb 19 02:02:04
2010
@@ -141,7 +141,7 @@
class TypeField: public BitField<Type, 0, 2> {};
class NumberInfoField : public BitField<NumberInfo::Type, 2, 3> {};
- class DataField: public BitField<uint32_t, 5, 32 - 6> {};
+ class DataField: public BitField<uint32_t, 5, 32 - 5> {};
inline void CopyTo(Result* destination) const;
=======================================
--- /branches/bleeding_edge/src/utils.h Thu Feb 18 04:47:17 2010
+++ /branches/bleeding_edge/src/utils.h Fri Feb 19 02:02:04 2010
@@ -157,7 +157,9 @@
// Returns a uint32_t mask of bit field.
static uint32_t mask() {
- return (1U << (size + shift)) - (1U << shift);
+ // 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);
}
// Returns a uint32_t with the bit field value encoded.
@@ -168,7 +170,7 @@
// Extracts the bit field from the value.
static T decode(uint32_t value) {
- return static_cast<T>((value >> shift) & ((1U << (size)) - 1));
+ return static_cast<T>((value & mask()) >> shift);
}
};
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev