Merge from trunk @ 138209
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / funcspec-3.c
blob80ec23da09f0a9993b9abf8093c1c89678d19a85
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" } */
7 extern void exit (int);
8 extern void abort (void);
10 #define SSE4A_ATTR __attribute__((__option__("arch=amdfam10")))
11 #define SSE42_ATTR __attribute__((__option__("sse4.2")))
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);
18 static
19 int sse4a_pop_i (int a)
21 return __builtin_popcount (a);
24 static
25 long sse42_pop_l (long a)
27 return __builtin_popcountl (a);
30 static
31 int generic_pop_i (int a)
33 return __builtin_popcount (a);
36 static
37 long generic_pop_l (long a)
39 return __builtin_popcountl (a);
42 int five = 5;
43 long seven = 7;
45 int main ()
47 if (sse4a_pop_i (five) != 2)
48 abort ();
50 if (sse42_pop_l (seven) != 3L)
51 abort ();
53 if (generic_pop_i (five) != 2)
54 abort ();
56 if (generic_pop_l (seven) != 3L)
57 abort ();
59 exit (0);
62 /* { dg-final { scan-assembler "popcntl" } } */
63 /* { dg-final { scan-assembler "popcntq" } } */
64 /* { dg-final { scan-assembler "call\t(.*)sse4a_pop_i" } } */
65 /* { dg-final { scan-assembler "call\t(.*)sse42_pop_l" } } */
66 /* { dg-final { scan-assembler "call\t(.*)popcountdi2" } } */