lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] odd/expm1_log1p 59fff893 4/4: Test gcc builtins for


From: Greg Chicares
Subject: [lmi-commits] [lmi] odd/expm1_log1p 59fff893 4/4: Test gcc builtins for certain transcendentals
Date: Thu, 19 May 2022 06:37:38 -0400 (EDT)

branch: odd/expm1_log1p
commit 59fff893554eff66f5dd097477a204f218692d7a
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Test gcc builtins for certain transcendentals
    
    __builtin_expm1() seems to behave differently between platforms--in
    these tests, lmi::foo() simply forwards to __builtin_foo():
    
    x86_64, sse, gcc, posix
      1.74560101501691655734305 std::expm1(1.01)
      0.00995033085316808334209 std::log1p(0.01)
      0.00327373978219886374239 std::expm1(std::log1p(0.04) / 12)
      1.74560101501691655734305 lmi::expm1(1.01)
      0.00995033085316808334209 lmi::log1p(0.01)
      0.00327373978219886374239 lmi::expm1(lmi::log1p(0.04) / 12)
    
    x86_64, sse, gcc, msw
      1.74560101501691633529845 std::expm1(1.01)
      0.00995033085316808334209 std::log1p(0.01)
      0.00327373978219886417607 std::expm1(std::log1p(0.04) / 12)
      1.74560101501691633529845 lmi::expm1(1.01)
      0.00995033085316808334209 lmi::log1p(0.01)
      0.00327373978219886417607 lmi::expm1(lmi::log1p(0.04) / 12)
    
    ...so either these builtins merely forward to the C RTL, or they differ
    by version:
    
    $gcc -v 2>&1 |grep "gcc version"
    gcc version 11.2.0 (Debian 11.2.0-13)
    
    $x86_64-w64-mingw32-gcc -v 2>&1 |grep "gcc version"
    gcc version 10-win32 20210110 (GCC)
    
    ...but they certainly don't behave the same across platforms and
    compiler versions.
---
 math_functions.hpp      | 31 ++++---------------------------
 math_functions_test.cpp |  4 ++--
 2 files changed, 6 insertions(+), 29 deletions(-)

diff --git a/math_functions.hpp b/math_functions.hpp
index c253bc27..df4f9180 100644
--- a/math_functions.hpp
+++ b/math_functions.hpp
@@ -24,8 +24,6 @@
 
 #include "config.hpp"
 
-#include "bourn_cast.hpp"
-
 #include <algorithm>                    // max(), min(), transform()
 #include <cmath>                        // expm1(), log1p(), signbit()
 #include <limits>
@@ -103,35 +101,14 @@ T signum(T t)
 
 namespace lmi
 {
-// Cf. lmi commit 16afb361c29 .
-
-#define LOGE2L  6.9314718055994530941723E-1L
-#define LOG2EL  1.4426950408889634073599E0L
-
-inline double expm1(long double x)
+inline double expm1(double x)
 {
-  if(std::fabs(x) < LOGE2L)
-      {
-      x *= LOG2EL;
-      __asm__("f2xm1" : "=t" (x) : "0" (x));
-      return bourn_cast<double>(x);
-      }
-  else
-    return bourn_cast<double>(std::exp(x) - 1.0);
+    return __builtin_expm1(x);
 }
 
-inline double log1p(long double x)
+inline double log1p(double x)
 {
-  if(std::fabs(x) < 1 - LOGE2L / 2)
-      {
-      long double y = LOGE2L;
-//    __asm__("fldln2");
-//    __asm__("fxch");
-      __asm__("fyl2xp1" : "=t" (x) : "0" (x), "u" (y) : "st(1)");
-      return bourn_cast<double>(x);
-      }
-  else
-    return bourn_cast<double>(std::log(1.0 + x));
+    return __builtin_log1p(x);
 }
 } // namespace lmi
 
diff --git a/math_functions_test.cpp b/math_functions_test.cpp
index 11f08c3d..2d8390e1 100644
--- a/math_functions_test.cpp
+++ b/math_functions_test.cpp
@@ -171,8 +171,8 @@ void sample_results()
         << ", by various methods:\n"
         << "      000000000111111111122\n"
         << "      123456789012345678901\n"
-        << "  " << i_upper_n_over_n_from_i      <long double,12>()(intrate)
-        << "  long double prec, production template\n"
+//      << "  " << i_upper_n_over_n_from_i      <long double,12>()(intrate)
+//      << "  long double prec, production template\n"
         ;
 #if defined LMI_X87
     fenv_precision(fe_ldblprec);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]