This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: new __builtin_choose_type (patch)


dewar@gnat.com writes:

> This seems a bit of a kludgy feature to me. Do we really need to add
> overloading to C for this purpose? If so, surely it should be done
> in a manner that is coherent with the rest of the language.

We don't absolutely have to add overloading to C to make <tgmath.h>
and the altivec stuff work---it appears to work now---but it's
terribly horribly ugly.  <tgmath.h> works like this:

# define __TGMATH_TERNARY_REAL_ONLY(Val1, Val2, Val3, Fct) \
     (__extension__ ({ __tgmath_real_type ((Val1) + (Val2) + (Val3)) __tgmres;\
		       if ((sizeof (Val1) > sizeof (double)		      \
			    || sizeof (Val2) > sizeof (double)		      \
			    || sizeof (Val3) > sizeof (double))		      \
			   && __builtin_classify_type ((Val1) + (Val2)	      \
						       + (Val3)) == 8)	      \
			 __tgmres = __tgml(Fct) (Val1, Val2, Val3);	      \
		       else if (sizeof (Val1) == sizeof (double)	      \
				|| sizeof (Val2) == sizeof (double)	      \
				|| sizeof (Val3) == sizeof (double)	      \
				|| __builtin_classify_type (Val1) != 8	      \
				|| __builtin_classify_type (Val2) != 8	      \
				|| __builtin_classify_type (Val3) != 8)	      \
			 __tgmres = Fct (Val1, Val2, Val3);		      \
		       else						      \
			 __tgmres = Fct##f (Val1, Val2, Val3);		      \
		       __tgmres; }))

and frankly, I think it'd be worth one more builtin to make this
code more obvious.

-- 
- Geoffrey Keating <geoffk@geoffk.org>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]