Update to v106r78 release.

byuu says:

I've implemented a lot more TLCS900H instructions. There are currently
20 missing spots, all of which are unique instructions (well, MINC and
MDEC could be considered pairs of 3 each), from a map of 1024 slots.

After that, I have to write the disassembler. Then the memory bus. Then
I get to start the fun process of debugging this monstrosity.

Also new is nall/inline-if.hpp. Note that this file is technically a war
crime, so be careful when opening it. This replaces ternary() from the
previous WIP.
This commit is contained in:
Tim Allen
2019-01-14 17:16:28 +11:00
parent bb1dd8c609
commit 6871e0e32a
29 changed files with 450 additions and 105 deletions

View File

@@ -23,8 +23,8 @@ template<typename T, typename U, typename... P> auto max(const T& t, const U& u,
return t > u ? max(t, forward<P>(p)...) : max(u, forward<P>(p)...);
}
template<typename T, typename U> auto ternary(bool test, const T& lhs, const U& rhs) -> T {
return test ? lhs : (T)rhs;
}
//template<typename T, typename U> auto ternary(bool test, const T& lhs, const U& rhs) -> T {
// return test ? lhs : (T)rhs;
//}
}}

10
nall/inline-if.hpp Normal file
View File

@@ -0,0 +1,10 @@
#pragma once
#define if1(statement) if(statement)
#define if2(condition, false) ([](auto&& value) -> decltype(condition) { \
return (bool)value ? value : (decltype(condition))false; \
})(condition)
#define if3(condition, true, false) ((condition) ? (true) : (decltype(true))(false))
#define if4(type, condition, true, false) ((condition) ? (type)(true) : (type)(false))
#define if_(_1, _2, _3, _4, name, ...) name
#define if(...) if_(__VA_ARGS__, if4, if3, if2, if1)(__VA_ARGS__)

View File

@@ -2,8 +2,8 @@
namespace nall {
template<int RequestedPrecision> struct BitRange {
enum : uint { Precision = RequestedPrecision < 1 ? 1 : RequestedPrecision > 64 ? 64 : RequestedPrecision };
template<int Requested> struct BitRange {
enum : uint { Precision = Requested < 1 ? 1 : Requested > 64 ? 64 : Requested };
static inline constexpr auto bits() -> uint { return Precision; }
using type =
typename conditional<bits() <= 8, uint8_t,
@@ -13,8 +13,13 @@ template<int RequestedPrecision> struct BitRange {
void>::type>::type>::type>::type;
static inline constexpr auto mask() -> type { return ~0ull >> 64 - bits(); }
inline BitRange(type& source, uint low, uint high)
: source(source), lo(low < high ? low : high), hi(high > low ? high : low) {}
inline BitRange(type& source, int lo, int hi) : source(source) {
if(lo < 0) lo = Precision + lo;
if(hi < 0) hi = Precision + hi;
if(lo > hi) swap(lo, hi);
this->lo = lo;
this->hi = hi;
}
inline auto& operator=(BitRange& source) { return set(source.get()); }
inline auto operator++(int) { auto value = get(); set(value + 1); return value; }
@@ -23,7 +28,7 @@ template<int RequestedPrecision> struct BitRange {
inline auto& operator++() { return set(get() + 1); }
inline auto& operator--() { return set(get() - 1); }
inline operator uint64_t() const { return get(); }
inline operator type() const { return get(); }
template<typename T> inline auto& operator =(const T& value) { return set( value); }
template<typename T> inline auto& operator *=(const T& value) { return set(get() * value); }
template<typename T> inline auto& operator /=(const T& value) { return set(get() / value); }
@@ -37,7 +42,7 @@ template<int RequestedPrecision> struct BitRange {
template<typename T> inline auto& operator |=(const T& value) { return set(get() | value); }
private:
inline auto get() const -> uint64_t {
inline auto get() const -> type {
const type rangeBits = hi - lo + 1;
const type rangeMask = (1ull << rangeBits) - 1 << lo & mask();
return (source & rangeMask) >> lo;
@@ -51,8 +56,8 @@ private:
}
type& source;
const uint lo;
const uint hi;
uint lo;
uint hi;
};
}

View File

@@ -2,8 +2,8 @@
namespace nall {
template<int RequestedPrecision> struct Integer {
enum : uint { Precision = RequestedPrecision < 1 ? 1 : RequestedPrecision > 64 ? 64 : RequestedPrecision };
template<int Requested> struct Integer {
enum : uint { Precision = Requested < 1 ? 1 : Requested > 64 ? 64 : Requested };
static inline constexpr auto bits() -> uint { return Precision; }
using type =
typename conditional<bits() <= 8, int8_t,
@@ -11,14 +11,13 @@ template<int RequestedPrecision> struct Integer {
typename conditional<bits() <= 32, int32_t,
typename conditional<bits() <= 64, int64_t,
void>::type>::type>::type>::type;
using utype = typename Natural<RequestedPrecision>::type;
using utype = typename Natural<Requested>::type;
static inline constexpr auto mask() -> utype { return ~0ull >> 64 - bits(); }
static inline constexpr auto sign() -> utype { return 1ull << Precision - 1; }
inline Integer() : data(0) {}
template<typename T> inline Integer(const T& value) { data = mask(value); }
explicit inline operator bool() const { return (bool)data; }
inline operator type() const { return data; }
inline auto operator++(int) { auto value = *this; data = mask(data + 1); return value; }
@@ -48,36 +47,31 @@ template<int RequestedPrecision> struct Integer {
#undef lhs
#undef rfs
inline auto serialize(serializer& s) { s(data); }
inline auto bits(int lo, int hi) -> BitRange<Requested> { return {(utype&)data, lo, hi}; }
inline auto bit(int index) -> BitRange<Requested> { return {(utype&)data, index, index}; }
inline auto byte(int index) -> BitRange<Requested> { return {(utype&)data, index * 8 + 0, index * 8 + 7}; }
inline auto zero() const -> bool { return data == 0; }
inline auto positive() const -> bool { return data >= 0; }
inline auto negative() const -> bool { return data < 0; }
inline auto bits(int lo, int hi) const -> const BitRange<Requested> { return {(utype&)*this, lo, lo}; }
inline auto bit(int index) const -> const BitRange<Requested> { return {(utype&)*this, index, index}; }
inline auto byte(int index) const -> const BitRange<Requested> { return {(utype&)*this, index * 8 + 0, index * 8 + 7}; }
inline auto bits(uint lo, uint hi) -> BitRange<RequestedPrecision> { return {(utype&)data, lo, hi}; }
inline auto bit(uint index) -> BitRange<RequestedPrecision> { return {(utype&)data, index, index}; }
inline auto byte(uint index) -> BitRange<RequestedPrecision> { return {(utype&)data, index * 8 + 0, index * 8 + 7}; }
inline auto bits(uint lo, uint hi) const -> const BitRange<RequestedPrecision> { return {(utype&)*this, lo, lo}; }
inline auto bit(uint index) const -> const BitRange<RequestedPrecision> { return {(utype&)*this, index, index}; }
inline auto byte(uint index) const -> const BitRange<RequestedPrecision> { return {(utype&)*this, index * 8 + 0, index * 8 + 7}; }
inline auto clamp(uint bits) -> intmax {
inline auto clamp(uint bits) -> type {
const intmax b = 1ull << (bits - 1);
const intmax m = b - 1;
return data > m ? m : data < -b ? -b : data;
}
inline auto clip(uint bits) -> intmax {
inline auto clip(uint bits) -> type {
const uintmax b = 1ull << (bits - 1);
const uintmax m = b * 2 - 1;
return ((data & m) ^ b) - b;
}
inline auto natural() const -> Natural<RequestedPrecision>;
inline auto serialize(serializer& s) { s(data); }
inline auto natural() const -> Natural<Requested>;
private:
auto mask(type value) const -> type {
inline auto mask(type value) const -> type {
return (value & mask() ^ sign()) - sign();
}

View File

@@ -2,8 +2,8 @@
namespace nall {
template<int RequestedPrecision> struct Natural {
enum : uint { Precision = RequestedPrecision < 1 ? 1 : RequestedPrecision > 64 ? 64 : RequestedPrecision };
template<int Requested> struct Natural {
enum : uint { Precision = Requested < 1 ? 1 : Requested > 64 ? 64 : Requested };
static inline constexpr auto bits() -> uint { return Precision; }
using type =
typename conditional<bits() <= 8, uint8_t,
@@ -16,7 +16,6 @@ template<int RequestedPrecision> struct Natural {
inline Natural() : data(0) {}
template<typename T> inline Natural(const T& value) { data = mask(value); }
explicit inline operator bool() const { return (bool)data; }
inline operator type() const { return data; }
inline auto operator++(int) { auto value = *this; data = mask(data + 1); return value; }
@@ -46,33 +45,28 @@ template<int RequestedPrecision> struct Natural {
#undef lhs
#undef rhs
inline auto serialize(serializer& s) { s(data); }
inline auto bits(int lo, int hi) -> BitRange<Requested> { return {(type&)data, lo, hi}; }
inline auto bit(int index) -> BitRange<Requested> { return {(type&)data, index, index}; }
inline auto byte(int index) -> BitRange<Requested> { return {(type&)data, index * 8 + 0, index * 8 + 7}; }
inline auto zero() const -> bool { return data == 0; }
inline auto positive() const -> bool { return data >> bits() - 1 == 0; }
inline auto negative() const -> bool { return data >> bits() - 1 == 1; }
inline auto bits(int lo, int hi) const -> const BitRange<Requested> { return {(type&)data, lo, hi}; }
inline auto bit(int index) const -> const BitRange<Requested> { return {(type&)data, index, index}; }
inline auto byte(int index) const -> const BitRange<Requested> { return {(type&)data, index * 8 + 0, index * 8 + 7}; }
inline auto bits(uint lo, uint hi) -> BitRange<RequestedPrecision> { return {(type&)data, lo, hi}; }
inline auto bit(uint index) -> BitRange<RequestedPrecision> { return {(type&)data, index, index}; }
inline auto byte(uint index) -> BitRange<RequestedPrecision> { return {(type&)data, index * 8 + 0, index * 8 + 7}; }
inline auto bits(uint lo, uint hi) const -> const BitRange<RequestedPrecision> { return {(type&)data, lo, hi}; }
inline auto bit(uint index) const -> const BitRange<RequestedPrecision> { return {(type&)data, index, index}; }
inline auto byte(uint index) const -> const BitRange<RequestedPrecision> { return {(type&)data, index * 8 + 0, index * 8 + 7}; }
inline auto clamp(uint bits) -> uintmax {
inline auto clamp(uint bits) -> type {
const uintmax b = 1ull << (bits - 1);
const uintmax m = b * 2 - 1;
return data < m ? data : m;
}
inline auto clip(uint bits) -> uintmax {
inline auto clip(uint bits) -> type {
const uintmax b = 1ull << (bits - 1);
const uintmax m = b * 2 - 1;
return data & m;
}
inline auto integer() const -> Integer<RequestedPrecision>;
inline auto serialize(serializer& s) { s(data); }
inline auto integer() const -> Integer<Requested>;
private:
inline auto mask(type value) const -> type {

View File

@@ -2,8 +2,8 @@
namespace nall {
template<int RequestedPrecision> struct Real {
enum : uint { Precision = RequestedPrecision <= 32 ? 32 : 64 };
template<int Requested> struct Real {
enum : uint { Precision = Requested <= 32 ? 32 : 64 };
static inline constexpr auto bits() -> uint { return Precision; }
using type =
typename conditional<bits() == 32, float32_t,
@@ -13,7 +13,6 @@ template<int RequestedPrecision> struct Real {
inline Real() : data(0.0) {}
template<typename T> inline Real(const T& value) : data((type)value) {}
explicit operator bool() const { return (bool)data; }
inline operator type() const { return data; }
inline auto operator++(int) { auto value = *this; ++data; return value; }
@@ -23,11 +22,11 @@ template<int RequestedPrecision> struct Real {
inline auto& operator--() { data--; return *this; }
template<typename T> inline auto& operator =(const T& value) { data = value; return *this; }
template<typename T> inline auto& operator+=(const T& value) { data = data + value; return *this; }
template<typename T> inline auto& operator-=(const T& value) { data = data - value; return *this; }
template<typename T> inline auto& operator*=(const T& value) { data = data * value; return *this; }
template<typename T> inline auto& operator/=(const T& value) { data = data / value; return *this; }
template<typename T> inline auto& operator%=(const T& value) { data = data % value; return *this; }
template<typename T> inline auto& operator+=(const T& value) { data = data + value; return *this; }
template<typename T> inline auto& operator-=(const T& value) { data = data - value; return *this; }
inline auto serialize(serializer& s) { s(data); }

View File

@@ -15,6 +15,7 @@ namespace nall {
using std::enable_if_t;
using std::false_type;
using std::is_floating_point;
using std::is_floating_point_v;
using std::forward;
using std::initializer_list;
using std::is_array;
@@ -23,8 +24,11 @@ namespace nall {
using std::is_integral;
using std::is_integral_v;
using std::is_same;
using std::is_same_v;
using std::is_signed;
using std::is_signed_v;
using std::is_unsigned;
using std::is_unsigned_v;
using std::move;
using std::nullptr_t;
using std::remove_extent;