On Tue, May 1, 2012 at 7:45 PM, Sriraman Tallam <tmsri...@google.com> wrote: > Hi H.J, > > Done now. Patch attached. > > Thanks, > -Sri. > > On Tue, May 1, 2012 at 5:08 PM, H.J. Lu <hjl.to...@gmail.com> wrote: >> On Tue, May 1, 2012 at 4:51 PM, Sriraman Tallam <tmsri...@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.
2 questions: 1. Since AVX > SSE4 > SSSE3 > SSE3 > SSE2 > SSE, with foo for AVX and SSE3, on AVX processors, which foo will be selected? 2. I don't see any tests for __builtin_cpu_supports ("XXX") nor __builtin_cpu_is ("XXX"). I think you need tests for them. -- H.J.