Making ComplexBitMap a POD part 1
This commit is contained in:
@@ -1,205 +1,6 @@
|
||||
#ifndef __JABYENGINE_IOPORT_HPP__
|
||||
#define __JABYENGINE_IOPORT_HPP__
|
||||
#include "../../Auxiliary/bits.hpp"
|
||||
|
||||
struct ClearBitValue {
|
||||
size_t bit;
|
||||
|
||||
constexpr ClearBitValue(size_t bit) : bit(bit) {
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct Bit {
|
||||
typedef T ValueType;
|
||||
|
||||
size_t value;
|
||||
|
||||
constexpr Bit(size_t value) : value(value) {
|
||||
}
|
||||
|
||||
constexpr operator size_t() const {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
constexpr ClearBitValue operator!() const {
|
||||
return ClearBitValue(this->value);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct BitRangeValue {
|
||||
T value;
|
||||
size_t begin;
|
||||
size_t length;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct BitRange {
|
||||
typedef T ValueType;
|
||||
|
||||
size_t begin;
|
||||
size_t length;
|
||||
|
||||
static constexpr BitRange<T> from_to(size_t start, size_t end) {
|
||||
return {start, (end - start + 1)};
|
||||
}
|
||||
|
||||
constexpr BitRangeValue<T> with(T value) const {
|
||||
return {value, this->begin, this->length};
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
static constexpr __always_inline BitRangeValue<T> operator<<(const BitRange<T>& range, T value) {
|
||||
return BitRangeValue{value, range.begin, range.length};
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class __no_align ComplexBitMap {
|
||||
private:
|
||||
T value = 0;
|
||||
|
||||
template<typename S>
|
||||
constexpr ComplexBitMap<T>& set_va(const S& value) {
|
||||
return this->set(value);
|
||||
}
|
||||
|
||||
template<typename S, typename...ARGS>
|
||||
constexpr ComplexBitMap<T>& set_va(const S& value, const ARGS&...args) {
|
||||
return this->set_va(value).set_va(args...);
|
||||
}
|
||||
|
||||
public:
|
||||
constexpr ComplexBitMap() = default;
|
||||
constexpr ComplexBitMap(T value) : value(value) {
|
||||
}
|
||||
|
||||
template<typename...ARGS>
|
||||
static constexpr ComplexBitMap<T> with(ARGS...args) {
|
||||
return ComplexBitMap().set_va(args...);
|
||||
}
|
||||
|
||||
//Accesssing bits
|
||||
template<typename S>
|
||||
constexpr ComplexBitMap<T>& set_bit(S bit) {
|
||||
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr void set_bit(S bit) volatile {
|
||||
this->value = bit::set(this->value, static_cast<size_t>(bit));
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr ComplexBitMap<T>& clear_bit(S bit) {
|
||||
this->value = bit::clear(this->value, static_cast<size_t>(bit));
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr void clear_bit(S bit) volatile {
|
||||
this->value = bit::clear(this->value, static_cast<size_t>(bit));
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr bool is_bit_set(S bit) {
|
||||
return bit::is_set(this->value, static_cast<size_t>(bit));
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr bool is_bit_set(S bit) volatile {
|
||||
return bit::is_set(this->value, static_cast<size_t>(bit));
|
||||
}
|
||||
|
||||
//Accessing values
|
||||
template<typename S>
|
||||
constexpr ComplexBitMap<T>& set_value(S value, const BitRange<S>& range) {
|
||||
this->value = bit::value::set_normalized(this->value, static_cast<T>(value), range.begin, range.length);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr void set_value(S value, const BitRange<S>& range) volatile {
|
||||
this->value = bit::value::set_normalized(this->value, static_cast<T>(value), range.begin, range.length);
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr ComplexBitMap<T>& clear_value(const BitRange<S>& range) {
|
||||
this->value = bit::value::clear_normalized(this->value, range.begin, range.length);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr void clear_value(const BitRange<S>& range) volatile {
|
||||
this->value = bit::value::clear_normalized(this->value, range.begin, range.length);
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr S get_value(const BitRange<S>& range) {
|
||||
return static_cast<S>(bit::value::get_normalized(this->value, range.begin, range.length));
|
||||
}
|
||||
|
||||
template<typename S>
|
||||
constexpr S get_value(const BitRange<S>& range) volatile {
|
||||
return static_cast<S>(bit::value::get_normalized(this->value, range.begin, range.length));
|
||||
}
|
||||
|
||||
// For easier constructing
|
||||
constexpr ComplexBitMap<T>& set(const BitRange<T>& range, T value) {
|
||||
this->set_value(value, range);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr ComplexBitMap<T>& set(const BitRangeValue<T>& value) {
|
||||
this->set_value(value.value, {value.begin, value.length});
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr ComplexBitMap<T>& set(const Bit<T>& bit) {
|
||||
this->set_bit(bit.value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr ComplexBitMap<T>& set(const ClearBitValue& value) {
|
||||
this->clear_bit(value.bit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr ComplexBitMap<T>& operator|(const BitRangeValue<T>& value) {
|
||||
this->set_value(value.value, value.range);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr ComplexBitMap<T>& operator|(const Bit<T>& bit) {
|
||||
this->set_bit(bit.value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr ComplexBitMap<T>& operator|(const ClearBitValue& value) {
|
||||
this->clear_bit(value.bit);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//For raw access
|
||||
constexpr operator T() const {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
constexpr operator T() const volatile {
|
||||
return this->value;
|
||||
}
|
||||
|
||||
constexpr ComplexBitMap<T>& operator=(T value) {
|
||||
this->value = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr void operator=(T value) volatile {
|
||||
this->value = value;
|
||||
}
|
||||
};
|
||||
#include "../../Auxiliary/complex_bitmap.hpp"
|
||||
|
||||
template<typename T>
|
||||
class __no_align IOPort {
|
||||
@@ -230,23 +31,23 @@ struct __no_align ubus32_t {
|
||||
}
|
||||
|
||||
constexpr operator uint32_t() const {
|
||||
return ((this->high << 16) | this->low);
|
||||
return ((this->high.raw << 16) | this->low.raw);
|
||||
}
|
||||
|
||||
constexpr operator uint32_t() const volatile {
|
||||
return ((this->high << 16) | this->low);
|
||||
operator uint32_t() const volatile {
|
||||
return ((this->high.raw << 16) | this->low.raw);
|
||||
}
|
||||
|
||||
constexpr ubus32_t& operator=(uint32_t value) {
|
||||
this->low = (value & 0xFFFF);
|
||||
this->high = (value >> 16);
|
||||
this->low.raw = (value & 0xFFFF);
|
||||
this->high.raw = (value >> 16);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr void operator=(uint32_t value) volatile {
|
||||
this->low = (value & 0xFFFF);
|
||||
this->high = (value >> 16);
|
||||
this->low.raw = (value & 0xFFFF);
|
||||
this->high.raw = (value >> 16);
|
||||
}
|
||||
};
|
||||
static constexpr uintptr_t IO_Base_Mask = 0xF0000000;
|
||||
@@ -257,12 +58,25 @@ static constexpr uintptr_t IO_Base_Adr = 0x10000000;
|
||||
#define __declare_io_port_global_const(type, name, adr) __declare_io_port_global_raw(const, type, name, adr)
|
||||
#define __declare_io_port_global_array(type, name, adr, size) static __always_inline auto& name = reinterpret_cast<type(&)[size]>(*reinterpret_cast<type*>((IO_Base_Adr + (adr & ~IO_Base_Mask))));
|
||||
#define __io_port_inherit_complex_bit_map(name) \
|
||||
constexpr name() = default; \
|
||||
constexpr name(ComplexBitMap value) : ComplexBitMap(value) { \
|
||||
} \
|
||||
template<typename...ARGS> \
|
||||
static constexpr name with(ARGS...args) { \
|
||||
return {ComplexBitMap::with(args...)}; \
|
||||
}\
|
||||
template<typename T> \
|
||||
constexpr void operator=(ComplexBitMap<T> value) volatile { \
|
||||
this->raw = value.raw; \
|
||||
}
|
||||
|
||||
/*\
|
||||
using ComplexBitMap::operator=; \
|
||||
constexpr name() = default; \
|
||||
constexpr name(ComplexBitMap value) : ComplexBitMap(value) { \
|
||||
}\
|
||||
template<typename...ARGS> \
|
||||
constexpr name(ARGS...args) : ComplexBitMap(args...) {\
|
||||
}
|
||||
}*/
|
||||
|
||||
#endif //!__JABYENGINE_IOPORT_HPP__
|
||||
Reference in New Issue
Block a user