Skip to content

Commit

Permalink
fmt builtin
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgerrets committed Apr 8, 2024
1 parent 843bf67 commit 01241fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion third_party/fmt/include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,13 @@ using std_string_view = std::experimental::basic_string_view<Char>;
template <typename T> struct std_string_view {};
#endif


#if defined(__SIZEOF_INT128__)
# define FMT_USE_INT128 1
using fmt_uint128_builtin_t = __uint128_t;
#else
# define FMT_USE_INT128 0
using fmt_uint128_builtin_t = {};
#endif

using fmt_int128_t = duckdb::hugeint_t;
using fmt_uint128_t = duckdb::uhugeint_t;
Expand Down
6 changes: 3 additions & 3 deletions third_party/fmt/include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ inline bool operator==(fp x, fp y) { return x.f == y.f && x.e == y.e; }
// Computes lhs * rhs / pow(2, 64) rounded to nearest with half-up tie breaking.
inline uint64_t multiply(uint64_t lhs, uint64_t rhs) {
#if FMT_USE_INT128
auto product = static_cast<fmt_uint128_internal_t_t>(lhs) * rhs;
auto product = static_cast<fmt_uint128_builtin_t>(lhs) * rhs;
auto f = static_cast<uint64_t>(product >> 64);
return (static_cast<uint64_t>(product) & (1ULL << 63)) != 0 ? f + 1 : f;
#else
Expand Down Expand Up @@ -427,7 +427,7 @@ FMT_FUNC fp get_cached_power(int min_exponent, int& pow10_exponent) {
return {data::pow10_significands[index], data::pow10_exponents[index]};
}

// A simple accumulator to hold the sums of terms in bigint::square if fmt_uint128_t
// A simple accumulator to hold the sums of terms in bigint::square if fmt_uint128_builtin_t
// is not available.
struct accumulator {
uint64_t lower;
Expand Down Expand Up @@ -629,7 +629,7 @@ class bigint {
int num_bigits = static_cast<int>(bigits_.size());
int num_result_bigits = 2 * num_bigits;
bigits_.resize(num_result_bigits);
using accumulator_t = conditional_t<FMT_USE_INT128, fmt_uint128_internal_t, accumulator>;
using accumulator_t = conditional_t<FMT_USE_INT128, fmt_uint128_builtin_t, accumulator>;
auto sum = accumulator_t();
for (int bigit_index = 0; bigit_index < num_bigits; ++bigit_index) {
// Compute bigit at position bigit_index of the result by adding
Expand Down

0 comments on commit 01241fe

Please sign in to comment.