[PATCH 0/5] errno changes for libm

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 0/5] errno changes for libm

Sourceware - newlib list mailing list
Here's a series which reflects the review I did about newlib errno in
various math functions.

Patches 1-3 change the errno value used in gamma and y functions to
match the POSIX spec which uses ERANGE in several places that used to
set EDOM.

Patches 1-3 and patch 4 change POSIX math functions so that they don't
adjust values returned from the IEEE functions; none of those
adjustments were necessary, and some of them were incorrect when
compared with POSIX. This way, enabling errno support in the library
doesn't also change what the functions return.

Patch 5 is a proposed method for making newlib errno reporting
consistent between all math functions. It uses _IEEE_LIBM across the
whole library to select whether errno is set at library build
time. When _IEEE_LIBM is not set, errno is always set by math
functions when required. When _IEEE_LIBM is set, errno is never
modified by math functions.


Reply | Threaded
Open this post in threaded view
|

[PATCH 1/5] libm/math: set errno to ERANGE at gamma poles

Sourceware - newlib list mailing list
For POSIX, gamma(i) (i non-positive integer) should set errno to
ERANGE instead of EDOM.

Signed-off-by: Keith Packard <[hidden email]>
---
 newlib/libm/math/w_gamma.c   | 14 ++++----------
 newlib/libm/math/w_lgamma.c  | 13 ++++---------
 newlib/libm/math/wf_gamma.c  | 14 ++++----------
 newlib/libm/math/wf_lgamma.c | 14 ++++----------
 4 files changed, 16 insertions(+), 39 deletions(-)

diff --git a/newlib/libm/math/w_gamma.c b/newlib/libm/math/w_gamma.c
index cfded7b5d..b65d5cc4b 100644
--- a/newlib/libm/math/w_gamma.c
+++ b/newlib/libm/math/w_gamma.c
@@ -155,16 +155,10 @@ in terms of the base return values, although the <[signgam]> global for
         y = __ieee754_gamma_r(x,&(_REENT_SIGNGAM(_REENT)));
         if(_LIB_VERSION == _IEEE_) return y;
         if(!finite(y)&&finite(x)) {
-    if(floor(x)==x&&x<=0.0) {
- /* gamma(-integer) or gamma(0) */
- errno = EDOM;
-    } else {
- /* gamma(finite) overflow */
- errno = ERANGE;
-    }
-    return HUGE_VAL;
-        } else
-            return y;
+    /* gamma(finite) overflow */
+    errno = ERANGE;
+        }
+ return y;
 #endif
 }            
 
diff --git a/newlib/libm/math/w_lgamma.c b/newlib/libm/math/w_lgamma.c
index 25d12c9c7..c07804779 100644
--- a/newlib/libm/math/w_lgamma.c
+++ b/newlib/libm/math/w_lgamma.c
@@ -38,15 +38,10 @@
         y = __ieee754_lgamma_r(x,&(_REENT_SIGNGAM(_REENT)));
         if(_LIB_VERSION == _IEEE_) return y;
         if(!finite(y)&&finite(x)) {
-    if(floor(x)==x&&x<=0.0)
-      /* lgamma(-integer) */
-      errno = EDOM;
-    else
-      /* lgamma(finite) overflow */
-      errno = ERANGE;
-    return HUGE_VAL;
- } else
-            return y;
+    /* lgamma(finite) overflow */
+    errno = ERANGE;
+ }
+ return y;
 #endif
 }            
 
diff --git a/newlib/libm/math/wf_gamma.c b/newlib/libm/math/wf_gamma.c
index 0235ff4db..f0284a282 100644
--- a/newlib/libm/math/wf_gamma.c
+++ b/newlib/libm/math/wf_gamma.c
@@ -32,16 +32,10 @@
         y = __ieee754_gammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
         if(_LIB_VERSION == _IEEE_) return y;
         if(!finitef(y)&&finitef(x)) {
-    if(floorf(x)==x&&x<=0.0f) {
- /* gammaf(-integer) or gammaf(0) */
- errno = EDOM;
-            } else {
- /* gammaf(finite) overflow */
- errno = ERANGE;
-            }
-    return HUGE_VALF;
-        } else
-            return y;
+    /* gammaf(finite) overflow */
+    errno = ERANGE;
+        }
+ return y;
 #endif
 }            
 
diff --git a/newlib/libm/math/wf_lgamma.c b/newlib/libm/math/wf_lgamma.c
index c644072e4..b232ecfe4 100644
--- a/newlib/libm/math/wf_lgamma.c
+++ b/newlib/libm/math/wf_lgamma.c
@@ -32,16 +32,10 @@
         y = __ieee754_lgammaf_r(x,&(_REENT_SIGNGAM(_REENT)));
         if(_LIB_VERSION == _IEEE_) return y;
         if(!finitef(y)&&finitef(x)) {
-    if(floorf(x)==x&&x<=0.0f) {
- /* lgammaf(-integer) */
- errno = EDOM;
-    } else {
- /* lgammaf(finite) overflow */
- errno = ERANGE;
-    }
-            return HUGE_VALF;
-        } else
-            return y;
+    /* lgammaf(finite) overflow */
+    errno = ERANGE;
+        }
+ return y;
 #endif
 }            
 
--
2.28.0

Reply | Threaded
Open this post in threaded view
|

[PATCH 2/5] libm/math: Make yx functions set errno=ERANGE for x=0

Sourceware - newlib list mailing list
In reply to this post by Sourceware - newlib list mailing list
The y0, y1 and yn functions need separate conditions when x is zero as
that returns ERANGE instead of EDOM.

Also stop adjusting the return value from the __ieee754_y* functions
as that is already correct and we were just breaking it.

Signed-off-by: Keith Packard <[hidden email]>
---
 newlib/libm/math/w_j0.c  | 14 ++++++++------
 newlib/libm/math/w_j1.c  | 14 ++++++++------
 newlib/libm/math/w_jn.c  | 14 ++++++++------
 newlib/libm/math/wf_j0.c | 19 ++++++++++---------
 newlib/libm/math/wf_j1.c | 14 ++++++++------
 newlib/libm/math/wf_jn.c | 19 ++++++++++---------
 6 files changed, 52 insertions(+), 42 deletions(-)

diff --git a/newlib/libm/math/w_j0.c b/newlib/libm/math/w_j0.c
index b537ef406..47063ff6f 100644
--- a/newlib/libm/math/w_j0.c
+++ b/newlib/libm/math/w_j0.c
@@ -128,17 +128,19 @@ None of the Bessel functions are in ANSI C.
  double z;
  z = __ieee754_y0(x);
  if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
-        if(x <= 0.0){
-    /* y0(0) = -inf or y0(x<0) = NaN */
+        if(x < 0.0){
+    /* y0(x<0) = NaN */
     errno = EDOM;
-    return -HUGE_VAL;
+        }
+        if(x == 0.0){
+    /* y0(0) = -inf */
+    errno = ERANGE;
         }
  if(x>X_TLOSS) {
     /* y0(x>X_TLOSS) */
     errno = ERANGE;
-    return 0.0;
- } else
-    return z;
+ }
+ return z;
 #endif
 }
 
diff --git a/newlib/libm/math/w_j1.c b/newlib/libm/math/w_j1.c
index 6f25fea27..0912b6776 100644
--- a/newlib/libm/math/w_j1.c
+++ b/newlib/libm/math/w_j1.c
@@ -55,17 +55,19 @@
  double z;
  z = __ieee754_y1(x);
  if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
-        if(x <= 0.0){
-    /* y1(0) = -inf  or y1(x<0) = NaN */
+        if(x < 0.0){
+    /* y1(x<0) = NaN */
     errno = EDOM;
-    return -HUGE_VAL;
+        }
+        if(x == 0.0){
+    /* y1(0) = -inf */
+    errno = ERANGE;
         }
  if(x>X_TLOSS) {
     /* y1(x>X_TLOSS) */
     errno = ERANGE;
-    return 0.0;
- } else
-    return z;
+ }
+ return z;
 #endif
 }
 
diff --git a/newlib/libm/math/w_jn.c b/newlib/libm/math/w_jn.c
index 28a9abc07..4e770ea5c 100644
--- a/newlib/libm/math/w_jn.c
+++ b/newlib/libm/math/w_jn.c
@@ -77,17 +77,19 @@
  double z;
  z = __ieee754_yn(n,x);
  if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
-        if(x <= 0.0){
-    /* yn(n,0) = -inf or yn(x<0) = NaN */
+        if(x < 0.0){
+    /* yn(x<0) = NaN */
     errno = EDOM;
-    return -HUGE_VAL;
+        }
+        if(x == 0.0){
+    /* yn(0) = -inf */
+    errno = ERANGE;
         }
  if(x>X_TLOSS) {
     /* yn(x>X_TLOSS) */
     errno = ERANGE;
-    return 0.0;
- } else
-    return z;
+ }
+ return z;
 #endif
 }
 
diff --git a/newlib/libm/math/wf_j0.c b/newlib/libm/math/wf_j0.c
index 4d125db79..ed21a01f5 100644
--- a/newlib/libm/math/wf_j0.c
+++ b/newlib/libm/math/wf_j0.c
@@ -35,9 +35,8 @@
  if(fabsf(x)>(float)X_TLOSS) {
     /* j0f(|x|>X_TLOSS) */
     errno = ERANGE;
-    return 0.0f;
- } else
-    return z;
+ }
+ return z;
 #endif
 }
 
@@ -54,17 +53,19 @@
  float z;
  z = __ieee754_y0f(x);
  if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
-        if(x <= (float)0.0){
-    /* y0f(0) = -inf  or y0f(x<0) = NaN */
+        if(x < 0.0f){
+    /* y0f(x<0) = NaN */
     errno = EDOM;
-    return -HUGE_VALF;
         }
+ if (x == 0.0f){
+    /* y0f(n,0) = -inf */
+    errno = ERANGE;
+ }
  if(x>(float)X_TLOSS) {
     /* y0f(x>X_TLOSS) */
     errno = ERANGE;
-    return 0.0f;
- } else
-    return z;
+ }
+ return z;
 #endif
 }
 
diff --git a/newlib/libm/math/wf_j1.c b/newlib/libm/math/wf_j1.c
index e178273c5..a4609ba28 100644
--- a/newlib/libm/math/wf_j1.c
+++ b/newlib/libm/math/wf_j1.c
@@ -56,17 +56,19 @@
  float z;
  z = __ieee754_y1f(x);
  if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
-        if(x <= 0.0f){
-    /* y1f(0) = -inf or y1f(x<0) = NaN */
+        if(x < 0.0f){
+    /* y1f(x<0) = NaN */
     errno = EDOM;
-    return -HUGE_VALF;
         }
+ if (x == 0.0f){
+    /* y1f(n,0) = -inf */
+    errno = ERANGE;
+ }
  if(x>(float)X_TLOSS) {
     /* y1f(x>X_TLOSS) */
     errno = ERANGE;
-    return 0.0f;
- } else
-    return z;
+ }
+ return z;
 #endif
 }
 
diff --git a/newlib/libm/math/wf_jn.c b/newlib/libm/math/wf_jn.c
index 3e4632ead..b82346d79 100644
--- a/newlib/libm/math/wf_jn.c
+++ b/newlib/libm/math/wf_jn.c
@@ -33,9 +33,8 @@
  if(fabsf(x)>(float)X_TLOSS) {
     /* jnf(|x|>X_TLOSS) */
     errno = ERANGE;
-    return 0.0f;
- } else
-    return z;
+ }
+ return z;
 #endif
 }
 
@@ -52,17 +51,19 @@
  float z;
  z = __ieee754_ynf(n,x);
  if(_LIB_VERSION == _IEEE_ || isnan(x) ) return z;
-        if(x <= 0.0f){
-    /* ynf(n,0) = -inf or ynf(x<0) = NaN */
+        if(x < 0.0f){
+    /* ynf(x<0) = NaN */
     errno = EDOM;
-    return -HUGE_VALF;
         }
+ if (x == 0.0f){
+    /* ynf(n,0) = -inf */
+    errno = ERANGE;
+ }
  if(x>(float)X_TLOSS) {
     /* ynf(x>X_TLOSS) */
     errno = ERANGE;
-    return 0.0f;
- } else
-    return z;
+ }
+ return z;
 #endif
 }
 
--
2.28.0

Reply | Threaded
Open this post in threaded view
|

[PATCH 3/5] libm/math: Set errno to ERANGE for pow(0, -y)

Sourceware - newlib list mailing list
In reply to this post by Sourceware - newlib list mailing list
POSIX says that the errno for pow(0, -y) should be ERANGE instead of
EDOM.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/pow.html

Signed-off-by: Keith Packard <[hidden email]>
---
 newlib/libm/math/w_pow.c  | 3 +--
 newlib/libm/math/wf_pow.c | 3 +--
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/newlib/libm/math/w_pow.c b/newlib/libm/math/w_pow.c
index 6e953360a..d8556a170 100644
--- a/newlib/libm/math/w_pow.c
+++ b/newlib/libm/math/w_pow.c
@@ -84,8 +84,7 @@ PORTABILITY
     }
     if(finite(y)&&y<0.0) {
  /* 0**neg */
- errno = EDOM;
- return -HUGE_VAL;
+ errno = ERANGE;
     }
     return z;
  }
diff --git a/newlib/libm/math/wf_pow.c b/newlib/libm/math/wf_pow.c
index 73648b83f..e551e6b48 100644
--- a/newlib/libm/math/wf_pow.c
+++ b/newlib/libm/math/wf_pow.c
@@ -50,8 +50,7 @@
     }
     if(finitef(y)&&y<0.0f) {
  /* 0**neg */
- errno = EDOM;
- return -HUGE_VALF;
+ errno = ERANGE;
     }
     return z;
  }
--
2.28.0

Reply | Threaded
Open this post in threaded view
|

[PATCH 4/5] libm/math: Don't modify __ieee754_pow return values in pow

Sourceware - newlib list mailing list
In reply to this post by Sourceware - newlib list mailing list
The __ieee754 functions already return the right value in exception
cases, so don't modify those. Setting the library to _POSIX_/_IEEE_
mode now only affects whether errno is modified.

Signed-off-by: Keith Packard <[hidden email]>
---
 newlib/libm/math/w_pow.c  | 14 +-------------
 newlib/libm/math/wf_pow.c | 14 +-------------
 2 files changed, 2 insertions(+), 26 deletions(-)

diff --git a/newlib/libm/math/w_pow.c b/newlib/libm/math/w_pow.c
index d8556a170..cf6099cf4 100644
--- a/newlib/libm/math/w_pow.c
+++ b/newlib/libm/math/w_pow.c
@@ -68,14 +68,6 @@ PORTABILITY
  double z;
  z=__ieee754_pow(x,y);
  if(_LIB_VERSION == _IEEE_|| isnan(y)) return z;
- if(isnan(x)) {
-    if(y==0.0) {
- /* pow(NaN,0.0) */
- /* Not an error.  */
-                return 1.0;
-    } else
- return z;
- }
  if(x==0.0){
     if(y==0.0) {
  /* pow(0.0,0.0) */
@@ -93,20 +85,16 @@ PORTABILITY
         if(isnan(z)) {
     /* neg**non-integral */
     errno = EDOM;
-    return 0.0/0.0;
         } else {
     /* pow(x,y) overflow */
     errno = ERANGE;
-    if(x<0.0&&rint(y)!=y)
-      return -HUGE_VAL;
-    return HUGE_VAL;
                 }
+ return z;
     }
  }
  if(z==0.0&&finite(x)&&finite(y)) {
     /* pow(x,y) underflow */
     errno = ERANGE;
-    return 0.0;
         }
  return z;
 #endif
diff --git a/newlib/libm/math/wf_pow.c b/newlib/libm/math/wf_pow.c
index e551e6b48..e9babf67c 100644
--- a/newlib/libm/math/wf_pow.c
+++ b/newlib/libm/math/wf_pow.c
@@ -34,14 +34,6 @@
  float z;
  z=__ieee754_powf(x,y);
  if(_LIB_VERSION == _IEEE_|| isnan(y)) return z;
- if(isnan(x)) {
-    if(y==0.0f) {
- /* powf(NaN,0.0) */
- /* Not an error.  */
- return 1.0f;
-    } else
- return z;
- }
  if(x==0.0f){
     if(y==0.0f) {
  /* powf(0.0,0.0) */
@@ -61,20 +53,16 @@
     errno = EDOM;
     /* Use a float divide, to avoid a soft-float double
        divide call on single-float only targets.  */
-    return 0.0f/0.0f;
  } else {
     /* powf(x,y) overflow */
     errno = ERANGE;
-    if(x<0.0f&&rintf(y)!=y)
-      return -HUGE_VALF;
-    return HUGE_VALF;
  }
+ return z;
     }
  }
  if(z==0.0f&&finitef(x)&&finitef(y)) {
     /* powf(x,y) underflow */
     errno = ERANGE;
-    return 0.0f;
         }
  return z;
 #endif
--
2.28.0

Reply | Threaded
Open this post in threaded view
|

[PATCH 5/5] libm: Control errno support with _IEEE_LIBM configuration parameter

Sourceware - newlib list mailing list
In reply to this post by Sourceware - newlib list mailing list
This removes the run-time configuration of errno support present in
portions of the math library and unifies all of the compile-time errno
configuration under a single parameter so that the whole library
is consistent.

The run-time support provided by _LIB_VERSION is no longer present in
the public API, although it is still used internally to disable errno
setting in some functions. Now that it is a constant, the compiler should
remove that code when errno is not supported.

This removes s_lib_ver.c as _LIB_VERSION is no longer variable.

Signed-off-by: Keith Packard <[hidden email]>
---
 newlib/libc/include/math.h       | 16 ---------------
 newlib/libm/common/Makefile.am   |  2 +-
 newlib/libm/common/Makefile.in   | 11 ++--------
 newlib/libm/common/fdlibm.h      |  1 +
 newlib/libm/common/math_config.h |  5 +++++
 newlib/libm/common/s_lib_ver.c   | 35 --------------------------------
 6 files changed, 9 insertions(+), 61 deletions(-)
 delete mode 100644 newlib/libm/common/s_lib_ver.c

diff --git a/newlib/libc/include/math.h b/newlib/libc/include/math.h
index 9fd82d9fa..5e6155cc4 100644
--- a/newlib/libc/include/math.h
+++ b/newlib/libc/include/math.h
@@ -612,22 +612,6 @@ extern int *__signgam (void);
 #define M_LOG2_E        _M_LN2
 #define M_INVLN2        1.4426950408889633870E0  /* 1 / log(2) */
 
-/* Global control over fdlibm error handling.  */
-
-enum __fdlibm_version
-{
-  __fdlibm_ieee = -1,
-  __fdlibm_posix
-};
-
-#define _LIB_VERSION_TYPE enum __fdlibm_version
-#define _LIB_VERSION __fdlib_version
-
-extern __IMPORT _LIB_VERSION_TYPE _LIB_VERSION;
-
-#define _IEEE_  __fdlibm_ieee
-#define _POSIX_ __fdlibm_posix
-
 #endif /* __BSD_VISIBLE */
 
 _END_STD_C
diff --git a/newlib/libm/common/Makefile.am b/newlib/libm/common/Makefile.am
index 1eef0236a..1d178da4d 100644
--- a/newlib/libm/common/Makefile.am
+++ b/newlib/libm/common/Makefile.am
@@ -8,7 +8,7 @@ src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \
  s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \
  s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
  s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
- s_rint.c s_logb.c s_log2.c s_lib_ver.c \
+ s_rint.c s_logb.c s_log2.c \
  s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
  s_lrint.c s_llrint.c \
  s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
diff --git a/newlib/libm/common/Makefile.in b/newlib/libm/common/Makefile.in
index 2caf7dd6c..b1098565f 100644
--- a/newlib/libm/common/Makefile.in
+++ b/newlib/libm/common/Makefile.in
@@ -85,7 +85,6 @@ am__objects_1 = lib_a-s_finite.$(OBJEXT) lib_a-s_copysign.$(OBJEXT) \
  lib_a-s_nan.$(OBJEXT) lib_a-s_nextafter.$(OBJEXT) \
  lib_a-s_pow10.$(OBJEXT) lib_a-s_rint.$(OBJEXT) \
  lib_a-s_logb.$(OBJEXT) lib_a-s_log2.$(OBJEXT) \
- lib_a-s_lib_ver.$(OBJEXT) lib_a-s_fdim.$(OBJEXT) \
  lib_a-s_fma.$(OBJEXT) lib_a-s_fmax.$(OBJEXT) \
  lib_a-s_fmin.$(OBJEXT) lib_a-s_fpclassify.$(OBJEXT) \
  lib_a-s_lrint.$(OBJEXT) lib_a-s_llrint.$(OBJEXT) \
@@ -163,7 +162,7 @@ am__objects_5 = s_finite.lo s_copysign.lo s_modf.lo s_scalbn.lo \
  s_cbrt.lo s_exp10.lo s_expm1.lo s_ilogb.lo s_infinity.lo \
  s_isinf.lo s_isinfd.lo s_isnan.lo s_isnand.lo s_log1p.lo \
  s_nan.lo s_nextafter.lo s_pow10.lo s_rint.lo s_logb.lo \
- s_log2.lo s_lib_ver.lo s_fdim.lo s_fma.lo s_fmax.lo s_fmin.lo \
+ s_log2.lo s_fdim.lo s_fma.lo s_fmax.lo s_fmin.lo \
  s_fpclassify.lo s_lrint.lo s_llrint.lo s_lround.lo \
  s_llround.lo s_nearbyint.lo s_remquo.lo s_round.lo \
  s_scalbln.lo s_signbit.lo s_trunc.lo exp.lo exp2.lo \
@@ -354,7 +353,7 @@ src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \
  s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \
  s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
  s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
- s_rint.c s_logb.c s_log2.c s_lib_ver.c \
+ s_rint.c s_logb.c s_log2.c \
  s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
  s_lrint.c s_llrint.c \
  s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
@@ -602,12 +601,6 @@ lib_a-s_log2.o: s_log2.c
 lib_a-s_log2.obj: s_log2.c
  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_log2.obj `if test -f 's_log2.c'; then $(CYGPATH_W) 's_log2.c'; else $(CYGPATH_W) '$(srcdir)/s_log2.c'; fi`
 
-lib_a-s_lib_ver.o: s_lib_ver.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lib_ver.o `test -f 's_lib_ver.c' || echo '$(srcdir)/'`s_lib_ver.c
-
-lib_a-s_lib_ver.obj: s_lib_ver.c
- $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lib_ver.obj `if test -f 's_lib_ver.c'; then $(CYGPATH_W) 's_lib_ver.c'; else $(CYGPATH_W) '$(srcdir)/s_lib_ver.c'; fi`
-
 lib_a-s_fdim.o: s_fdim.c
  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fdim.o `test -f 's_fdim.c' || echo '$(srcdir)/'`s_fdim.c
 
diff --git a/newlib/libm/common/fdlibm.h b/newlib/libm/common/fdlibm.h
index 8dfff243d..8dffc832d 100644
--- a/newlib/libm/common/fdlibm.h
+++ b/newlib/libm/common/fdlibm.h
@@ -15,6 +15,7 @@
 #include <math.h>
 #include <sys/types.h>
 #include <machine/ieeefp.h>
+#include "math_config.h"
 
 /* Most routines need to check whether a float is finite, infinite, or not a
    number, and many need to know whether the result of an operation will
diff --git a/newlib/libm/common/math_config.h b/newlib/libm/common/math_config.h
index 3be7e6320..1089b0ec6 100644
--- a/newlib/libm/common/math_config.h
+++ b/newlib/libm/common/math_config.h
@@ -38,15 +38,20 @@
 #endif
 #ifdef _IEEE_LIBM
 # define WANT_ERRNO 0
+# define _LIB_VERSION _IEEE_
 #else
 /* Set errno according to ISO C with (math_errhandling & MATH_ERRNO) != 0.  */
 # define WANT_ERRNO 1
+# define _LIB_VERSION _POSIX_
 #endif
 #ifndef WANT_ERRNO_UFLOW
 /* Set errno to ERANGE if result underflows to 0 (in all rounding modes).  */
 # define WANT_ERRNO_UFLOW (WANT_ROUNDING && WANT_ERRNO)
 #endif
 
+#define _IEEE_  -1
+#define _POSIX_ 0
+
 /* Compiler can inline round as a single instruction.  */
 #ifndef HAVE_FAST_ROUND
 # if __aarch64__
diff --git a/newlib/libm/common/s_lib_ver.c b/newlib/libm/common/s_lib_ver.c
deleted file mode 100644
index 8da03b79a..000000000
--- a/newlib/libm/common/s_lib_ver.c
+++ /dev/null
@@ -1,35 +0,0 @@
-
-/* @(#)s_lib_ver.c 5.1 93/09/24 */
-/*
- * ====================================================
- * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
- *
- * Developed at SunPro, a Sun Microsystems, Inc. business.
- * Permission to use, copy, modify, and distribute this
- * software is freely granted, provided that this notice
- * is preserved.
- * ====================================================
- */
-
-/*
- * MACRO for standards
- */
-
-#include "fdlibm.h"
-
-/*
- * define and initialize _LIB_VERSION
- */
-#ifdef _POSIX_MODE
-_LIB_VERSION_TYPE _LIB_VERSION = _POSIX_;
-#else
-#ifdef _XOPEN_MODE
-#error _XOPEN_MODE is unsupported
-#else
-#ifdef _SVID3_MODE
-#error _SVID3_MODE is unsupported
-#else /* default _IEEE_MODE */
-_LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;
-#endif
-#endif
-#endif
--
2.28.0

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 5/5] libm: Control errno support with _IEEE_LIBM configuration parameter

Sourceware - newlib list mailing list
On Aug  4 15:22, Keith Packard via Newlib wrote:

> This removes the run-time configuration of errno support present in
> portions of the math library and unifies all of the compile-time errno
> configuration under a single parameter so that the whole library
> is consistent.
>
> The run-time support provided by _LIB_VERSION is no longer present in
> the public API, although it is still used internally to disable errno
> setting in some functions. Now that it is a constant, the compiler should
> remove that code when errno is not supported.
>
> This removes s_lib_ver.c as _LIB_VERSION is no longer variable.

This math stuff is a bit over my head.  IIUC, the default is
NOT setting _IEEE_LIBM, which results in the defauklt behaviour
today.  That's what I care most about: Not introducing backward
incompatible settings into Cygwin.


Corinna

>
> Signed-off-by: Keith Packard <[hidden email]>
> ---
>  newlib/libc/include/math.h       | 16 ---------------
>  newlib/libm/common/Makefile.am   |  2 +-
>  newlib/libm/common/Makefile.in   | 11 ++--------
>  newlib/libm/common/fdlibm.h      |  1 +
>  newlib/libm/common/math_config.h |  5 +++++
>  newlib/libm/common/s_lib_ver.c   | 35 --------------------------------
>  6 files changed, 9 insertions(+), 61 deletions(-)
>  delete mode 100644 newlib/libm/common/s_lib_ver.c
>
> diff --git a/newlib/libc/include/math.h b/newlib/libc/include/math.h
> index 9fd82d9fa..5e6155cc4 100644
> --- a/newlib/libc/include/math.h
> +++ b/newlib/libc/include/math.h
> @@ -612,22 +612,6 @@ extern int *__signgam (void);
>  #define M_LOG2_E        _M_LN2
>  #define M_INVLN2        1.4426950408889633870E0  /* 1 / log(2) */
>  
> -/* Global control over fdlibm error handling.  */
> -
> -enum __fdlibm_version
> -{
> -  __fdlibm_ieee = -1,
> -  __fdlibm_posix
> -};
> -
> -#define _LIB_VERSION_TYPE enum __fdlibm_version
> -#define _LIB_VERSION __fdlib_version
> -
> -extern __IMPORT _LIB_VERSION_TYPE _LIB_VERSION;
> -
> -#define _IEEE_  __fdlibm_ieee
> -#define _POSIX_ __fdlibm_posix
> -
>  #endif /* __BSD_VISIBLE */
>  
>  _END_STD_C
> diff --git a/newlib/libm/common/Makefile.am b/newlib/libm/common/Makefile.am
> index 1eef0236a..1d178da4d 100644
> --- a/newlib/libm/common/Makefile.am
> +++ b/newlib/libm/common/Makefile.am
> @@ -8,7 +8,7 @@ src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \
>   s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \
>   s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
>   s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
> - s_rint.c s_logb.c s_log2.c s_lib_ver.c \
> + s_rint.c s_logb.c s_log2.c \
>   s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
>   s_lrint.c s_llrint.c \
>   s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
> diff --git a/newlib/libm/common/Makefile.in b/newlib/libm/common/Makefile.in
> index 2caf7dd6c..b1098565f 100644
> --- a/newlib/libm/common/Makefile.in
> +++ b/newlib/libm/common/Makefile.in
> @@ -85,7 +85,6 @@ am__objects_1 = lib_a-s_finite.$(OBJEXT) lib_a-s_copysign.$(OBJEXT) \
>   lib_a-s_nan.$(OBJEXT) lib_a-s_nextafter.$(OBJEXT) \
>   lib_a-s_pow10.$(OBJEXT) lib_a-s_rint.$(OBJEXT) \
>   lib_a-s_logb.$(OBJEXT) lib_a-s_log2.$(OBJEXT) \
> - lib_a-s_lib_ver.$(OBJEXT) lib_a-s_fdim.$(OBJEXT) \
>   lib_a-s_fma.$(OBJEXT) lib_a-s_fmax.$(OBJEXT) \
>   lib_a-s_fmin.$(OBJEXT) lib_a-s_fpclassify.$(OBJEXT) \
>   lib_a-s_lrint.$(OBJEXT) lib_a-s_llrint.$(OBJEXT) \
> @@ -163,7 +162,7 @@ am__objects_5 = s_finite.lo s_copysign.lo s_modf.lo s_scalbn.lo \
>   s_cbrt.lo s_exp10.lo s_expm1.lo s_ilogb.lo s_infinity.lo \
>   s_isinf.lo s_isinfd.lo s_isnan.lo s_isnand.lo s_log1p.lo \
>   s_nan.lo s_nextafter.lo s_pow10.lo s_rint.lo s_logb.lo \
> - s_log2.lo s_lib_ver.lo s_fdim.lo s_fma.lo s_fmax.lo s_fmin.lo \
> + s_log2.lo s_fdim.lo s_fma.lo s_fmax.lo s_fmin.lo \
>   s_fpclassify.lo s_lrint.lo s_llrint.lo s_lround.lo \
>   s_llround.lo s_nearbyint.lo s_remquo.lo s_round.lo \
>   s_scalbln.lo s_signbit.lo s_trunc.lo exp.lo exp2.lo \
> @@ -354,7 +353,7 @@ src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \
>   s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \
>   s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
>   s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
> - s_rint.c s_logb.c s_log2.c s_lib_ver.c \
> + s_rint.c s_logb.c s_log2.c \
>   s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
>   s_lrint.c s_llrint.c \
>   s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
> @@ -602,12 +601,6 @@ lib_a-s_log2.o: s_log2.c
>  lib_a-s_log2.obj: s_log2.c
>   $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_log2.obj `if test -f 's_log2.c'; then $(CYGPATH_W) 's_log2.c'; else $(CYGPATH_W) '$(srcdir)/s_log2.c'; fi`
>  
> -lib_a-s_lib_ver.o: s_lib_ver.c
> - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lib_ver.o `test -f 's_lib_ver.c' || echo '$(srcdir)/'`s_lib_ver.c
> -
> -lib_a-s_lib_ver.obj: s_lib_ver.c
> - $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_lib_ver.obj `if test -f 's_lib_ver.c'; then $(CYGPATH_W) 's_lib_ver.c'; else $(CYGPATH_W) '$(srcdir)/s_lib_ver.c'; fi`
> -
>  lib_a-s_fdim.o: s_fdim.c
>   $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-s_fdim.o `test -f 's_fdim.c' || echo '$(srcdir)/'`s_fdim.c
>  
> diff --git a/newlib/libm/common/fdlibm.h b/newlib/libm/common/fdlibm.h
> index 8dfff243d..8dffc832d 100644
> --- a/newlib/libm/common/fdlibm.h
> +++ b/newlib/libm/common/fdlibm.h
> @@ -15,6 +15,7 @@
>  #include <math.h>
>  #include <sys/types.h>
>  #include <machine/ieeefp.h>
> +#include "math_config.h"
>  
>  /* Most routines need to check whether a float is finite, infinite, or not a
>     number, and many need to know whether the result of an operation will
> diff --git a/newlib/libm/common/math_config.h b/newlib/libm/common/math_config.h
> index 3be7e6320..1089b0ec6 100644
> --- a/newlib/libm/common/math_config.h
> +++ b/newlib/libm/common/math_config.h
> @@ -38,15 +38,20 @@
>  #endif
>  #ifdef _IEEE_LIBM
>  # define WANT_ERRNO 0
> +# define _LIB_VERSION _IEEE_
>  #else
>  /* Set errno according to ISO C with (math_errhandling & MATH_ERRNO) != 0.  */
>  # define WANT_ERRNO 1
> +# define _LIB_VERSION _POSIX_
>  #endif
>  #ifndef WANT_ERRNO_UFLOW
>  /* Set errno to ERANGE if result underflows to 0 (in all rounding modes).  */
>  # define WANT_ERRNO_UFLOW (WANT_ROUNDING && WANT_ERRNO)
>  #endif
>  
> +#define _IEEE_  -1
> +#define _POSIX_ 0
> +
>  /* Compiler can inline round as a single instruction.  */
>  #ifndef HAVE_FAST_ROUND
>  # if __aarch64__
> diff --git a/newlib/libm/common/s_lib_ver.c b/newlib/libm/common/s_lib_ver.c
> deleted file mode 100644
> index 8da03b79a..000000000
> --- a/newlib/libm/common/s_lib_ver.c
> +++ /dev/null
> @@ -1,35 +0,0 @@
> -
> -/* @(#)s_lib_ver.c 5.1 93/09/24 */
> -/*
> - * ====================================================
> - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
> - *
> - * Developed at SunPro, a Sun Microsystems, Inc. business.
> - * Permission to use, copy, modify, and distribute this
> - * software is freely granted, provided that this notice
> - * is preserved.
> - * ====================================================
> - */
> -
> -/*
> - * MACRO for standards
> - */
> -
> -#include "fdlibm.h"
> -
> -/*
> - * define and initialize _LIB_VERSION
> - */
> -#ifdef _POSIX_MODE
> -_LIB_VERSION_TYPE _LIB_VERSION = _POSIX_;
> -#else
> -#ifdef _XOPEN_MODE
> -#error _XOPEN_MODE is unsupported
> -#else
> -#ifdef _SVID3_MODE
> -#error _SVID3_MODE is unsupported
> -#else /* default _IEEE_MODE */
> -_LIB_VERSION_TYPE _LIB_VERSION = _IEEE_;
> -#endif
> -#endif
> -#endif
> --
> 2.28.0

--
Corinna Vinschen
Cygwin Maintainer
Red Hat

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 5/5] libm: Control errno support with _IEEE_LIBM configuration parameter

Sourceware - newlib list mailing list
Corinna Vinschen via Newlib <[hidden email]> writes:

> This math stuff is a bit over my head.  IIUC, the default is
> NOT setting _IEEE_LIBM, which results in the defauklt behaviour
> today.  That's what I care most about: Not introducing backward
> incompatible settings into Cygwin.

TL;DR summary:

The only effect on Cygwin will be to enable errno reporting for the few
functions coming from libm/math.

Longer discussion:

There are a lot of inter-related standards and I feel like I'm
down the rabbit hole on a lot of this. I think this particular issue can
be understood at a fairly high level as one of identifying inconsistent
semantics across the math library and then trying to identify ways to
fix that.

The new math code (libm/common) has errno enabled unless you set
WANT_ERRNO=0 (which no included configuration does).

The old math code (libm/math) has the errno code compiled-in unless you
define _IEEE_LIBM (which no configuration does). When _IEEE_LIBM is
defined, most (but not all) of the errno-setting code is removed.
However, the errno code in libm/math is also controlled by a run-time
conditional, _LIB_VERSION, which blocks the errno behavior *unless* the
global variable _LIB_VERSION is set to _POSIX_, which is not the default
on anything other than the spu build.

So, the current Cygwin behavior has most functions always setting errno
(those from libm/common), but some functions (those from libm/math) only
setting errno if the application happens to know about _LIB_VERSION and
sets that to _POSIX_.

This patch tries to simplify things so that one single global
compile-time define, _IEEE_LIBM, controls whether errno is ever modified
by the math library, and removes the run-time behavior controlled by
_LIB_VERSION.

--
-keith

signature.asc (847 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 5/5] libm: Control errno support with _IEEE_LIBM configuration parameter

Sourceware - newlib list mailing list
In reply to this post by Sourceware - newlib list mailing list
Hi Keith,

On Aug  4 15:22, Keith Packard via Newlib wrote:

> This removes the run-time configuration of errno support present in
> portions of the math library and unifies all of the compile-time errno
> configuration under a single parameter so that the whole library
> is consistent.
>
> The run-time support provided by _LIB_VERSION is no longer present in
> the public API, although it is still used internally to disable errno
> setting in some functions. Now that it is a constant, the compiler should
> remove that code when errno is not supported.
>
> This removes s_lib_ver.c as _LIB_VERSION is no longer variable.
>
> Signed-off-by: Keith Packard <[hidden email]>
> ---
> [...]
> diff --git a/newlib/libm/common/Makefile.am b/newlib/libm/common/Makefile.am
> index 1eef0236a..1d178da4d 100644
> --- a/newlib/libm/common/Makefile.am
> +++ b/newlib/libm/common/Makefile.am
> @@ -8,7 +8,7 @@ src = s_finite.c s_copysign.c s_modf.c s_scalbn.c \
>   s_cbrt.c s_exp10.c s_expm1.c s_ilogb.c \
>   s_infinity.c s_isinf.c s_isinfd.c s_isnan.c s_isnand.c \
>   s_log1p.c s_nan.c s_nextafter.c s_pow10.c \
> - s_rint.c s_logb.c s_log2.c s_lib_ver.c \
> + s_rint.c s_logb.c s_log2.c \
>   s_fdim.c s_fma.c s_fmax.c s_fmin.c s_fpclassify.c \
>   s_lrint.c s_llrint.c \
>   s_lround.c s_llround.c s_nearbyint.c s_remquo.c s_round.c s_scalbln.c \
> diff --git a/newlib/libm/common/Makefile.in b/newlib/libm/common/Makefile.in
> index 2caf7dd6c..b1098565f 100644
> --- a/newlib/libm/common/Makefile.in
> +++ b/newlib/libm/common/Makefile.in
> @@ -85,7 +85,6 @@ am__objects_1 = lib_a-s_finite.$(OBJEXT) lib_a-s_copysign.$(OBJEXT) \
>   lib_a-s_nan.$(OBJEXT) lib_a-s_nextafter.$(OBJEXT) \
>   lib_a-s_pow10.$(OBJEXT) lib_a-s_rint.$(OBJEXT) \
>   lib_a-s_logb.$(OBJEXT) lib_a-s_log2.$(OBJEXT) \
> - lib_a-s_lib_ver.$(OBJEXT) lib_a-s_fdim.$(OBJEXT) \

This accidentally removes lib_a-s_fdim.o, so building Cygwin fails.
Not much of a problem, though.  I pushed the series with regen'ed
newlib/libm/common/Makefile.in file.


Thanks,
Corinna

--
Corinna Vinschen
Cygwin Maintainer
Red Hat

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 5/5] libm: Control errno support with _IEEE_LIBM configuration parameter

Sourceware - newlib list mailing list
Corinna Vinschen via Newlib <[hidden email]> writes:

> This accidentally removes lib_a-s_fdim.o, so building Cygwin fails.
> Not much of a problem, though.  I pushed the series with regen'ed
> newlib/libm/common/Makefile.in file.

Thanks, I cannot generate the Makefile.in files so I edit them by hand.

--
-keith

signature.asc (847 bytes) Download Attachment