summaryrefslogtreecommitdiffstats
path: root/include/tgmath.h
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2012-01-06 19:04:59 +0000
committered <ed@FreeBSD.org>2012-01-06 19:04:59 +0000
commit888b946dd29027ca585859a2961df50f0259e0a0 (patch)
tree3198598ec6529267d8e4b1a467d8eedcf5019fed /include/tgmath.h
parent59483a638a02eff9fb03fa1887084910f65a95ee (diff)
downloadFreeBSD-src-888b946dd29027ca585859a2961df50f0259e0a0.zip
FreeBSD-src-888b946dd29027ca585859a2961df50f0259e0a0.tar.gz
Last attempt at <tgmath.h>: do enable the new code for C11 compilers.
I was thinking by myself, if the new code doesn't work with GCC 4.2, why not simply turn it into an efficient version for C11 compilers? By changing the code to use _Generic() directly in that case, I can build the tgmath regression test in a matter of milliseconds with Clang, instead of the 8 seconds it used to take. So by the time C11 becomes the default, it will pick up the new code automatically. And now I will refrain from making more changes to <tgmath.h>.
Diffstat (limited to 'include/tgmath.h')
-rw-r--r--include/tgmath.h28
1 files changed, 17 insertions, 11 deletions
diff --git a/include/tgmath.h b/include/tgmath.h
index 9de0afe..9302302 100644
--- a/include/tgmath.h
+++ b/include/tgmath.h
@@ -53,19 +53,23 @@
* Note that these macros cannot be implemented with C's ?: operator,
* because the return type of the whole expression would incorrectly be long
* double complex regardless of the argument types.
+ *
+ * The structure of the C11 implementation of these macros can in
+ * principle be reused for non-C11 compilers, but due to an integer
+ * promotion bug for complex types in GCC 4.2, simply let non-C11
+ * compilers use an inefficient yet reliable version.
*/
-#ifndef __generic
-#error "<tgmath.h> not implemented for this compiler"
-#endif
-
-#if 0 /* XXX: Much shorter and faster to compile, but broken with GCC 4.2. */
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
#define __tg_generic(x, cfnl, cfn, cfnf, fnl, fn, fnf) \
- __generic(x, long double _Complex, cfnl, \
- __generic(x, double _Complex, cfn, \
- __generic(x, float _Complex, cfnf, \
- __generic(x, long double, fnl, \
- __generic(x, float, fnf, fn)))))
+ _Generic(x, \
+ long double _Complex: cfnl, \
+ double _Complex: cfn, \
+ float _Complex: cfnf, \
+ long double: fnl, \
+ default: fn, \
+ float: fnf \
+ )
#define __tg_type(x) \
__tg_generic(x, (long double _Complex)0, (double _Complex)0, \
(float _Complex)0, (long double)0, (double)0, (float)0)
@@ -77,7 +81,7 @@
__tg_generic( \
__tg_type(x) + __tg_type(y), \
cfnl, cfn, cfnf, fnl, fn, fnf)(__VA_ARGS__)
-#else
+#elif defined(__generic)
#define __tg_generic_simple(x, fnl, fn, fnf) \
__generic(x, long double _Complex, fnl, \
__generic(x, double _Complex, fn, \
@@ -113,6 +117,8 @@
__tg_generic_full(y, cfnl, cfn , cfn , fnl , fn , fn ), \
__tg_generic_full(y, cfnl, cfn , cfnf, fnl , fn , fnf )) \
(__VA_ARGS__)
+#else
+#error "<tgmath.h> not implemented for this compiler"
#endif
/* Macros to save lots of repetition below */
OpenPOWER on IntegriCloud