cursed bit slice helper
This commit is contained in:
@@ -14,7 +14,20 @@ using s64 = int64_t;
|
|||||||
using u128 = __uint128_t;
|
using u128 = __uint128_t;
|
||||||
using s128 = __int128_t;
|
using s128 = __int128_t;
|
||||||
using m128 = __m128i;
|
using m128 = __m128i;
|
||||||
|
|
||||||
#define UINT128_MAX ((u128)0xFFFF'FFFF'FFFF'FFFF << 64) | 0xFFFF'FFFF'FFFF'FFFF
|
#define UINT128_MAX ((u128)0xFFFF'FFFF'FFFF'FFFF << 64) | 0xFFFF'FFFF'FFFF'FFFF
|
||||||
#define UINT128_MIN 0
|
#define UINT128_MIN 0
|
||||||
#define INT128_MAX ((u128)0x7FFF'FFFF'FFFF'FFFF << 64) | 0xFFFF'FFFF'FFFF'FFFF
|
#define INT128_MAX ((u128)0x7FFF'FFFF'FFFF'FFFF << 64) | 0xFFFF'FFFF'FFFF'FFFF
|
||||||
#define INT128_MIN (-INT128_MAX - 1LL)
|
#define INT128_MIN (-INT128_MAX - 1LL)
|
||||||
|
|
||||||
|
template <u8 start, u8 end>
|
||||||
|
using BitSliceType =
|
||||||
|
std::conditional<(end - start) <= 7, u8,
|
||||||
|
std::conditional<(end - start) <= 15, u16,
|
||||||
|
std::conditional<(end - start) <= 31, u32,
|
||||||
|
std::conditional<(end - start) <= 63, u64,
|
||||||
|
std::conditional<(end - start) <= 127, u128, u128>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>;
|
||||||
|
|||||||
@@ -2,5 +2,33 @@
|
|||||||
#include <common.hpp>
|
#include <common.hpp>
|
||||||
|
|
||||||
namespace natsukashii::core {
|
namespace natsukashii::core {
|
||||||
struct Cpu {};
|
template <class A, class B>
|
||||||
|
struct RegisterPair {
|
||||||
|
A low;
|
||||||
|
B high;
|
||||||
|
auto operator=(const u16& rhs) {
|
||||||
|
low = rhs & 0xff;
|
||||||
|
high = rhs >> 8;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
union RegF {
|
||||||
|
struct {
|
||||||
|
unsigned z:1;
|
||||||
|
unsigned n:1;
|
||||||
|
unsigned h:1;
|
||||||
|
unsigned c:1;
|
||||||
|
unsigned:4;
|
||||||
|
};
|
||||||
|
u8 raw;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Cpu {
|
||||||
|
private:
|
||||||
|
RegisterPair<u8, RegF> af;
|
||||||
|
RegisterPair<u8, u8> bc;
|
||||||
|
RegisterPair<u8, u8> de;
|
||||||
|
RegisterPair<u8, u8> hl;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
12
src/core/util.hpp
Normal file
12
src/core/util.hpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <common.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace natsukashii::util {
|
||||||
|
template <u8 start, u8 end, typename T>
|
||||||
|
BitSliceType<start, end> BitSlice(const T& num) {
|
||||||
|
static_assert(end - start > 127);
|
||||||
|
static_assert(end - start > sizeof(T));
|
||||||
|
return (num >> start) & ((1 << end) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user