Skip to content

Commit

Permalink
int128: Compile with -Wpedantic
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed May 23, 2019
1 parent 50a3f4e commit cd0b7ea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ include(Hunter/init)
project(intx LANGUAGES CXX)
set(PROJECT_VERSION 0.3.0-dev)

cable_configure_compiler(NO_PEDANTIC NO_CONVERSION_WARNINGS NO_STACK_PROTECTION)
cable_configure_compiler(NO_CONVERSION_WARNINGS NO_STACK_PROTECTION)

if(INTX_TESTING)
enable_testing()
Expand Down
10 changes: 8 additions & 2 deletions include/intx/int128.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ struct uint<128>
{}

#ifdef __SIZEOF_INT128__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
constexpr uint(unsigned __int128 x) noexcept // NOLINT
: lo{uint64_t(x)}, hi{uint64_t(x >> 64)}
{}

constexpr explicit operator unsigned __int128() const noexcept
{
return ((unsigned __int128){hi} << 64) | lo;
return (static_cast<unsigned __int128>(hi) << 64) | lo;
}
#pragma GCC diagnostic pop
#endif

constexpr explicit operator bool() const noexcept { return hi | lo; }
Expand Down Expand Up @@ -287,8 +290,11 @@ constexpr uint128 constexpr_umul(uint64_t x, uint64_t y) noexcept
inline uint128 umul(uint64_t x, uint64_t y) noexcept
{
#if defined(__SIZEOF_INT128__)
const auto p = (unsigned __int128){x} * y;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
const auto p = static_cast<unsigned __int128>(x) * y;
return {uint64_t(p >> 64), uint64_t(p)};
#pragma GCC diagnostic pop
#elif defined(_MSC_VER)
unsigned __int64 hi;
const auto lo = _umul128(x, y, &hi);
Expand Down
1 change: 1 addition & 0 deletions test/benchmarks/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cstdint>
#include <cstring>

#pragma GCC diagnostic ignored "-Wpedantic"

uint64_t udiv_native(uint64_t x, uint64_t y) noexcept
{
Expand Down
13 changes: 8 additions & 5 deletions test/unittests/test_int128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@ TEST(int128, div)
}

#ifdef __SIZEOF_INT128__
#pragma GCC diagnostic ignored "-Wpedantic"
using uint128_ty = unsigned __int128;

TEST(int128, arith_random_args)
{
int c = 1000000;
Expand All @@ -311,11 +314,11 @@ TEST(int128, arith_random_args)
auto q = x / y;
auto r = x % y;

auto expected_s = uint128{(unsigned __int128){x} + (unsigned __int128){y}};
auto expected_d = uint128{(unsigned __int128){x} - (unsigned __int128){y}};
auto expected_p = uint128{(unsigned __int128){x} * (unsigned __int128){y}};
auto expected_q = uint128{(unsigned __int128){x} / (unsigned __int128){y}};
auto expected_r = uint128{(unsigned __int128){x} % (unsigned __int128){y}};
auto expected_s = uint128{uint128_ty{x} + uint128_ty{y}};
auto expected_d = uint128{uint128_ty{x} - uint128_ty{y}};
auto expected_p = uint128{uint128_ty{x} * uint128_ty{y}};
auto expected_q = uint128{uint128_ty{x} / uint128_ty{y}};
auto expected_r = uint128{uint128_ty{x} % uint128_ty{y}};

EXPECT_EQ(s, expected_s) << c;
EXPECT_EQ(d, expected_d) << c;
Expand Down
4 changes: 2 additions & 2 deletions test/utils/gmp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inline div_result<Int> udivrem(const Int& x, const Int& y) noexcept
auto p_y = (mp_srcptr)&y;
mpn_tdiv_qr(p_q, p_r, 0, p_x, x_limbs, p_y, y_limbs);
return {q, r};
};
}

template <typename Int>
inline div_result<Int> sdivrem(const Int& x, const Int& y) noexcept
Expand Down Expand Up @@ -98,7 +98,7 @@ inline div_result<Int> sdivrem(const Int& x, const Int& y) noexcept
mpz_clears(x_gmp, y_gmp, q_gmp, r_gmp, NULL);

return {q, r};
};
}

template <typename Int>
inline Int add(const Int& x, const Int& y) noexcept
Expand Down

0 comments on commit cd0b7ea

Please sign in to comment.