If we tried to get/set something that was exactly 64 bits, we would
try to do (1 << 64) - 1 to calculate the mask which doesn't give us all
1's like we want.
v2 (Iago)
- Replace ~0 by ~0ull
- Removed unnecessary parenthesis
v3 (Kristian)
- Avoid the conditional
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Reviewed-by: Matt Turner <mattst88@gmail.com>
Reviewed-by: Kristian Høgsberg <krh@bitplanet.net>
high %= 64;
low %= 64;
- const uint64_t mask = (1ull << (high - low + 1)) - 1;
+ const uint64_t mask = (~0ul >> (64 - (high - low + 1)));
return (inst->data[word] >> low) & mask;
}
high %= 64;
low %= 64;
- const uint64_t mask = ((1ull << (high - low + 1)) - 1) << low;
+ const uint64_t mask = (~0ul >> (64 - (high - low + 1))) << low;
/* Make sure the supplied value actually fits in the given bitfield. */
assert((value & (mask >> low)) == value);