summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>2008-01-17 17:02:11 +0000
committerbde <bde@FreeBSD.org>2008-01-17 17:02:11 +0000
commitb9ae01c4c72a469ad5314b6d8d4f74cb6bd3b495 (patch)
tree6939f68a48175850c16475fe246cf14db56b721d /lib
parentc553ad248f2b357789e1fdfb79d3efea1497c193 (diff)
downloadFreeBSD-src-b9ae01c4c72a469ad5314b6d8d4f74cb6bd3b495.zip
FreeBSD-src-b9ae01c4c72a469ad5314b6d8d4f74cb6bd3b495.tar.gz
Add a macro STRICT_ASSIGN() to help avoid the compiler bug that
assignments and casts don't clip extra precision, if any. The implementation is to assign to a temporary volatile variable and read the result back to assign to the original lvalue. lib/msun currently 2 different hard-coded hacks to avoid the problem in just a few places and needs it in a few more places. One variant uses volatile for the original lvalue. This works but is slower than necessary. Another temporarily casts the lvalue to volatile. This broke with gcc-4.2.1 or earlier (gcc now stores to the lvalue but doesn't load from it).
Diffstat (limited to 'lib')
-rw-r--r--lib/msun/src/math_private.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/msun/src/math_private.h b/lib/msun/src/math_private.h
index 2db3c02..15ef4fb 100644
--- a/lib/msun/src/math_private.h
+++ b/lib/msun/src/math_private.h
@@ -154,6 +154,22 @@ do { \
(d) = sf_u.value; \
} while (0)
+#ifdef FLT_EVAL_METHOD
+/*
+ * Attempt to get strict C99 semantics for assignment with non-C99 compilers.
+ */
+#if FLT_EVAL_METHOD == 0 || __GNUC__ == 0
+#define STRICT_ASSIGN(type, lval, rval) ((lval) = (rval))
+#else
+#define STRICT_ASSIGN(type, lval, rval) do { \
+ volatile type __lval; \
+ \
+ __lval = (rval); \
+ (lval) = __lval; \
+} while (0)
+#endif
+#endif
+
/*
* Common routine to process the arguments to nan(), nanf(), and nanl().
*/
OpenPOWER on IntegriCloud