mirror of
https://github.com/TomHarte/CLK.git
synced 2025-04-09 15:39:08 +00:00
Test, improve BitStream.
This commit is contained in:
parent
88ffcbc62b
commit
9162c86e21
@ -46,8 +46,8 @@ template <
|
||||
> class CachingExecutor {
|
||||
public:
|
||||
using Performer = void (Executor::*)();
|
||||
using PerformerIndex = typename MinIntTypeValue<max_performer_count>::type;
|
||||
using ProgramCounterType = typename MinIntTypeValue<max_address>::type;
|
||||
using PerformerIndex = min_int_for_value_t<max_performer_count>;
|
||||
using ProgramCounterType = min_int_for_value_t<max_address>;
|
||||
|
||||
// MARK: - Parser call-ins.
|
||||
|
||||
|
@ -29,7 +29,7 @@ template <
|
||||
typename AddressType
|
||||
> class Disassembler {
|
||||
public:
|
||||
using ProgramCounterType = typename MinIntTypeValue<max_address>::type;
|
||||
using ProgramCounterType = min_int_for_value_t<max_address>;
|
||||
|
||||
/*!
|
||||
Adds the result of disassembling @c memory which is @c length @c MemoryWords long from @c start_address
|
||||
|
@ -54,9 +54,9 @@ private:
|
||||
// integer size large enough to hold all actual operations plus the ephemeral
|
||||
// ones used here. Intention is to support table-based decoding, which will mean
|
||||
// making those integers less ephemeral, hence the desire to pick a minimum size.
|
||||
using OpT = typename MinIntTypeValue<
|
||||
using OpT = min_int_for_value_t<
|
||||
uint64_t(OperationMax<model>::value) + 67
|
||||
>::type;
|
||||
>;
|
||||
static constexpr auto OpMax = OpT(OperationMax<model>::value);
|
||||
|
||||
// Specific instruction decoders.
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
#include "BitReverse.hpp"
|
||||
#include "Sizes.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
namespace Numeric {
|
||||
@ -23,7 +25,7 @@ namespace Numeric {
|
||||
template <int max_bits, bool lsb_first>
|
||||
class BitStream {
|
||||
public:
|
||||
using IntT = min_int_size_t<max_bits + 8>;
|
||||
using IntT = min_int_for_bits_t<max_bits>;
|
||||
|
||||
BitStream(std::function<uint8_t(void)> next_byte) : next_byte_(next_byte) {}
|
||||
|
||||
@ -33,6 +35,9 @@ public:
|
||||
/// `rbits` is ignored if `bits` is non-zero.
|
||||
template <size_t bits = 0>
|
||||
IntT next([[maybe_unused]] const size_t rbits = 0) {
|
||||
static_assert(bits <= max_bits);
|
||||
static constexpr size_t ShiftBitSize = sizeof(ShiftIntT) * 8;
|
||||
|
||||
const size_t required = bits ? bits : rbits;
|
||||
while(enqueued_ < required) {
|
||||
uint8_t next = next_byte_();
|
||||
@ -40,11 +45,11 @@ public:
|
||||
next = bit_reverse(next);
|
||||
}
|
||||
|
||||
input_ |= IntT(next) << (BitSize - 8 - enqueued_);
|
||||
input_ |= ShiftIntT(next) << (ShiftBitSize - 8 - enqueued_);
|
||||
enqueued_ += 8;
|
||||
}
|
||||
|
||||
const auto result = IntT(input_ >> (BitSize - required));
|
||||
const auto result = IntT(input_ >> (ShiftBitSize - required));
|
||||
input_ <<= required;
|
||||
enqueued_ -= required;
|
||||
return result;
|
||||
@ -53,10 +58,9 @@ public:
|
||||
private:
|
||||
std::function<uint8_t(void)> next_byte_;
|
||||
|
||||
using ShiftIntT = min_int_for_bits_t<max_bits + 7>;
|
||||
ShiftIntT input_{};
|
||||
size_t enqueued_{};
|
||||
|
||||
IntT input_{};
|
||||
static constexpr size_t BitSize = sizeof(IntT) * 8;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -77,6 +77,6 @@ private:
|
||||
IntType value_ = 0;
|
||||
};
|
||||
|
||||
template <uint64_t polynomial> class LFSRv: public LFSR<typename MinIntTypeValue<polynomial>::type, polynomial> {};
|
||||
template <uint64_t polynomial> class LFSRv: public LFSR<min_int_for_value_t<polynomial>, polynomial> {};
|
||||
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ template <int size> using uint_t = typename uint_t_impl<size>::type;
|
||||
* uint64_t.
|
||||
*/
|
||||
template <uint64_t max_value>
|
||||
struct MinIntTypeValue {
|
||||
struct MinIntForValue {
|
||||
using type =
|
||||
std::conditional_t<
|
||||
max_value <= std::numeric_limits<uint8_t>::max(), uint8_t,
|
||||
@ -43,7 +43,7 @@ struct MinIntTypeValue {
|
||||
>
|
||||
>;
|
||||
};
|
||||
template <uint64_t max_value> using min_int_value_t = typename MinIntTypeValue<max_value>::type;
|
||||
template <uint64_t max_value> using min_int_for_value_t = typename MinIntForValue<max_value>::type;
|
||||
|
||||
/*!
|
||||
Maps to the smallest integral type that can hold at least `max_bits` bits, from the following options:
|
||||
@ -53,19 +53,25 @@ template <uint64_t max_value> using min_int_value_t = typename MinIntTypeValue<m
|
||||
* uint32_t; or
|
||||
* uint64_t.
|
||||
*/
|
||||
template <int max_bits>
|
||||
struct MinIntTypeSize {
|
||||
static_assert(max_bits <= 64, "Only integers up to 64 bits are supported");
|
||||
template <int min_bits>
|
||||
struct MinIntForBits {
|
||||
static_assert(min_bits <= 64, "Only integers up to 64 bits are supported");
|
||||
using type =
|
||||
std::conditional_t<
|
||||
max_bits <= 8, uint8_t,
|
||||
min_bits <= 8, uint8_t,
|
||||
std::conditional_t<
|
||||
max_bits <= 16, uint16_t,
|
||||
min_bits <= 16, uint16_t,
|
||||
std::conditional_t<
|
||||
max_bits <= 32, uint32_t,
|
||||
min_bits <= 32, uint32_t,
|
||||
uint64_t
|
||||
>
|
||||
>
|
||||
>;
|
||||
};
|
||||
template <uint64_t max_value> using min_int_size_t = typename MinIntTypeValue<max_value>::type;
|
||||
template <int min_bits> using min_int_for_bits_t = typename MinIntForBits<min_bits>::type;
|
||||
|
||||
static_assert(std::is_same_v<min_int_for_bits_t<7>, uint8_t>);
|
||||
static_assert(std::is_same_v<min_int_for_bits_t<8>, uint8_t>);
|
||||
static_assert(std::is_same_v<min_int_for_bits_t<9>, uint16_t>);
|
||||
static_assert(std::is_same_v<min_int_for_bits_t<16>, uint16_t>);
|
||||
static_assert(std::is_same_v<min_int_for_bits_t<17>, uint32_t>);
|
||||
|
@ -235,6 +235,7 @@
|
||||
4B0ACC3123775819008902D0 /* TIASound.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0ACC2123775819008902D0 /* TIASound.cpp */; };
|
||||
4B0ACC3223775819008902D0 /* Atari2600.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0ACC2223775819008902D0 /* Atari2600.cpp */; };
|
||||
4B0ACC3323775819008902D0 /* Atari2600.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0ACC2223775819008902D0 /* Atari2600.cpp */; };
|
||||
4B0B23A12D6826DE00153879 /* NumericTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4B0B23A02D6826DE00153879 /* NumericTests.mm */; };
|
||||
4B0CCC451C62D0B3001CAC5F /* CRT.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0CCC421C62D0B3001CAC5F /* CRT.cpp */; };
|
||||
4B0DA67B282DCDF100C12F17 /* Instruction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0DA67A282DCC4200C12F17 /* Instruction.cpp */; };
|
||||
4B0DA67C282DCDF300C12F17 /* Instruction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0DA67A282DCC4200C12F17 /* Instruction.cpp */; };
|
||||
@ -1372,6 +1373,7 @@
|
||||
4B0ACC2423775819008902D0 /* PIA.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = PIA.hpp; sourceTree = "<group>"; };
|
||||
4B0ACC2523775819008902D0 /* TIA.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = TIA.hpp; sourceTree = "<group>"; };
|
||||
4B0B239F2D658C9400153879 /* BitStream.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = BitStream.hpp; sourceTree = "<group>"; };
|
||||
4B0B23A02D6826DE00153879 /* NumericTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = NumericTests.mm; sourceTree = "<group>"; };
|
||||
4B0CCC421C62D0B3001CAC5F /* CRT.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CRT.cpp; sourceTree = "<group>"; };
|
||||
4B0CCC431C62D0B3001CAC5F /* CRT.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CRT.hpp; sourceTree = "<group>"; };
|
||||
4B0DA67A282DCC4200C12F17 /* Instruction.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Instruction.cpp; sourceTree = "<group>"; };
|
||||
@ -4702,6 +4704,7 @@
|
||||
4BA91E1C216D85BA00F79557 /* MasterSystemVDPTests.mm */,
|
||||
4BC6237126F94BCB00F83DFE /* MintermTests.mm */,
|
||||
4B98A0601FFADCDE00ADF63B /* MSXStaticAnalyserTests.mm */,
|
||||
4B0B23A02D6826DE00153879 /* NumericTests.mm */,
|
||||
4BC0CB272446BC7B00A79DBB /* OPLTests.mm */,
|
||||
4B121F9A1E06293F00BFDA12 /* PCMSegmentEventSourceTests.mm */,
|
||||
4BD4A8CF1E077FD20020D856 /* PCMTrackTests.mm */,
|
||||
@ -6631,6 +6634,7 @@
|
||||
4B06AB022C6460CB0034D014 /* Typer.cpp in Sources */,
|
||||
4BA91E1D216D85BA00F79557 /* MasterSystemVDPTests.mm in Sources */,
|
||||
4B98A0611FFADCDE00ADF63B /* MSXStaticAnalyserTests.mm in Sources */,
|
||||
4B0B23A12D6826DE00153879 /* NumericTests.mm in Sources */,
|
||||
4BE34438238389E10058E78F /* AtariSTVideoTests.mm in Sources */,
|
||||
4BEF6AAC1D35D1C400E73575 /* DPLLTests.swift in Sources */,
|
||||
4BE76CF922641ED400ACD6FA /* QLTests.mm in Sources */,
|
||||
|
Loading…
x
Reference in New Issue
Block a user