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 7extern void exit (int); 8extern void abort (void); 9 10#define SSE4A_ATTR __attribute__((__target__("arch=amdfam10"))) 11#define SSE42_ATTR __attribute__((__target__("sse4.2"))) 12 13static int sse4a_pop_i (int a) SSE4A_ATTR; 14static long sse42_pop_l (long a) SSE42_ATTR; 15static int generic_pop_i (int a); 16static long generic_pop_l (long a); 17 18static 19int sse4a_pop_i (int a) 20{ 21 return __builtin_popcount (a); 22} 23 24static 25long sse42_pop_l (long a) 26{ 27 return __builtin_popcountl (a); 28} 29 30static 31int generic_pop_i (int a) 32{ 33 return __builtin_popcount (a); 34} 35 36static 37long generic_pop_l (long a) 38{ 39 return __builtin_popcountl (a); 40} 41 42int five = 5; 43long seven = 7; 44 45int 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" } } */ 68