1 /* Test case to check if Multiversioning chooses the correct 2 dispatching order when versions are for various ISAs. */ 3 /* { dg-do run } */ 4 /* { dg-require-ifunc "" } */ 5 /* { dg-options "-O2" } */ 6 7 #include <assert.h> 8 9 /* Default version. */ 10 int foo () __attribute__ ((target ("default"))); 11 /* The dispatch checks should be in the exact reverse order of the 12 declarations below. */ 13 int foo () __attribute__ ((target ("mmx"))); 14 int foo () __attribute__ ((target ("sse"))); 15 int foo () __attribute__ ((target ("sse2"))); 16 int foo () __attribute__ ((target ("sse3"))); 17 int foo () __attribute__ ((target ("ssse3"))); 18 int foo () __attribute__ ((target ("sse4.1"))); 19 int foo () __attribute__ ((target ("sse4.2"))); 20 int foo () __attribute__ ((target ("popcnt"))); 21 int foo () __attribute__ ((target ("avx"))); 22 int foo () __attribute__ ((target ("avx2"))); 23 int foo () __attribute__ ((target ("avx512f"))); 24 main()25int main () 26 { 27 int val = foo (); 28 29 if (__builtin_cpu_supports ("avx512f")) 30 assert (val == 11); 31 else if (__builtin_cpu_supports ("avx2")) 32 assert (val == 10); 33 else if (__builtin_cpu_supports ("avx")) 34 assert (val == 9); 35 else if (__builtin_cpu_supports ("popcnt")) 36 assert (val == 8); 37 else if (__builtin_cpu_supports ("sse4.2")) 38 assert (val == 7); 39 else if (__builtin_cpu_supports ("sse4.1")) 40 assert (val == 6); 41 else if (__builtin_cpu_supports ("ssse3")) 42 assert (val == 5); 43 else if (__builtin_cpu_supports ("sse3")) 44 assert (val == 4); 45 else if (__builtin_cpu_supports ("sse2")) 46 assert (val == 3); 47 else if (__builtin_cpu_supports ("sse")) 48 assert (val == 2); 49 else if (__builtin_cpu_supports ("mmx")) 50 assert (val == 1); 51 else 52 assert (val == 0); 53 54 return 0; 55 } 56 57 int __attribute__ ((target("default"))) foo()58foo () 59 { 60 return 0; 61 } 62 63 int __attribute__ ((target("mmx"))) foo()64foo () 65 { 66 return 1; 67 } 68 69 int __attribute__ ((target("sse"))) foo()70foo () 71 { 72 return 2; 73 } 74 75 int __attribute__ ((target("sse2"))) foo()76foo () 77 { 78 return 3; 79 } 80 81 int __attribute__ ((target("sse3"))) foo()82foo () 83 { 84 return 4; 85 } 86 87 int __attribute__ ((target("ssse3"))) foo()88foo () 89 { 90 return 5; 91 } 92 93 int __attribute__ ((target("sse4.1"))) foo()94foo () 95 { 96 return 6; 97 } 98 99 int __attribute__ ((target("sse4.2"))) foo()100foo () 101 { 102 return 7; 103 } 104 105 int __attribute__ ((target("popcnt"))) foo()106foo () 107 { 108 return 8; 109 } 110 111 int __attribute__ ((target("avx"))) foo()112foo () 113 { 114 return 9; 115 } 116 117 int __attribute__ ((target("avx2"))) foo()118foo () 119 { 120 return 10; 121 } 122 123 int __attribute__ ((target("avx512f"))) foo()124foo () 125 { 126 return 11; 127 } 128