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
);
20 int sse4a_pop_i (int a
)
22 return __builtin_popcount (a
);
26 long sse42_pop_l (long a
)
28 return __builtin_popcountl (a
);
32 int generic_pop_i (int a
)
34 return __builtin_popcount (a
);
38 long generic_pop_l (long a
)
40 return __builtin_popcountl (a
);
48 if (sse4a_pop_i (five
) != 2)
51 if (sse42_pop_l (seven
) != 3L)
54 if (generic_pop_i (five
) != 2)
57 if (generic_pop_l (seven
) != 3L)
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" } } */