Remove the ComplexBitMap

This commit is contained in:
Jaby
2023-03-22 20:46:08 +01:00
committed by Jaby
parent 1829f1f5e3
commit 7d3d080129
13 changed files with 307 additions and 489 deletions

View File

@@ -4,49 +4,6 @@
#include "../../Auxiliary/types.hpp"
namespace JabyEngine {
struct IOBitUnset {
uint16_t pos;
constexpr IOBitUnset(uint16_t bit_pos) : pos(bit_pos) {
}
};
struct IOBitSet {
uint16_t pos;
constexpr IOBitSet(uint16_t bit_pos) : pos(bit_pos) {
}
constexpr IOBitUnset operator!() const {
return IOBitUnset(this->pos);
}
};
struct IOValueSet {
template<typename T>
using IOValueSetPair = pair<IOValueSet, T>;
uint16_t pos;
uint16_t length;
constexpr IOValueSet(uint16_t pos, uint16_t length) : pos(pos), length(length) {
}
static constexpr IOValueSet from_to(uint16_t first_bit, uint16_t last_bit) {
return IOValueSet(first_bit, (last_bit - first_bit) + 1);
}
template<typename T>
constexpr IOValueSetPair<T> with(T value) const {
return {*this, value};
}
template<typename T>
constexpr IOValueSetPair<T> range_max() const {
return IOValueSet::with<T>((1 << this->length) - 1);
}
};
namespace IOPort {
struct IOValueType {
template<typename T>
@@ -91,24 +48,24 @@ namespace JabyEngine {
return Self().set_va(args...); \
} \
\
constexpr Self& set(IOBitSet bit) { \
this->raw_value = bit::set(this->raw_value, bit.pos); \
constexpr Self& set(Bit bit) { \
this->raw_value = bit::set(this->raw_value, bit); \
return *this; \
} \
\
constexpr Self& set(IOBitUnset bit) { \
this->raw_value = bit::clear(this->raw_value, bit.pos); \
constexpr Self& set(ClearBit bit) { \
this->raw_value = bit::set(this->raw_value, bit); \
return *this; \
} \
\
constexpr Self& set(IOValueSet bits, UnderlyingValue value) { \
this->raw_value = bit::value::set_normalized(this->raw_value, value, bits.pos, bits.length); \
constexpr Self& set(BitRange bits, UnderlyingValue value) { \
this->raw_value = bit::value::set_normalized(this->raw_value, bits, value); \
return *this; \
} \
\
template<typename S> \
constexpr Self& set(const IOValueSet::IOValueSetPair<S>& value) { \
this->set(value.first, static_cast<UnderlyingValue>(value.second)); \
constexpr Self& set(const BitRange::RangeValuePair<S>& value) { \
this->raw_value = bit::value::set_normalized(this->raw_value, value); \
return *this; \
} \
\
@@ -122,17 +79,17 @@ namespace JabyEngine {
return this->set(head).set_va(tail...); \
} \
\
constexpr UnderlyingValue get(IOValueSet bits) const { \
constexpr UnderlyingValue get(BitRange bits) const { \
return bit::value::get_normalized(this->raw_value, bits.pos, bits.length); \
} \
\
constexpr Self& clear(IOBitSet bit) { \
this->raw_value = bit::clear(this->raw_value, bit.pos); \
constexpr Self& clear(Bit bit) { \
this->raw_value = bit::clear(this->raw_value, bit); \
return *this; \
} \
\
constexpr bool is_set(IOBitSet bit) const { \
return bit::is_set(this->raw_value, bit.pos); \
constexpr bool is_set(Bit bit) const { \
return bit::is_set(this->raw_value, bit); \
} \
\
constexpr void operator=(UnderlyingValue value) { \
@@ -160,38 +117,6 @@ namespace JabyEngine {
}
};
// For use with ComplexBitMaps or what else satisfies this API
template<typename T>
struct VolatileBitMapPOD {
typedef typename T::UnderlyingType Raw;
VolatilePOD<Raw> pod;
constexpr Raw read_raw() const {
return this->pod.read();
}
constexpr T read() const {
return T{this->pod.read()};
}
constexpr Raw read(const BitRange<Raw>& range) const {
return VolatileBitMapPOD<T>::read().get_value(range);
}
constexpr void write_raw(Raw value) {
this->pod.write(value);
}
constexpr void write(const T& value) {
this->pod.write(static_cast<Raw>(value));
}
constexpr void write(const BitRangeValue<Raw>& value) {
VolatileBitMapPOD<T>::write(T{T::with(value)});
}
};
struct __no_align ubus32_t {
__declare_io_type(uint16_t, uint16_t,);
uint16_t_v low;