This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: User directed Function Multiversioning via Function Overloading (issue5752064)
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: Sriraman Tallam <tmsriram at google dot com>
- Cc: Richard Guenther <richard dot guenther at gmail dot com>, Jan Hubicka <jh at suse dot cz>, Uros Bizjak <ubizjak at gmail dot com>, reply at codereview dot appspotmail dot com, gcc-patches at gcc dot gnu dot org, David Li <davidxl at google dot com>
- Date: Tue, 1 May 2012 17:08:50 -0700
- Subject: Re: User directed Function Multiversioning via Function Overloading (issue5752064)
- References: <20120307004630.A503DB21B6@azwildcat.mtv.corp.google.com> <CAFiYyc3hy9wdB0d87D0TZX1Vj7P=oH0-ARf0rE3Z9wc+i8j8UA@mail.gmail.com> <CAAs8HmxsZPTH4VS78G9HZOGYXxEiVi90PgRrCc6gwp9de935WQ@mail.gmail.com> <CAAs8HmyeZE25B+vAp7aretL85WtPfyUuLAZNw7oFPFsUHZBtPA@mail.gmail.com> <CAMe9rOqUpYHNnHXMpVbN8nEPFcRV0Gr14j1YxA-Bx7Y0nMUu3w@mail.gmail.com> <CAAs8Hmx7OfYrNVFsVYi_BknexVFvP0hYroH7dnusu3Z86gs-CQ@mail.gmail.com> <CAMe9rOqaUNN67h64jJMugTsgrvpC7gsQx74UcKjBSGorxU0qOQ@mail.gmail.com> <CAAs8HmztTFyAO7ze2HKrfSNLOKc7rHomAuSLSKOSRQ-bkN_dgQ@mail.gmail.com> <CAMe9rOroWTs9KYo7ONfnc1aVK1pySzMfpEnF24C_ABF9TG5zhA@mail.gmail.com> <CAAs8Hmz64_myVEXaCrOQFBZgmW7wkBpuJnkkB_j=ebipuq92Tg@mail.gmail.com>
On Tue, May 1, 2012 at 4:51 PM, Sriraman Tallam <tmsriram@google.com> wrote:
> Hi,
>
> New patch attached, updated test case and fixed bugs related to
> __PRETTY_FUNCTION_.
>
> Patch also available for review here: ?http://codereview.appspot.com/5752064
@@ -0,0 +1,39 @@
+/* Simple test case to check if Multiversioning works. */
+/* { dg-do run } */
+/* { dg-options "-O2 -fPIC" } */
+
+#include <assert.h>
+
+int foo ();
+int foo () __attribute__ ((target("arch=corei7,sse4.2,popcnt")));
+/* The target operands in this declaration and the definition are re-ordered.
+ This should still work. */
+int foo () __attribute__ ((target("ssse3,avx2")));
+
+int (*p)() = &foo;
+int main ()
+{
+ return foo () + (*p)();
+}
+
+int foo ()
+{
+ return 0;
+}
+
+int __attribute__ ((target("arch=corei7,sse4.2,popcnt")))
+foo ()
+{
+ assert (__builtin_cpu_is ("corei7")
+ && __builtin_cpu_supports ("sse4.2")
+ && __builtin_cpu_supports ("popcnt"));
+ return 0;
+}
+
+int __attribute__ ((target("avx2,ssse3")))
+foo ()
+{
+ assert (__builtin_cpu_supports ("avx2")
+ && __builtin_cpu_supports ("ssse3"));
+ return 0;
+}
This test will pass if
int foo ()
{
return 0;
}
is selected on processors with AVX. The run-time test should
check that the right function is selected on the target processor,
not the selected function matches the target attribute. You can
do it by returning different values for each foo and call cpuid
to check if the right foo is selected.
You should add a testcase for __builtin_cpu_supports to check
all valid arguments.
--
H.J.