Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 12 May 2017 14:56:54 -0700
From:      Steve Kargl <sgk@troutmask.apl.washington.edu>
To:        numerics@freebsd.org, freebsd-hackers@freebsd.org
Subject:   catrig[fl].c and inexact
Message-ID:  <20170512215654.GA82545@troutmask.apl.washington.edu>

next in thread | raw e-mail | index | archive | help
So, I've been making improvements to my implementations of
the half-cycle trig functions.  In doing so, I decide to 
add WARNS=2 to msun/Makefile.  clang 4.0.0 dies with an
error about an unused variable in raise_inexact() from 
catrig[fl].c.

/usr/home/kargl/trunk/math/libm/msun/src/catrigl.c:195:2: error: unused variable
      'junk' [-Werror,-Wunused-variable]
        raise_inexact();
        ^
/usr/home/kargl/trunk/math/libm/msun/src/catrigl.c:56:45: note: expanded from
      macro 'raise_inexact'
#define raise_inexact() do { volatile float junk = 1 + tiny; } while(0)
                                            ^
Grepping catrig.o for the variable 'junk' suggests that 'junk' is
optimized out (with at least -O2).

A quick and dirty patch to achieve the intent of the original
code follows.  It would be nice if some would like to commit
the patch.  Of course, you may want to wait for Bruce to 
review the diff.


Index: src/catrig.c
===================================================================
--- src/catrig.c	(revision 1935)
+++ src/catrig.c	(working copy)
@@ -37,7 +37,7 @@ __FBSDID("$FreeBSD: head/lib/msun/src/catrig.c 313863 
 #define isinf(x)	(fabs(x) == INFINITY)
 #undef isnan
 #define isnan(x)	((x) != (x))
-#define	raise_inexact()	do { volatile float junk = 1 + tiny; } while(0)
+#define	raise_inexact(x)	do { (x) = 1 + tiny; } while(0)
 #undef signbit
 #define signbit(x)	(__builtin_signbit(x))
 
@@ -315,7 +315,7 @@ casinh(double complex z)
 		return (z);
 
 	/* All remaining cases are inexact. */
-	raise_inexact();
+	raise_inexact(new_y);
 
 	if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
 		return (z);
@@ -400,7 +400,7 @@ cacos(double complex z)
 		return (CMPLX(0, -y));
 
 	/* All remaining cases are inexact. */
-	raise_inexact();
+	raise_inexact(new_x);
 
 	if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
 		return (CMPLX(pio2_hi - (x - pio2_lo), -y));
@@ -607,7 +607,7 @@ catanh(double complex z)
 		 * inexact, but this is the only only that needs to do it
 		 * explicitly.
 		 */
-		raise_inexact();
+		raise_inexact(ax);
 		return (z);
 	}
 
Index: src/catrigf.c
===================================================================
--- src/catrigf.c	(revision 1935)
+++ src/catrigf.c	(working copy)
@@ -51,7 +51,7 @@ __FBSDID("$FreeBSD: head/lib/msun/src/catrigf.c 275819
 #define isinf(x)	(fabsf(x) == INFINITY)
 #undef isnan
 #define isnan(x)	((x) != (x))
-#define	raise_inexact()	do { volatile float junk = 1 + tiny; } while(0)
+#define	raise_inexact(x)	do { (x) = 1 + tiny; } while(0)
 #undef signbit
 #define signbit(x)	(__builtin_signbitf(x))
 
@@ -176,7 +176,7 @@ casinhf(float complex z)
 	if (x == 0 && y == 0)
 		return (z);
 
-	raise_inexact();
+	raise_inexact(new_y);
 
 	if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
 		return (z);
@@ -234,7 +234,7 @@ cacosf(float complex z)
 	if (x == 1 && y == 0)
 		return (CMPLXF(0, -y));
 
-	raise_inexact();
+	raise_inexact(new_x);
 
 	if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
 		return (CMPLXF(pio2_hi - (x - pio2_lo), -y));
@@ -365,7 +365,7 @@ catanhf(float complex z)
 		    copysignf(pio2_hi + pio2_lo, y)));
 
 	if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) {
-		raise_inexact();
+		raise_inexact(ax);
 		return (z);
 	}
 
Index: src/catrigl.c
===================================================================
--- src/catrigl.c	(revision 1935)
+++ src/catrigl.c	(working copy)
@@ -53,7 +53,7 @@ __FBSDID("$FreeBSD: head/lib/msun/src/catrigl.c 313761
 #define isinf(x)	(fabsl(x) == INFINITY)
 #undef isnan
 #define isnan(x)	((x) != (x))
-#define	raise_inexact()	do { volatile float junk = 1 + tiny; } while(0)
+#define	raise_inexact(x)	do { (x) = 1 + tiny; } while(0)
 #undef signbit
 #define signbit(x)	(__builtin_signbitl(x))
 
@@ -192,7 +192,7 @@ casinhl(long double complex z)
 	if (x == 0 && y == 0)
 		return (z);
 
-	raise_inexact();
+	raise_inexact(new_y);
 
 	if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
 		return (z);
@@ -251,7 +251,7 @@ cacosl(long double complex z)
 	if (x == 1 && y == 0)
 		return (CMPLXL(0, -y));
 
-	raise_inexact();
+	raise_inexact(new_x);
 
 	if (ax < SQRT_6_EPSILON / 4 && ay < SQRT_6_EPSILON / 4)
 		return (CMPLXL(pio2_hi - (x - pio2_lo), -y));
@@ -383,7 +383,7 @@ catanhl(long double complex z)
 		    copysignl(pio2_hi + pio2_lo, y)));
 
 	if (ax < SQRT_3_EPSILON / 2 && ay < SQRT_3_EPSILON / 2) {
-		raise_inexact();
+		raise_inexact(ax);
 		return (z);
 	}
 

-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20170512215654.GA82545>