MCPcopy Create free account
hub / github.com/CodingGay/BlackDex / BitFieldInsert

Function BitFieldInsert

Bcore/src/main/cpp/base/bit_utils.h:444–456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

442
443template <typename T, typename T2>
444inline static constexpr T BitFieldInsert(T value, T2 data, size_t lsb, size_t width) {
445 DCHECK_GE(BitSizeOf(value), lsb + width) << "Bit field out of range for value";
446 if (width != 0u) {
447 DCHECK_GE(MaxInt<T2>(width), data) << "Data out of range [too large] for bitwidth";
448 DCHECK_LE(MinInt<T2>(width), data) << "Data out of range [too small] for bitwidth";
449 } else {
450 DCHECK_EQ(static_cast<T2>(0), data) << "Data out of range [nonzero] for bitwidth 0";
451 }
452 const auto data_mask = MaskLeastSignificant<T2>(width);
453 const auto value_cleared = BitFieldClear(value, lsb, width);
454
455 return static_cast<T>(value_cleared | ((data & data_mask) << lsb));
456}
457
458// Extracts the bitfield starting at the least significant bit "lsb" with a bitwidth of 'width'.
459// Signed types are sign-extended during extraction. (Equivalent of ARM UBFX/SBFX instruction).

Callers

nothing calls this directly

Calls 2

BitSizeOfFunction · 0.85
BitFieldClearFunction · 0.85

Tested by

no test coverage detected