// BitField is a template for encoding and decoding a bit field inside // an unsigned machine word. template<typename T, size_t kPosition, size_t kSize> class BitField { public: using value_type = T; static constexpr size_t position = kPosition; static constexpr size_t size = kSize;
// Tells whether the provided value fits into the bit field. static constexpr bool IsValid(T value) { return (static_cast<uintptr_t>(value) & ~Mask()) == 0;
}
// Returns a uword mask of the bit field. static constexpr uintptr_t Mask() { return (size == sizeof(uintptr_t) * kBitsPerByte)
? static_cast<uintptr_t>(-1)
: (static_cast<uintptr_t>(1u) << size) - 1u;
}
// Returns a uword mask of the bit field which can be applied directly to // the raw unshifted bits. static constexpr uintptr_t MaskInPlace() { return Mask() << position;
}
// Returns the shift count needed to right-shift the bit field to // the least-significant bits. static constexpr int Shift() { return position;
}
// Returns the size of the bit field. static constexpr int BitSize() { return size;
}
// Returns a uword with the bit field value encoded. static constexpr uintptr_t Encode(T value) {
DCHECK(IsValid(value)); returnstatic_cast<uintptr_t>(value) << position;
}
// Extracts the bit field from the value. static constexpr T Decode(uintptr_t value) { returnstatic_cast<T>((value >> position) & Mask());
}
// Returns a uword with the bit field value encoded based on the // original value. Only the bits corresponding to this bit field // will be changed. static constexpr uintptr_t Update(T value, uintptr_t original) {
DCHECK(IsValid(value)); return (static_cast<uintptr_t>(value) << position) |
(~MaskInPlace() & original);
}
};
} // namespace art
#endif// ART_LIBARTBASE_BASE_BIT_FIELD_H_
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.