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