* __attribute__ ifunc examples?
@ 2012-03-14 14:23 James Cloos
2012-03-15 2:45 ` Ian Lance Taylor
0 siblings, 1 reply; 3+ messages in thread
From: James Cloos @ 2012-03-14 14:23 UTC (permalink / raw)
To: gcc-help
Does anyone have a worked example in C of using attribute ifunc to
dispatch over the various x86 SSE/AVX flags, as well as arm neon?
Must one call cpuid manually, or are flags already available to check?
I haven't found any via goog (and the C++ example I found was
incompatible with the gcc-4.6 syntax for ifunc), and glibc's
support for it is too opaque for grep.
Thanks,
-JimC
--
James Cloos <cloos@jhcloos.com> OpenPGP: 1024D/ED7DAEA6
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: __attribute__ ifunc examples?
2012-03-14 14:23 __attribute__ ifunc examples? James Cloos
@ 2012-03-15 2:45 ` Ian Lance Taylor
2012-03-22 20:53 ` James Cloos
0 siblings, 1 reply; 3+ messages in thread
From: Ian Lance Taylor @ 2012-03-15 2:45 UTC (permalink / raw)
To: James Cloos; +Cc: gcc-help
James Cloos <cloos@jhcloos.com> writes:
> Does anyone have a worked example in C of using attribute ifunc to
> dispatch over the various x86 SSE/AVX flags, as well as arm neon?
Not using SSE/AVX flags, but the basic idea is not too hard. Here is an
example that sets the implementation of foo based on a global variable.
#include <stdio.h>
int foo (void) __attribute__ ((ifunc ("foo_ifunc")));
static int global = 1;
static int
f1 (void)
{
return 0;
}
static int
f2 (void)
{
return 1;
}
void *
foo_ifunc (void)
{
return global == 1 ? f1 : f2;
}
int
main ()
{
printf ("%d\n", foo());
}
For your case you need to write foo_ifunc using appropriate asm
instructions to check cpuid or whatever. Note that foo_ifunc runs as
the program is just starting, so it can't call library routines or check
command line arguments or anything like that. Checking cpuid is fine.
> Must one call cpuid manually, or are flags already available to check?
At present you have to call it manually. There is an outstanding patch
to add __builtin_cpuid on x86 systems, but I don't think it has been
approved.
Ian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: __attribute__ ifunc examples?
2012-03-15 2:45 ` Ian Lance Taylor
@ 2012-03-22 20:53 ` James Cloos
0 siblings, 0 replies; 3+ messages in thread
From: James Cloos @ 2012-03-22 20:53 UTC (permalink / raw)
To: Ian Lance Taylor; +Cc: gcc-help
>>>>> "ILT" == Ian Lance Taylor <iant@google.com> writes:
JC>> Does anyone have a worked example in C of using attribute ifunc to
JC>> dispatch over the various x86 SSE/AVX flags, as well as arm neon?
ILT> For your case you need to write foo_ifunc using appropriate asm
ILT> instructions to check cpuid or whatever.
Thanks, but that much I already got out of the docs. I was hoping for
an example of actual checks for the various cpu features for x86 & arm
in the ifunc context.
The existing cpu feature detectors out in the wild, plus the i+a+v docs,
should provide enough extra clue, of course. Just a matter of coding,
after all.
ILT> At present you have to call it manually. There is an outstanding patch
ILT> to add __builtin_cpuid on x86 systems, but I don't think it has been
ILT> approved.
That would be a useful addition.
Thank you.
-JimC
--
James Cloos <cloos@jhcloos.com> OpenPGP: 1024D/ED7DAEA6
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-03-22 20:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-14 14:23 __attribute__ ifunc examples? James Cloos
2012-03-15 2:45 ` Ian Lance Taylor
2012-03-22 20:53 ` James Cloos
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).