| 442 | |
| 443 | template <typename T, typename T2> |
| 444 | inline 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). |
nothing calls this directly
no test coverage detected