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]
Other format: [Raw text]

__builtin_generic


Hello all,

I have recently updated may OpenServer header files and
library functions, and it has exposed a problem (for me,
but bear with me, this can be very useful). The native
compiler supports a construct called "__builtin_generic"
that works like this.

It looks like a normal function call, whose prototype
would be somevalue __builtin_generic (..., const char *).
"somevalue" changes; read on. The last argument is 
format specifier that indicates argument types and
function names. When this is encountered, if any of
the arguments before the string are of one of the
types in the string, then the function rferenced is
called as a replacement to the __builtin_generic call.
I doubt I explained this propperly so consider this
example:

__builtin_generic (x, "ld:cosld;f:cosf;:cos");

If 'x' is of type long double ("ld"), then cosld()
will be called. If it is of type float ("f") then
cosf() will be called. Otherwise, for any other
type, simple cos() will be called. You can see the
value in this, especially for defining macros that
can take any argument type, and have them call the
correct function. In fact, that's exactly what
our math.h does, for many functions where there are
different library calls based on the argument type.

I started trying to implement this in 2.95.3 (yes
I know its old, its what I have to work with) and
I am afraid I simply don't have the compiler
internals smarts to do it. Specifically, how to
change the function call from __builtin_generic
to the one chosen. I am sure given enough time I
could figure it out but if anyone with any real
smarts finds this interesting and can see as much
use for it as I do (no that's not a self-serving
statement) then I'd love to work with you to
implement this. I can work in the 3.3 tree if I
must - I'll backport it to 2.95.3 myself.

Anyone care to lend a hand? Comments? Questions?

Kean.


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