Optimizing: Reduce memory usage of HInstructions.
Pack narrow fields and flags into a single 32-bit field.
Change-Id: Ib2f7abf987caee0339018d21f0d498f8db63542d
diff --git a/runtime/base/bit_field.h b/runtime/base/bit_field.h
index fd65d50..a80ca28 100644
--- a/runtime/base/bit_field.h
+++ b/runtime/base/bit_field.h
@@ -26,9 +26,18 @@
// BitField is a template for encoding and decoding a bit field inside
// an unsigned machine word.
-template<typename T, int position, int size>
+template<typename T, size_t kPosition, size_t kSize>
class BitField {
public:
+ typedef T value_type;
+ static constexpr size_t position = kPosition;
+ static constexpr size_t size = kSize;
+
+ static_assert(position < sizeof(uintptr_t) * kBitsPerByte, "Invalid position.");
+ static_assert(size != 0u, "Invalid size.");
+ static_assert(size <= sizeof(uintptr_t) * kBitsPerByte, "Invalid size.");
+ static_assert(size + position <= sizeof(uintptr_t) * kBitsPerByte, "Invalid position + size.");
+
// Tells whether the provided value fits into the bit field.
static bool IsValid(T value) {
return (static_cast<uintptr_t>(value) & ~((kUintPtrTOne << size) - 1)) == 0;
diff --git a/runtime/primitive.h b/runtime/primitive.h
index ca42c47..2454a21 100644
--- a/runtime/primitive.h
+++ b/runtime/primitive.h
@@ -46,6 +46,7 @@
kPrimFloat,
kPrimDouble,
kPrimVoid,
+ kPrimLast = kPrimVoid
};
static Type GetType(char type) {