Skip to content

Commit

Permalink
fix some warnings in MSVC /Wall
Browse files Browse the repository at this point in the history
  • Loading branch information
wjr-z committed Aug 5, 2024
1 parent 8ac8a35 commit fde7d0e
Show file tree
Hide file tree
Showing 19 changed files with 153 additions and 112 deletions.
8 changes: 4 additions & 4 deletions include/wjr/biginteger/biginteger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace biginteger_detail {
*
*/
inline uint32_t normalize(const uint64_t *ptr, uint32_t n) noexcept {
return reverse_find_not_n(ptr, 0, n);
return static_cast<uint32_t>(reverse_find_not_n(ptr, 0, n));
}

} // namespace biginteger_detail
Expand All @@ -38,7 +38,7 @@ class default_biginteger_size_reference {
: m_size(&size) {}

constexpr default_biginteger_size_reference &operator=(uint32_t size) noexcept {
*m_size = __fasts_negate_with<int32_t>(*m_size, size);
*m_size = __fasts_negate_with<int32_t>(*m_size, to_signed(size));
return *this;
}

Expand Down Expand Up @@ -1327,7 +1327,7 @@ class basic_biginteger {
void set_ssize(T new_size) noexcept {
if constexpr (std::is_unsigned_v<T>) {
const auto u32size = static_cast<uint32_t>(new_size);
WJR_ASSUME(u32size == new_size);
WJR_ASSERT_ASSUME(u32size == new_size);
get_storage().set_ssize(__fasts_from_unsigned(u32size));
} else {
get_storage().set_ssize(new_size);
Expand Down Expand Up @@ -3271,7 +3271,7 @@ inline uint32_t __ctz_impl(const biginteger_data *num) noexcept {

const auto *const ptr = num->data();
const uint32_t size = num->size();
const uint32_t idx = find_not_n(ptr, 0, size);
const uint32_t idx = static_cast<uint32_t>(find_not_n(ptr, 0, size));
WJR_ASSERT(idx != size);
return idx * 64 + ctz(ptr[idx]);
}
Expand Down
7 changes: 7 additions & 0 deletions include/wjr/format/fastfloat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ struct default_writer {

WJR_INTRINSIC_CONSTEXPR T &get_float() noexcept { return value; }

default_writer() = delete;
default_writer(const default_writer &) = default;
default_writer(default_writer &&) = default;
default_writer &operator=(const default_writer &) = default;
default_writer &operator=(default_writer &&) = delete;
~default_writer() = default;

T &value;
};

Expand Down
8 changes: 4 additions & 4 deletions include/wjr/format/utf8/utf8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ inline constexpr std::array<uint32_t, 886> digit_to_val32 = {

WJR_PURE WJR_INTRINSIC_CONSTEXPR uint32_t
hex_to_u32_unchecked(const uint8_t *src) noexcept {
const uint32_t v1 = digit_to_val32[630 + src[0]];
const uint32_t v2 = digit_to_val32[420 + src[1]];
const uint32_t v3 = digit_to_val32[210 + src[2]];
const uint32_t v4 = digit_to_val32[0 + src[3]];
const uint32_t v1 = digit_to_val32[630u + src[0]];
const uint32_t v2 = digit_to_val32[420u + src[1]];
const uint32_t v3 = digit_to_val32[210u + src[2]];
const uint32_t v4 = digit_to_val32[0u + src[3]];
return v1 | v2 | v3 | v4;
}

Expand Down
32 changes: 14 additions & 18 deletions include/wjr/json/detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ template <typename T>
using result = expected<T, result_error>;

enum class value_t : uint8_t {
null,
boolean,
number_signed,
number_unsigned,
number_signed,
number_float,
null,
boolean,
string,
object,
array,
};

using null_t = integral_constant<value_t, value_t::null>;
inline constexpr null_t null_v = {};

using boolean_t = integral_constant<value_t, value_t::boolean>;
inline constexpr boolean_t boolean_v = {};
using number_unsigned_t = integral_constant<value_t, value_t::number_unsigned>;
inline constexpr number_unsigned_t number_unsigned_v = {};

using number_signed_t = integral_constant<value_t, value_t::number_signed>;
inline constexpr number_signed_t number_signed_v = {};

using number_unsigned_t = integral_constant<value_t, value_t::number_unsigned>;
inline constexpr number_unsigned_t number_unsigned_v = {};

using number_float_t = integral_constant<value_t, value_t::number_float>;
inline constexpr number_float_t number_float_v = {};

using null_t = integral_constant<value_t, value_t::null>;
inline constexpr null_t null_v = {};

using boolean_t = integral_constant<value_t, value_t::boolean>;
inline constexpr boolean_t boolean_v = {};

using string_t = integral_constant<value_t, value_t::string>;
inline constexpr string_t string_v = {};

Expand All @@ -82,8 +82,6 @@ inline constexpr object_t object_v = {};
using array_t = integral_constant<value_t, value_t::array>;
inline constexpr array_t array_v = {};

namespace detail {

struct basic_value {
WJR_ENABLE_DEFAULT_SPECIAL_MEMBERS(basic_value);

Expand All @@ -100,19 +98,17 @@ struct basic_value {
basic_value(array_t, void *ptr) noexcept : m_ptr(ptr), m_type(value_t::array) {}

union {
std::nullptr_t m_null;
bool m_boolean;
int64_t m_number_signed;
uint64_t m_number_unsigned;
int64_t m_number_signed;
double m_number_float;
std::nullptr_t m_null;
bool m_boolean;
void *m_ptr;
};

value_t m_type;
};

} // namespace detail

} // namespace wjr::json

#endif // WJR_JSON_DETAIL_HPP__
4 changes: 2 additions & 2 deletions include/wjr/json/number.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ WJR_PURE WJR_INTRINSIC_INLINE result<void> check_number(const char *first,
return {};
}

WJR_PURE WJR_INTRINSIC_INLINE basic_value parse_number(const char *first,
const char *last) noexcept {
WJR_PURE WJR_INTRINSIC_INLINE basic_value parse_number(
WJR_MAYBE_UNUSED const char *first, WJR_MAYBE_UNUSED const char *last) noexcept {
return basic_value(null_v);
}

Expand Down
2 changes: 1 addition & 1 deletion include/wjr/json/reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class reader {
m_str = sp;

lexer lex(m_str);
const size_type n = m_str.size();
const size_type n = static_cast<size_type>(m_str.size());
size_type capacity = n <= 2048 ? n : std::max<size_type>(2048, n / 20);
size_type buf_size = capacity;
json::lexer::result_type result;
Expand Down
4 changes: 2 additions & 2 deletions include/wjr/math/bit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ WJR_CONST WJR_INTRINSIC_CONSTEXPR bool has_single_bit(T n) noexcept {
template <typename T, WJR_REQUIRES(is_nonbool_unsigned_integral_v<T>)>
WJR_CONST WJR_INTRINSIC_CONSTEXPR20 int countl_zero(T x) noexcept {
// If not use __builtin_clz and use popcount, then don't need to handle zero.
#if WJR_HAS_BUILTIN(CLZ) || !(WJR_HAS_BUILTIN(POPCOUNT) && WJR_HAS_SIMD(POPCNT))
#if WJR_HAS_BUILTIN(CLZ) || !WJR_HAS_BUILTIN(POPCOUNT)
if (WJR_UNLIKELY(x == 0)) {
return std::numeric_limits<T>::digits;
}
Expand All @@ -27,7 +27,7 @@ WJR_CONST WJR_INTRINSIC_CONSTEXPR20 int countl_zero(T x) noexcept {
template <typename T, WJR_REQUIRES(is_nonbool_unsigned_integral_v<T>)>
WJR_CONST WJR_INTRINSIC_CONSTEXPR20 int countr_zero(T x) noexcept {
// If not use __builtin_ctz and use popcount, then don't need to handle zero.
#if WJR_HAS_BUILTIN(CTZ) || !(WJR_HAS_BUILTIN(POPCOUNT) && WJR_HAS_SIMD(POPCNT))
#if WJR_HAS_BUILTIN(CTZ) || !WJR_HAS_BUILTIN(POPCOUNT)
if (WJR_UNLIKELY(x == 0)) {
return std::numeric_limits<T>::digits;
}
Expand Down
6 changes: 3 additions & 3 deletions include/wjr/math/clz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ template <typename T>
WJR_CONST WJR_INTRINSIC_CONSTEXPR20 int fallback_clz(T x) noexcept {
constexpr auto nd = std::numeric_limits<T>::digits;

#if !(WJR_HAS_BUILTIN(POPCOUNT) && WJR_HAS_SIMD(POPCNT))
#if !WJR_HAS_BUILTIN(POPCOUNT)
if constexpr (nd >= 32) {
#endif
x |= (x >> 1);
Expand All @@ -61,11 +61,11 @@ WJR_CONST WJR_INTRINSIC_CONSTEXPR20 int fallback_clz(T x) noexcept {
if constexpr (nd >= 64) {
x |= (x >> 32);
}
#if !(WJR_HAS_BUILTIN(POPCOUNT) && WJR_HAS_SIMD(POPCNT))
#if !WJR_HAS_BUILTIN(POPCOUNT)
}
#endif

#if WJR_HAS_BUILTIN(POPCOUNT) && WJR_HAS_SIMD(POPCNT)
#if WJR_HAS_BUILTIN(POPCOUNT)
return popcount<T>(~x);
#else
if constexpr (nd < 32) {
Expand Down
2 changes: 1 addition & 1 deletion include/wjr/math/compare.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ WJR_INTRINSIC_CONSTEXPR20 bool __fallback_less_128(uint64_t lo0, uint64_t hi0,
uint8_t f = lo0 < lo1;
(void)subc_cc(hi0, hi1, f, f);
WJR_ASSUME(f <= 1);
return f;
return f != 0;
}

#if WJR_HAS_BUILTIN(__BUILTIN_LESS_128)
Expand Down
2 changes: 1 addition & 1 deletion include/wjr/math/ctz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ WJR_CONST WJR_INTRINSIC_CONSTEXPR int constexpr_ctz(T x) noexcept {

template <typename T>
WJR_CONST WJR_INTRINSIC_CONSTEXPR20 int fallback_ctz(T x) noexcept {
#if WJR_HAS_BUILTIN(POPCOUNT) && WJR_HAS_SIMD(POPCNT)
#if WJR_HAS_BUILTIN(POPCOUNT)
return popcount<T>(lowbit(x) - 1);
#else
constexpr auto nd = std::numeric_limits<T>::digits;
Expand Down
34 changes: 0 additions & 34 deletions include/wjr/math/detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,6 @@

namespace wjr {

#if !(WJR_HAS_BUILTIN(POPCOUNT) && WJR_HAS_SIMD(POPCNT))

namespace math_detail {

template <typename T, T seed>
class de_bruijn {
public:
constexpr static uint8_t digits = std::numeric_limits<T>::digits;
constexpr static uint8_t mv = digits == 32 ? 27 : 58;
constexpr de_bruijn() noexcept : lookup(), lookupr() { initialize(); }

constexpr int get(T idx) const noexcept { return lookup[(idx * seed) >> mv]; }
constexpr int getr(T idx) const noexcept { return lookupr[(idx * seed) >> mv]; }

private:
constexpr void initialize() noexcept {
for (uint8_t i = 0; i < digits; ++i) {
const auto idx = (seed << i) >> mv;
lookup[idx] = i;
lookupr[idx] = i == 0 ? 0 : digits - i;
}
}

uint8_t lookup[digits];
uint8_t lookupr[digits];
};

inline constexpr de_bruijn<uint32_t, 0x077C'B531> de_bruijn32 = {};
inline constexpr de_bruijn<uint64_t, 0x03f7'9d71'b4ca'8b09> de_bruijn64 = {};

} // namespace math_detail

#endif

/**
* @brief
*
Expand Down
2 changes: 1 addition & 1 deletion include/wjr/math/div.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ WJR_INTRINSIC_CONSTEXPR20 void divexact_1(uint64_t *dst, const uint64_t *src, si
WJR_ASSERT_ASSUME(div != 0);

if (WJR_UNLIKELY(is_zero_or_single_bit(div))) {
unsigned int c = ctz(div);
const unsigned int c = ctz(div);
(void)rshift_n(dst, src, n, c);
return;
}
Expand Down
22 changes: 12 additions & 10 deletions include/wjr/math/divider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ class div2by1_divider_noshift {
return basic_divide(divisor, value, lo, hi);
}

WJR_CONST WJR_CONSTEXPR20 static T reciprocal(T d) noexcept;
WJR_CONST WJR_CONSTEXPR20 static T reciprocal(T d) noexcept {
if (WJR_BUILTIN_CONSTANT_P_TRUE(d == 1ull << 63)) {
return in_place_max;
}

return __reciprocal_impl(d);
}

private:
WJR_CONST WJR_CONSTEXPR20 static T __reciprocal_impl(T d) noexcept;

WJR_INTRINSIC_CONSTEXPR static void fallback_div2by1_adjust(T rax, T div, T &r8,
T &rdx) noexcept {
const T r9 = r8 + div;
Expand Down Expand Up @@ -164,7 +172,7 @@ class div2by1_divider_noshift {
};

template <typename T>
WJR_CONST WJR_CONSTEXPR20 T div2by1_divider_noshift<T>::reciprocal(T d) noexcept {
WJR_CONST WJR_CONSTEXPR20 T div2by1_divider_noshift<T>::__reciprocal_impl(T d) noexcept {
WJR_ASSERT_ASSUME_L2(__has_high_bit(d));

uint64_t d40 = 0, d63 = 0;
Expand Down Expand Up @@ -246,18 +254,12 @@ class div2by1_divider : public div2by1_divider_noshift<T> {
m_shift = clz(m_divisor);
m_divisor <<= m_shift;

WJR_ASSUME(m_shift != 0);
WJR_ASSUME(m_shift != 0u);
} else {
WJR_ASSUME(m_shift == 0);
WJR_ASSUME(m_shift == 0u);
}

WJR_ASSUME(__has_high_bit(m_divisor));

if (WJR_UNLIKELY(m_divisor == 1ull << 63)) {
m_value = -1;
return;
}

m_value = Mybase::reciprocal(m_divisor);
}

Expand Down
6 changes: 3 additions & 3 deletions include/wjr/math/mul.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ WJR_INTRINSIC_CONSTEXPR20 uint64_t mul_1(uint64_t *dst, const uint64_t *src, siz
return 0;
}

unsigned int k = ctz(ml);
return lshift_n(dst, src, n, k);
const unsigned int c = ctz(ml);
return lshift_n(dst, src, n, c);
}

#if WJR_HAS_BUILTIN(ASM_MUL_1)
Expand Down Expand Up @@ -260,7 +260,7 @@ WJR_INTRINSIC_CONSTEXPR20 uint64_t addmul_1(uint64_t *dst, const uint64_t *src,
return 0;
}

unsigned int c = ctz(ml);
const unsigned int c = ctz(ml);
return addlsh_n(dst, dst, src, n, c);
}

Expand Down
Loading

0 comments on commit fde7d0e

Please sign in to comment.