LEFT | RIGHT |
(no file at all) | |
| 1 /* Test case to check if Multiversioning chooses the correct |
| 2 dispatching order when versions are for various ISAs. */ |
| 3 /* { dg-do run { target i?86-*-* x86_64-*-* } } */ |
| 4 /* { dg-require-ifunc "" } */ |
| 5 /* { dg-options "-O2 -mno-sse -mno-mmx -mno-popcnt -mno-avx" } */ |
| 6 |
| 7 #include <assert.h> |
| 8 |
| 9 /* Default version. */ |
| 10 int foo (); |
| 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 |
| 24 int main () |
| 25 { |
| 26 |
| 27 int val = foo (); |
| 28 |
| 29 if (__builtin_cpu_supports ("avx2")) |
| 30 assert (val == 1); |
| 31 else if (__builtin_cpu_supports ("avx")) |
| 32 assert (val == 2); |
| 33 else if (__builtin_cpu_supports ("popcnt")) |
| 34 assert (val == 3); |
| 35 else if (__builtin_cpu_supports ("sse4.2")) |
| 36 assert (val == 4); |
| 37 else if (__builtin_cpu_supports ("sse4.1")) |
| 38 assert (val == 5); |
| 39 else if (__builtin_cpu_supports ("ssse3")) |
| 40 assert (val == 6); |
| 41 else if (__builtin_cpu_supports ("sse3")) |
| 42 assert (val == 7); |
| 43 else if (__builtin_cpu_supports ("sse2")) |
| 44 assert (val == 8); |
| 45 else if (__builtin_cpu_supports ("sse")) |
| 46 assert (val == 9); |
| 47 else if (__builtin_cpu_supports ("mmx")) |
| 48 assert (val == 10); |
| 49 else |
| 50 assert (val == 0); |
| 51 |
| 52 return 0; |
| 53 } |
| 54 |
| 55 int |
| 56 foo () |
| 57 { |
| 58 return 0; |
| 59 } |
| 60 |
| 61 int __attribute__ ((target("mmx"))) |
| 62 foo () |
| 63 { |
| 64 return 10; |
| 65 } |
| 66 |
| 67 int __attribute__ ((target("sse"))) |
| 68 foo () |
| 69 { |
| 70 return 9; |
| 71 } |
| 72 |
| 73 int __attribute__ ((target("sse2"))) |
| 74 foo () |
| 75 { |
| 76 return 8; |
| 77 } |
| 78 |
| 79 int __attribute__ ((target("sse3"))) |
| 80 foo () |
| 81 { |
| 82 return 7; |
| 83 } |
| 84 |
| 85 int __attribute__ ((target("ssse3"))) |
| 86 foo () |
| 87 { |
| 88 return 6; |
| 89 } |
| 90 |
| 91 int __attribute__ ((target("sse4.1"))) |
| 92 foo () |
| 93 { |
| 94 return 5; |
| 95 } |
| 96 |
| 97 int __attribute__ ((target("sse4.2"))) |
| 98 foo () |
| 99 { |
| 100 return 4; |
| 101 } |
| 102 |
| 103 int __attribute__ ((target("popcnt"))) |
| 104 foo () |
| 105 { |
| 106 return 3; |
| 107 } |
| 108 |
| 109 int __attribute__ ((target("avx"))) |
| 110 foo () |
| 111 { |
| 112 return 2; |
| 113 } |
| 114 |
| 115 int __attribute__ ((target("avx2"))) |
| 116 foo () |
| 117 { |
| 118 return 1; |
| 119 } |
LEFT | RIGHT |