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__((__target__("arch=amdfam10")))
11 #define SSE42_ATTR __attribute__((__target__("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);
19 int sse4a_pop_i (int a)
21 return __builtin_popcount (a);
25 long sse42_pop_l (long a)
27 return __builtin_popcountl (a);
31 int generic_pop_i (int a)
33 return __builtin_popcount (a);
37 long generic_pop_l (long a)
39 return __builtin_popcountl (a);
47 if (sse4a_pop_i (five) != 2)
50 if (sse42_pop_l (seven) != 3L)
53 if (generic_pop_i (five) != 2)
56 if (generic_pop_l (seven) != 3L)
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" } } */