/* Truncate value to decr_width and sign extend for simplicity */
- value &= ((1ULL << nr_bits) - 1);
+ value = sextract64(value, 0, nr_bits);
negative = !!(value & (1ULL << (nr_bits - 1)));
if (negative) {
value |= (0xFFFFFFFFULL << nr_bits);
I think these lines that say "if negative then force all the
high bits to one" are also no longer required. That is, this
entire section of code:
value &= ((1ULL << nr_bits) - 1);
negative = !!(value & (1ULL << (nr_bits - 1)));
if (negative) {
value |= (0xFFFFFFFFULL << nr_bits);
}
is an open-coded sign-extension, which can all be replaced with
the single line
value = sextract64(value, 0, nr_bits);