From 8434f3f1375e5ca11e86d6326f7d21b16c2b4be9 Mon Sep 17 00:00:00 2001 From: DarkSharpness <2040703891@qq.com> Date: Wed, 24 Jul 2024 10:32:27 +0800 Subject: [PATCH] fix: fix some bugs in tools --- include/bit_impl.h | 2 +- include/operator.h | 22 +++++++++------------- include/tools.h | 4 ++-- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/include/bit_impl.h b/include/bit_impl.h index 609bdec..39b89e2 100644 --- a/include/bit_impl.h +++ b/include/bit_impl.h @@ -13,7 +13,7 @@ constexpr auto int_concat(max_size_t arg, auto... args) { template 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 { max_ssize_t _M_data : _Old; } tmp; diff --git a/include/operator.h b/include/operator.h index 23bb701..d110606 100644 --- a/include/operator.h +++ b/include/operator.h @@ -1,5 +1,6 @@ #pragma once #include "bit.h" +#include "register.h" namespace dark { @@ -75,7 +76,7 @@ constexpr auto operator^(const _Tp &lhs, const _Up &rhs) { } template -concept int_or_bit = int_type<_Tp> || bit_type<_Tp>; +concept int_or_bit = int_type<_Tp> || bit_type>; template 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)); } -template -constexpr bool operator&&(const _Tp &lhs, const _Up &rhs) { - return cast(lhs) && cast(rhs); -} - -template -constexpr bool operator||(const _Tp &lhs, const _Up &rhs) { - return cast(lhs) || cast(rhs); -} - template constexpr bool operator==(const _Tp &lhs, const _Up &rhs) { return cast(lhs) == cast(rhs); } +template +inline constexpr bool is_reg_ref_v = false; + +template +inline constexpr bool is_reg_ref_v &> = true; + template -constexpr auto operator<=>(const _Tp &lhs, const _Up &rhs) { +constexpr auto operator <=> (const _Tp &lhs, const _Up &rhs) { return cast(lhs) <=> cast(rhs); } - } // namespace dark diff --git a/include/tools.h b/include/tools.h index 7f273a2..7e190cb 100644 --- a/include/tools.h +++ b/include/tools.h @@ -24,10 +24,10 @@ using dark::max_ssize_t; template constexpr auto to_unsigned(const _Tp &x) { - return static_cast(x); + return static_cast(x); } template constexpr auto to_signed(const _Tp &x) { - return static_cast(sign_extend(x)); + return static_cast(static_cast(sign_extend(x))); }