mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-01-07 06:58:15 +01:00
A64: Implement logical
This commit is contained in:
parent
5a1d88c5dc
commit
0641445e51
13 changed files with 499 additions and 26 deletions
|
|
@ -9,6 +9,7 @@
|
|||
#include <bitset>
|
||||
#include <climits>
|
||||
#include <cstddef>
|
||||
#include <type_traits>
|
||||
|
||||
#include "common/assert.h"
|
||||
|
||||
|
|
@ -86,5 +87,37 @@ inline size_t BitCount(Integral value) {
|
|||
return std::bitset<BitSize<Integral>()>(value).count();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline int HighestSetBit(T value) {
|
||||
auto x = static_cast<std::make_unsigned_t<T>>(value);
|
||||
int result = -1;
|
||||
while (x != 0) {
|
||||
x >>= 1;
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T Ones(size_t count) {
|
||||
ASSERT_MSG(count <= BitSize<T>(), "count larger than bitsize of T");
|
||||
return ~(~static_cast<T>(0) << count);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T Replicate(T value, size_t element_size) {
|
||||
ASSERT_MSG(BitSize<T>() % element_size == 0, "bitsize of T not divisible by element_size");
|
||||
if (element_size == BitSize<T>())
|
||||
return value;
|
||||
return Replicate(value | (value << element_size), element_size * 2);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T RotateRight(T value, size_t amount) {
|
||||
amount %= BitSize<T>();
|
||||
auto x = static_cast<std::make_unsigned_t<T>>(value);
|
||||
return static_cast<T>((x >> amount) | (x << (BitSize<T>() - amount)));
|
||||
}
|
||||
|
||||
} // namespace Common
|
||||
} // namespace Dynarmic
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue