LEFT | RIGHT |
(no file at all) | |
| 1 /* Test case to check if Multiversioning works. */ |
| 2 /* { dg-do run { target i?86-*-* x86_64-*-* } } */ |
| 3 /* { dg-require-ifunc "" } */ |
| 4 /* { dg-options "-O2 -fPIC -mno-avx" } */ |
| 5 |
| 6 #include <assert.h> |
| 7 |
| 8 /* Default version. */ |
| 9 int foo (); |
| 10 /* The other versions of foo. Mix up the ordering and· |
| 11 check if the dispatching does it in the order of priority. */ |
| 12 /* Check combination of target attributes. */ |
| 13 int foo () __attribute__ ((target("arch=corei7,popcnt"))); |
| 14 /* The target operands in this declaration and the definition are re-ordered. |
| 15 This should still work. */ |
| 16 int foo () __attribute__ ((target("ssse3,avx2"))); |
| 17 |
| 18 /* Check for all target attributes for which dispatchers are available. */ |
| 19 /* Check arch= */ |
| 20 int foo () __attribute__((target("arch=core2"))); |
| 21 int foo () __attribute__((target("arch=corei7"))); |
| 22 int foo () __attribute__((target("arch=atom"))); |
| 23 /* Check ISAs */ |
| 24 int foo () __attribute__((target("avx"))); |
| 25 int foo () __attribute__ ((target("arch=core2,sse4.2"))); |
| 26 /* Check more arch=. */ |
| 27 int foo () __attribute__((target("arch=amdfam10"))); |
| 28 int foo () __attribute__((target("arch=bdver1"))); |
| 29 int foo () __attribute__((target("arch=bdver2"))); |
| 30 |
| 31 int (*p)() = &foo; |
| 32 int main () |
| 33 { |
| 34 int val = foo (); |
| 35 assert (val == (*p)()); |
| 36 |
| 37 /* Check in the exact same order in which the dispatching |
| 38 is expected to happen. */ |
| 39 if (__builtin_cpu_is ("bdver1")) |
| 40 assert (val == 1); |
| 41 else if (__builtin_cpu_is ("bdver2")) |
| 42 assert (val == 2); |
| 43 else if (__builtin_cpu_supports ("avx2") |
| 44 && __builtin_cpu_supports ("ssse3")) |
| 45 assert (val == 3); |
| 46 else if (__builtin_cpu_supports ("avx")) |
| 47 assert (val == 4); |
| 48 else if (__builtin_cpu_is ("corei7") |
| 49 && __builtin_cpu_supports ("popcnt")) |
| 50 assert (val == 5); |
| 51 else if (__builtin_cpu_is ("corei7")) |
| 52 assert (val == 6); |
| 53 else if (__builtin_cpu_is ("amdfam10h")) |
| 54 assert (val == 7); |
| 55 else if (__builtin_cpu_is ("core2") |
| 56 && __builtin_cpu_supports ("sse4.2")) |
| 57 assert (val == 8); |
| 58 else if (__builtin_cpu_is ("core2")) |
| 59 assert (val == 9); |
| 60 else if (__builtin_cpu_is ("atom")) |
| 61 assert (val == 10); |
| 62 else |
| 63 assert (val == 0); |
| 64 ·· |
| 65 return 0; |
| 66 } |
| 67 |
| 68 int foo () |
| 69 { |
| 70 return 0; |
| 71 } |
| 72 |
| 73 int __attribute__ ((target("arch=corei7,popcnt"))) |
| 74 foo () |
| 75 { |
| 76 return 5; |
| 77 } |
| 78 int __attribute__ ((target("avx2,ssse3"))) |
| 79 foo () |
| 80 { |
| 81 return 3; |
| 82 } |
| 83 |
| 84 int __attribute__ ((target("arch=core2"))) |
| 85 foo () |
| 86 { |
| 87 return 9; |
| 88 } |
| 89 |
| 90 int __attribute__ ((target("arch=corei7"))) |
| 91 foo () |
| 92 { |
| 93 return 6; |
| 94 } |
| 95 |
| 96 int __attribute__ ((target("arch=atom"))) |
| 97 foo () |
| 98 { |
| 99 return 10; |
| 100 } |
| 101 |
| 102 int __attribute__ ((target("avx"))) |
| 103 foo () |
| 104 { |
| 105 return 4; |
| 106 } |
| 107 |
| 108 int __attribute__ ((target("arch=core2,sse4.2"))) |
| 109 foo () |
| 110 { |
| 111 return 8; |
| 112 } |
| 113 |
| 114 int __attribute__ ((target("arch=amdfam10"))) |
| 115 foo () |
| 116 { |
| 117 return 7; |
| 118 } |
| 119 |
| 120 int __attribute__ ((target("arch=bdver1"))) |
| 121 foo () |
| 122 { |
| 123 return 1; |
| 124 } |
| 125 |
| 126 int __attribute__ ((target("arch=bdver2"))) |
| 127 foo () |
| 128 { |
| 129 return 2; |
| 130 } |
LEFT | RIGHT |