diff --git a/include/bit.h b/include/bit.h index 38881e6..e71e9be 100644 --- a/include/bit.h +++ b/include/bit.h @@ -1,5 +1,6 @@ #pragma once #include "target.h" +#include "debug.h" #include #include @@ -71,6 +72,15 @@ struct Bit { return Bit<_Hi - _Lo + 1>(this->_M_data >> _Lo); } + template + constexpr auto at(target_size_t pos) const -> Bit <_Len> { + static_assert(_Len != 0, "Bit::at: _Len should be greater than 0"); + debug::assert(pos + _Len <= _Nm, "Bit::at: pos out of range"); + return Bit <_Len> (this->_M_data >> pos); + } + + constexpr auto operator [](target_size_t pos) const -> Bit <1> { return this->at(pos); } + template constexpr auto zero_extend() const -> Bit<_New>;