diff --git a/include/fmt/core.h b/include/fmt/core.h index 6bde998a6d35..1fab00b5e794 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -234,11 +234,8 @@ # define FMT_CLASS_API FMT_MSC_WARNING(suppress : 4275) # ifdef FMT_EXPORT # define FMT_API __declspec(dllexport) -# define FMT_EXTERN_TEMPLATE_API FMT_API -# define FMT_EXPORTED # elif defined(FMT_SHARED) # define FMT_API __declspec(dllimport) -# define FMT_EXTERN_TEMPLATE_API FMT_API # endif #else # define FMT_CLASS_API @@ -246,29 +243,6 @@ #ifndef FMT_API # define FMT_API #endif -#ifndef FMT_EXTERN_TEMPLATE_API -# define FMT_EXTERN_TEMPLATE_API -#endif -#ifndef FMT_INSTANTIATION_DECL_API // clang marks dllexport at extern template. -# ifndef _MSC_VER -# define FMT_INSTANTIATION_DECL_API FMT_API -# else -# define FMT_INSTANTIATION_DECL_API -# endif -#endif -#ifndef FMT_INSTANTIATION_DEF_API // msvc marks dllexport at the definition itself. -# ifndef _MSC_VER -# define FMT_INSTANTIATION_DEF_API -# else -# define FMT_INSTANTIATION_DEF_API FMT_API -# endif -#endif - -#ifndef FMT_HEADER_ONLY -# define FMT_EXTERN extern -#else -# define FMT_EXTERN -#endif // libc++ supports string_view in pre-c++17. #if (FMT_HAS_INCLUDE() && \ @@ -432,9 +406,8 @@ template class basic_string_view { \endrst */ FMT_CONSTEXPR_CHAR_TRAITS - FMT_INLINE - basic_string_view(const Char* s) - : data_(s) { + FMT_INLINE + basic_string_view(const Char* s) : data_(s) { if (detail::const_check(std::is_same::value && !detail::is_constant_evaluated())) size_ = std::strlen(reinterpret_cast(s)); @@ -2009,7 +1982,7 @@ FMT_GCC_PRAGMA("GCC pop_options") FMT_END_NAMESPACE #ifdef FMT_HEADER_ONLY -#include "format.h" +# include "format.h" #endif #endif // FMT_CORE_H_ diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index 9b2f4d6db1ba..17f5ebcfa411 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -858,6 +858,54 @@ struct fixed_handler { } }; +// A 128-bit integer type used internally, +struct uint128_wrapper { + uint128_wrapper() = default; + +#if FMT_USE_INT128 + uint128_t internal_; + + constexpr uint128_wrapper(uint64_t high, uint64_t low) FMT_NOEXCEPT + : internal_{static_cast(low) | + (static_cast(high) << 64)} {} + + constexpr uint128_wrapper(uint128_t u) : internal_{u} {} + + constexpr uint64_t high() const FMT_NOEXCEPT { + return uint64_t(internal_ >> 64); + } + constexpr uint64_t low() const FMT_NOEXCEPT { return uint64_t(internal_); } + + uint128_wrapper& operator+=(uint64_t n) FMT_NOEXCEPT { + internal_ += n; + return *this; + } +#else + uint64_t high_; + uint64_t low_; + + constexpr uint128_wrapper(uint64_t high, uint64_t low) FMT_NOEXCEPT + : high_{high}, + low_{low} {} + + constexpr uint64_t high() const FMT_NOEXCEPT { return high_; } + constexpr uint64_t low() const FMT_NOEXCEPT { return low_; } + + uint128_wrapper& operator+=(uint64_t n) FMT_NOEXCEPT { +# if defined(_MSC_VER) && defined(_M_X64) + unsigned char carry = _addcarry_u64(0, low_, n, &low_); + _addcarry_u64(carry, high_, 0, &high_); + return *this; +# else + uint64_t sum = low_ + n; + high_ += (sum < low_ ? 1 : 0); + low_ = sum; + return *this; +# endif + } +#endif +}; + // Implementation of Dragonbox algorithm: https://github.com/jk-jeon/dragonbox. namespace dragonbox { // Computes 128-bit result of multiplication of two 64-bit unsigned integers. diff --git a/include/fmt/format.h b/include/fmt/format.h index 3e1380c08329..dc51c9b1a16d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -897,61 +897,13 @@ using uint32_or_64_or_128_t = template using uint64_or_128_t = conditional_t() <= 64, uint64_t, uint128_t>; -// 128-bit integer type used internally -struct FMT_EXTERN_TEMPLATE_API uint128_wrapper { - uint128_wrapper() = default; - -#if FMT_USE_INT128 - uint128_t internal_; - - constexpr uint128_wrapper(uint64_t high, uint64_t low) FMT_NOEXCEPT - : internal_{static_cast(low) | - (static_cast(high) << 64)} {} - - constexpr uint128_wrapper(uint128_t u) : internal_{u} {} - - constexpr uint64_t high() const FMT_NOEXCEPT { - return uint64_t(internal_ >> 64); - } - constexpr uint64_t low() const FMT_NOEXCEPT { return uint64_t(internal_); } - - uint128_wrapper& operator+=(uint64_t n) FMT_NOEXCEPT { - internal_ += n; - return *this; - } -#else - uint64_t high_; - uint64_t low_; - - constexpr uint128_wrapper(uint64_t high, uint64_t low) FMT_NOEXCEPT - : high_{high}, - low_{low} {} - - constexpr uint64_t high() const FMT_NOEXCEPT { return high_; } - constexpr uint64_t low() const FMT_NOEXCEPT { return low_; } - - uint128_wrapper& operator+=(uint64_t n) FMT_NOEXCEPT { -# if defined(_MSC_VER) && defined(_M_X64) - unsigned char carry = _addcarry_u64(0, low_, n, &low_); - _addcarry_u64(carry, high_, 0, &high_); - return *this; -# else - uint64_t sum = low_ + n; - high_ += (sum < low_ ? 1 : 0); - low_ = sum; - return *this; -# endif - } -#endif -}; - #define FMT_POWERS_OF_10(factor) \ factor * 10, (factor)*100, (factor)*1000, (factor)*10000, (factor)*100000, \ (factor)*1000000, (factor)*10000000, (factor)*100000000, \ (factor)*1000000000 // Static data is placed in this class template for the header-only config. -template struct FMT_EXTERN_TEMPLATE_API basic_data { +template struct basic_data { static constexpr const uint32_t zero_or_powers_of_10_32[] = { 0, 0, FMT_POWERS_OF_10(1U)}; @@ -1005,10 +957,6 @@ FMT_INLINE uint16_t bsr2log10(int bsr) { return data[bsr]; } -#ifndef FMT_EXPORTED -FMT_EXTERN template struct FMT_INSTANTIATION_DECL_API basic_data; -#endif - template FMT_CONSTEXPR int count_digits_fallback(T n) { int count = 1; for (;;) { diff --git a/src/format.cc b/src/format.cc index 3a53f3a1c100..618aa07d0bb6 100644 --- a/src/format.cc +++ b/src/format.cc @@ -55,10 +55,6 @@ vformat_to(buffer&, string_view, type_identity_t>>); } // namespace detail -// Clang doesn't allow dllexport on template instantiation definitions: -// https://reviews.llvm.org/D61118. -template struct FMT_INSTANTIATION_DEF_API detail::basic_data; - // Workaround a bug in MSVC2013 that prevents instantiation of format_float. int (*instantiate_format_float)(double, int, detail::float_specs, detail::buffer&) = detail::format_float;