PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / funcspec-3.c
blob613a1a0fb9521274bd453f2a3c6d09cce0f1d531
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-skip-if "" { *-*-* } { "-march=*" } { "-march=k8" } } */
6 /* { dg-options "-O2 -march=k8 -mno-sse3" } */
8 extern void exit (int);
9 extern void abort (void);
11 #define SSE4A_ATTR __attribute__((__target__("arch=amdfam10")))
12 #define SSE42_ATTR __attribute__((__target__("sse4.2")))
14 static int sse4a_pop_i (int a) SSE4A_ATTR;
15 static long sse42_pop_l (long a) SSE42_ATTR;
16 static int generic_pop_i (int a);
17 static long generic_pop_l (long a);
19 static
20 int sse4a_pop_i (int a)
22 return __builtin_popcount (a);
25 static
26 long sse42_pop_l (long a)
28 return __builtin_popcountl (a);
31 static
32 int generic_pop_i (int a)
34 return __builtin_popcount (a);
37 static
38 long generic_pop_l (long a)
40 return __builtin_popcountl (a);
43 int five = 5;
44 long seven = 7;
46 int main ()
48 if (sse4a_pop_i (five) != 2)
49 abort ();
51 if (sse42_pop_l (seven) != 3L)
52 abort ();
54 if (generic_pop_i (five) != 2)
55 abort ();
57 if (generic_pop_l (seven) != 3L)
58 abort ();
60 exit (0);
63 /* { dg-final { scan-assembler "popcntl" { target { ! *-*-darwin* } } } } */
64 /* { dg-final { scan-assembler "popcntq" { target { ! *-*-darwin* } } } } */
65 /* { dg-final { scan-assembler-times "popcnt" 2 { target *-*-darwin* } } } */
66 /* { dg-final { scan-assembler "call\t(.*)sse4a_pop_i" } } */
67 /* { dg-final { scan-assembler "call\t(.*)sse42_pop_l" } } */
68 /* { dg-final { scan-assembler "call\t(.*)popcountdi2" } } */