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>.
This commit is contained in:
Ed Schouten 2012-01-06 19:04:59 +00:00
parent ca3759b5de
commit 305bf119f8
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=229716

View File

@ -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 */