| 479 | // where S is the highest bit in 'bitfield'. |
| 480 | template <typename T> |
| 481 | inline static constexpr T BitFieldExtract(T value, size_t lsb, size_t width) { |
| 482 | DCHECK_GE(BitSizeOf(value), lsb + width) << "Bit field out of range for value"; |
| 483 | const auto val = static_cast<std::make_unsigned_t<T>>(value); |
| 484 | |
| 485 | const T bitfield_unsigned = |
| 486 | static_cast<T>((val >> lsb) & MaskLeastSignificant<T>(width)); |
| 487 | if (std::is_signed<T>::value) { |
| 488 | // Perform sign extension |
| 489 | if (width == 0) { // Avoid underflow. |
| 490 | return static_cast<T>(0); |
| 491 | } else if (bitfield_unsigned & (1 << (width - 1))) { // Detect if sign bit was set. |
| 492 | // MSB <width> LSB |
| 493 | // 0b11111...100...000000 |
| 494 | const auto ones_negmask = ~MaskLeastSignificant<T>(width); |
| 495 | return static_cast<T>(bitfield_unsigned | ones_negmask); |
| 496 | } |
| 497 | } |
| 498 | // Skip sign extension. |
| 499 | return bitfield_unsigned; |
| 500 | } |
| 501 | |
| 502 | } // namespace art_lkchan |
| 503 |
nothing calls this directly
no test coverage detected