bit_util: Do nothing in RotateRight if the rotation amount is zero
Without this sanitizing it's possible to perform a shift with a shift amount that's the same size as the type being shifted. This actually occurs when decoding ORR variants. We could get fancier here and make this branchless, but we don't really use RotateRight in any performance intensive areas.
This commit is contained in:
parent
e537985584
commit
aa92e33194
@ -130,6 +130,11 @@ inline T Replicate(T value, size_t element_size) {
|
||||
template <typename T>
|
||||
inline T RotateRight(T value, size_t amount) {
|
||||
amount %= BitSize<T>();
|
||||
|
||||
if (amount == 0) {
|
||||
return value;
|
||||
}
|
||||
|
||||
auto x = static_cast<std::make_unsigned_t<T>>(value);
|
||||
return static_cast<T>((x >> amount) | (x << (BitSize<T>() - amount)));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user