131
|
1 // Test case to check if Multiversioning works for BMI and BMI2.
|
|
2
|
|
3 // { dg-do run }
|
|
4 // { dg-require-ifunc "" }
|
|
5 // { dg-options "-O2" }
|
|
6
|
|
7 #include <assert.h>
|
|
8
|
|
9 // Check BMI feature selection works
|
|
10 int foo () __attribute__((target("default")));
|
|
11 int foo () __attribute__((target("bmi")));
|
|
12 int foo () __attribute__((target("bmi2")));
|
|
13
|
|
14 // Check specialized versions for archs with BMI is chosen over generic BMI versions.
|
|
15 int bar () __attribute__((target("default")));
|
|
16 int bar () __attribute__((target("bmi")));
|
|
17 int bar () __attribute__((target("bmi2")));
|
|
18 int bar () __attribute__((target("arch=btver2")));
|
|
19 int bar () __attribute__((target("arch=haswell")));
|
|
20
|
|
21 int main ()
|
|
22 {
|
|
23 int val = foo ();
|
|
24
|
|
25 if (__builtin_cpu_supports ("bmi2"))
|
|
26 assert (val == 2);
|
|
27 else if (__builtin_cpu_supports ("bmi"))
|
|
28 assert (val == 1);
|
|
29 else
|
|
30 assert (val == 0);
|
|
31
|
|
32 val = bar ();
|
|
33
|
|
34 if (__builtin_cpu_is ("btver2"))
|
|
35 assert (val == 5);
|
|
36 else if (__builtin_cpu_is ("haswell"))
|
|
37 assert (val == 6);
|
|
38 else if (__builtin_cpu_supports ("bmi2"))
|
|
39 assert (val == 2);
|
|
40 else if (__builtin_cpu_supports ("bmi"))
|
|
41 assert (val == 1);
|
|
42 else
|
|
43 assert (val == 0);
|
|
44
|
|
45 return 0;
|
|
46 }
|
|
47
|
|
48 int __attribute__ ((target("default")))
|
|
49 foo ()
|
|
50 {
|
|
51 return 0;
|
|
52 }
|
|
53
|
|
54 int __attribute__ ((target("bmi")))
|
|
55 foo ()
|
|
56 {
|
|
57 return 1;
|
|
58 }
|
|
59 int __attribute__ ((target("bmi2")))
|
|
60 foo ()
|
|
61 {
|
|
62 return 2;
|
|
63 }
|
|
64
|
|
65 int __attribute__ ((target("default")))
|
|
66 bar ()
|
|
67 {
|
|
68 return 0;
|
|
69 }
|
|
70
|
|
71 int __attribute__ ((target("bmi")))
|
|
72 bar ()
|
|
73 {
|
|
74 return 1;
|
|
75 }
|
|
76 int __attribute__ ((target("bmi2")))
|
|
77 bar ()
|
|
78 {
|
|
79 return 2;
|
|
80 }
|
|
81
|
|
82 int __attribute__ ((target("arch=btver2")))
|
|
83 bar ()
|
|
84 {
|
|
85 return 5;
|
|
86 }
|
|
87
|
|
88 int __attribute__ ((target("arch=haswell")))
|
|
89 bar ()
|
|
90 {
|
|
91 return 6;
|
|
92 }
|
|
93
|