]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/src/c++17/floating_from_chars.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / src / c++17 / floating_from_chars.cc
index 11a9be68770fcdd535ab92fabdd013449a14f507..5d18ca32dbb3b23d71b0f194e6af935ed6d01766 100644 (file)
@@ -1,6 +1,6 @@
 // std::from_chars implementation for floating-point types -*- C++ -*-
 
-// Copyright (C) 2020-2022 Free Software Foundation, Inc.
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
 //
 // This file is part of the GNU ISO C++ Library.  This library is free
 // software; you can redistribute it and/or modify it under the
@@ -63,10 +63,11 @@ extern "C" __ieee128 __strtoieee128(const char*, char**);
       && defined(__GLIBC_PREREQ)
 #define USE_STRTOF128_FOR_FROM_CHARS 1
 extern "C" _Float128 __strtof128(const char*, char**)
+  __asm ("strtof128")
 #ifndef _GLIBCXX_HAVE_FLOAT128_MATH
   __attribute__((__weak__))
 #endif
-  __asm ("strtof128");
+  ;
 #endif
 
 #if _GLIBCXX_FLOAT_IS_IEEE_BINARY32 && _GLIBCXX_DOUBLE_IS_IEEE_BINARY64 \
@@ -631,7 +632,7 @@ namespace
          {
 #ifndef _GLIBCXX_HAVE_FLOAT128_MATH
            if (&__strtof128 == nullptr)
-             tmpval = _Float128(std::strtold(str, &endptr);
+             tmpval = _Float128(std::strtold(str, &endptr));
            else
 #endif
              tmpval = __strtof128(str, &endptr);
@@ -782,11 +783,16 @@ namespace
     using uint_t = conditional_t<is_same_v<T, float>, uint32_t,
                                 conditional_t<is_same_v<T, double>, uint64_t,
                                               uint16_t>>;
+#if USE_LIB_FAST_FLOAT
     constexpr int mantissa_bits
       = fast_float::binary_format<T>::mantissa_explicit_bits();
     constexpr int exponent_bits
       = is_same_v<T, double> ? 11
        : is_same_v<T, fast_float::floating_type_float16_t> ? 5 : 8;
+#else
+    constexpr int mantissa_bits = is_same_v<T, float> ? 23 : 52;
+    constexpr int exponent_bits = is_same_v<T, float> ? 8 : 11;
+#endif
     constexpr int exponent_bias = (1 << (exponent_bits - 1)) - 1;
 
     __glibcxx_requires_valid_range(first, last);
@@ -944,8 +950,11 @@ namespace
        else if (mantissa_idx >= -4)
          {
            if constexpr (is_same_v<T, float>
+#if USE_LIB_FAST_FLOAT
                          || is_same_v<T,
-                                      fast_float::floating_type_bfloat16_t>)
+                                      fast_float::floating_type_bfloat16_t>
+#endif
+                        )
              {
                __glibcxx_assert(mantissa_idx == -1);
                mantissa |= hexit >> 1;
@@ -1129,6 +1138,7 @@ namespace
       }
     if constexpr (is_same_v<T, float> || is_same_v<T, double>)
       memcpy(&value, &result, sizeof(result));
+#if USE_LIB_FAST_FLOAT
     else if constexpr (is_same_v<T, fast_float::floating_type_bfloat16_t>)
       {
        uint32_t res = uint32_t{result} << 16;
@@ -1155,6 +1165,7 @@ namespace
                 | ((uint32_t{result} & 0x8000) << 16));
        memcpy(value.x, &res, sizeof(res));
       }
+#endif
 
     return {first, errc{}};
   }