fix: fix some bugs in tools
This commit is contained in:
@ -13,7 +13,7 @@ constexpr auto int_concat(max_size_t arg, auto... args) {
|
|||||||
|
|
||||||
template<std::size_t _Old, std::size_t _New = kMaxLength>
|
template<std::size_t _Old, std::size_t _New = kMaxLength>
|
||||||
constexpr auto sign_extend(max_size_t val) {
|
constexpr auto sign_extend(max_size_t val) {
|
||||||
static_assert(_Old < _New, "sign_extend: _Old should be less than _New");
|
static_assert(_Old <= _New, "sign_extend: _Old should be less than _New");
|
||||||
struct {
|
struct {
|
||||||
max_ssize_t _M_data : _Old;
|
max_ssize_t _M_data : _Old;
|
||||||
} tmp;
|
} tmp;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "bit.h"
|
#include "bit.h"
|
||||||
|
#include "register.h"
|
||||||
|
|
||||||
namespace dark {
|
namespace dark {
|
||||||
|
|
||||||
@ -75,7 +76,7 @@ constexpr auto operator^(const _Tp &lhs, const _Up &rhs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename _Tp>
|
template<typename _Tp>
|
||||||
concept int_or_bit = int_type<_Tp> || bit_type<_Tp>;
|
concept int_or_bit = int_type<_Tp> || bit_type<std::decay_t<_Tp>>;
|
||||||
|
|
||||||
template<bit_type _Tp, int_or_bit _Up>
|
template<bit_type _Tp, int_or_bit _Up>
|
||||||
constexpr auto operator<<(const _Tp &lhs, const _Up &rhs) {
|
constexpr auto operator<<(const _Tp &lhs, const _Up &rhs) {
|
||||||
@ -107,25 +108,20 @@ constexpr auto operator-(const _Tp &value) {
|
|||||||
return Bit<_Tp::_Bit_Len>(-cast(value));
|
return Bit<_Tp::_Bit_Len>(-cast(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<int_or_bit _Tp, int_or_bit _Up>
|
|
||||||
constexpr bool operator&&(const _Tp &lhs, const _Up &rhs) {
|
|
||||||
return cast(lhs) && cast(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<int_or_bit _Tp, int_or_bit _Up>
|
|
||||||
constexpr bool operator||(const _Tp &lhs, const _Up &rhs) {
|
|
||||||
return cast(lhs) || cast(rhs);
|
|
||||||
}
|
|
||||||
|
|
||||||
template<int_or_bit _Tp, int_or_bit _Up>
|
template<int_or_bit _Tp, int_or_bit _Up>
|
||||||
constexpr bool operator==(const _Tp &lhs, const _Up &rhs) {
|
constexpr bool operator==(const _Tp &lhs, const _Up &rhs) {
|
||||||
return cast(lhs) == cast(rhs);
|
return cast(lhs) == cast(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename _Tp>
|
||||||
|
inline constexpr bool is_reg_ref_v = false;
|
||||||
|
|
||||||
|
template <std::size_t _Len>
|
||||||
|
inline constexpr bool is_reg_ref_v<Register<_Len> &> = true;
|
||||||
|
|
||||||
template<int_or_bit _Tp, int_or_bit _Up>
|
template<int_or_bit _Tp, int_or_bit _Up>
|
||||||
constexpr auto operator<=>(const _Tp &lhs, const _Up &rhs) {
|
constexpr auto operator <=> (const _Tp &lhs, const _Up &rhs) {
|
||||||
return cast(lhs) <=> cast(rhs);
|
return cast(lhs) <=> cast(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace dark
|
} // namespace dark
|
||||||
|
@ -24,10 +24,10 @@ using dark::max_ssize_t;
|
|||||||
|
|
||||||
template<dark::concepts::bit_type _Tp>
|
template<dark::concepts::bit_type _Tp>
|
||||||
constexpr auto to_unsigned(const _Tp &x) {
|
constexpr auto to_unsigned(const _Tp &x) {
|
||||||
return static_cast<dark::max_size_t>(x);
|
return static_cast<max_size_t>(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<dark::concepts::bit_type _Tp>
|
template<dark::concepts::bit_type _Tp>
|
||||||
constexpr auto to_signed(const _Tp &x) {
|
constexpr auto to_signed(const _Tp &x) {
|
||||||
return static_cast<dark::max_ssize_t>(sign_extend(x));
|
return static_cast<max_ssize_t>(static_cast<max_size_t>(sign_extend(x)));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user