OSDN Git Service

PR rtl-optimization/323
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / i386 / funcspec-3.c
1 /* Test whether using target specific options, we can generate popcnt by
2    setting the architecture.  */
3 /* { dg-do compile } */
4 /* { dg-require-effective-target lp64 } */
5 /* { dg-options "-O2 -march=k8" } */
6
7 extern void exit (int);
8 extern void abort (void);
9
10 #define SSE4A_ATTR __attribute__((__target__("arch=amdfam10")))
11 #define SSE42_ATTR __attribute__((__target__("sse4.2")))
12
13 static int sse4a_pop_i (int a) SSE4A_ATTR;
14 static long sse42_pop_l (long a) SSE42_ATTR;
15 static int generic_pop_i (int a);
16 static long generic_pop_l (long a);
17
18 static
19 int sse4a_pop_i (int a)
20 {
21   return __builtin_popcount (a);
22 }
23
24 static
25 long sse42_pop_l (long a)
26 {
27   return __builtin_popcountl (a);
28 }
29
30 static
31 int generic_pop_i (int a)
32 {
33   return __builtin_popcount (a);
34 }
35
36 static
37 long generic_pop_l (long a)
38 {
39   return __builtin_popcountl (a);
40 }
41
42 int five = 5;
43 long seven = 7;
44
45 int main ()
46 {
47   if (sse4a_pop_i (five) != 2)
48     abort ();
49
50   if (sse42_pop_l (seven) != 3L)
51     abort ();
52
53   if (generic_pop_i (five) != 2)
54     abort ();
55
56   if (generic_pop_l (seven) != 3L)
57     abort ();
58
59   exit (0);
60 }
61
62 /* { dg-final { scan-assembler "popcntl" { target { ! *-*-darwin* } } } } */
63 /* { dg-final { scan-assembler "popcntq" { target { ! *-*-darwin* } } } } */
64 /* { dg-final { scan-assembler-times "popcnt" 2 { target *-*-darwin* } } } */
65 /* { dg-final { scan-assembler "call\t(.*)sse4a_pop_i" } } */
66 /* { dg-final { scan-assembler "call\t(.*)sse42_pop_l" } } */
67 /* { dg-final { scan-assembler "call\t(.*)popcountdi2" } } */