1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-11-02 02:16:18 +00:00

Further extend. This is becoming more of a SizedInt.

This commit is contained in:
Thomas Harte
2025-09-23 14:26:58 -04:00
parent ca226e4295
commit ebf09aceb2

View File

@@ -28,20 +28,35 @@ struct SizedCounter {
return counter_;
}
SizedCounter operator +(const SizedCounter offset) const {
return SizedCounter<bits>(counter_ + offset.counter_);
SizedCounter operator +(const SizedCounter offset) const { return SizedCounter<bits>(counter_ + offset.counter_); }
SizedCounter operator -(const SizedCounter offset) const { return SizedCounter<bits>(counter_ - offset.counter_); }
SizedCounter operator &(const SizedCounter offset) const { return SizedCounter<bits>(counter_ & offset.counter_); }
SizedCounter operator |(const SizedCounter offset) const { return SizedCounter<bits>(counter_ | offset.counter_); }
SizedCounter operator ^(const SizedCounter offset) const { return SizedCounter<bits>(counter_ ^ offset.counter_); }
SizedCounter operator >>(const int shift) const { return SizedCounter<bits>(counter_ >> shift); }
SizedCounter operator <<(const int shift) const { return SizedCounter<bits>(counter_ << shift); }
SizedCounter &operator &=(const SizedCounter offset) {
counter_ &= offset.counter_;
return *this;
}
SizedCounter &operator |=(const SizedCounter offset) {
counter_ |= offset.counter_;
return *this;
}
SizedCounter &operator ^=(const SizedCounter offset) {
counter_ ^= offset.counter_;
return *this;
}
SizedCounter operator &(const SizedCounter offset) const {
return SizedCounter<bits>(counter_ & offset.counter_);
SizedCounter &operator <<=(const int shift) {
counter_ = (counter_ << shift) & Mask;
return *this;
}
SizedCounter operator >>(const int shift) const {
return SizedCounter<bits>(counter_ >> shift);
}
SizedCounter operator <<(const int shift) const {
return SizedCounter<bits>(counter_ << shift);
SizedCounter &operator >>=(const int shift) {
counter_ >>= shift;
return *this;
}
SizedCounter &operator ++(int) {
@@ -78,6 +93,12 @@ struct SizedCounter {
load<begin, begin + sizeof(IntT)*8>(value);
}
template <int index>
requires (index < bits)
bool bit() {
return counter_ & (1 << index);
}
private:
IntT counter_{};
};