aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/ext/mv2.C
blob: 869e99b4faea8ee28a7c4af3a062b3584a7b3b19 (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
/* Test case to check if Multiversioning chooses the correct
   dispatching order when versions are for various ISAs.  */
/* { dg-do run { target i?86-*-* x86_64-*-* } } */
/* { dg-require-ifunc "" }  */
/* { dg-options "-O2" } */

#include <assert.h>

/* Default version.  */
int foo () __attribute__ ((target ("default")));
/* The dispatch checks should be in the exact reverse order of the
   declarations below.  */
int foo () __attribute__ ((target ("mmx")));
int foo () __attribute__ ((target ("sse")));
int foo () __attribute__ ((target ("sse2")));
int foo () __attribute__ ((target ("sse3")));
int foo () __attribute__ ((target ("ssse3")));
int foo () __attribute__ ((target ("sse4.1")));
int foo () __attribute__ ((target ("sse4.2")));
int foo () __attribute__ ((target ("popcnt")));
int foo () __attribute__ ((target ("avx")));
int foo () __attribute__ ((target ("avx2")));

int main ()
{
  int val = foo ();

  if (__builtin_cpu_supports ("avx2"))
    assert (val == 1);
  else if (__builtin_cpu_supports ("avx"))
    assert (val == 2);
  else if (__builtin_cpu_supports ("popcnt"))
    assert (val == 3);
  else if (__builtin_cpu_supports ("sse4.2"))
    assert (val == 4);
  else if (__builtin_cpu_supports ("sse4.1"))
    assert (val == 5);
  else if (__builtin_cpu_supports ("ssse3"))
    assert (val == 6);
  else if (__builtin_cpu_supports ("sse3"))
    assert (val == 7);
  else if (__builtin_cpu_supports ("sse2"))
    assert (val == 8);
  else if (__builtin_cpu_supports ("sse"))
    assert (val == 9);
  else if (__builtin_cpu_supports ("mmx"))
    assert (val == 10);
  else
    assert (val == 0);

  return 0;
}

int __attribute__ ((target("default")))
foo ()
{
  return 0;
}

int __attribute__ ((target("mmx")))
foo ()
{
  return 10;
}

int __attribute__ ((target("sse")))
foo ()
{
  return 9;
}

int __attribute__ ((target("sse2")))
foo ()
{
  return 8;
}

int __attribute__ ((target("sse3")))
foo ()
{
  return 7;
}

int __attribute__ ((target("ssse3")))
foo ()
{
  return 6;
}

int __attribute__ ((target("sse4.1")))
foo ()
{
  return 5;
}

int __attribute__ ((target("sse4.2")))
foo ()
{
  return 4;
}

int __attribute__ ((target("popcnt")))
foo ()
{
  return 3;
}

int __attribute__ ((target("avx")))
foo ()
{
  return 2;
}

int __attribute__ ((target("avx2")))
foo ()
{
  return 1;
}