10Sduke/* Test whether using target specific options, we can generate popcnt by 22362Sohair setting the architecture. */ 30Sduke/* { dg-do compile } */ 40Sduke/* { dg-require-effective-target lp64 } */ 50Sduke/* { dg-options "-O2 -march=k8" } */ 60Sduke 70Sdukeextern void exit (int); 80Sdukeextern void abort (void); 90Sduke 100Sduke#define SSE4A_ATTR __attribute__((__target__("arch=amdfam10"))) 110Sduke#define SSE42_ATTR __attribute__((__target__("sse4.2"))) 120Sduke 130Sdukestatic int sse4a_pop_i (int a) SSE4A_ATTR; 140Sdukestatic long sse42_pop_l (long a) SSE42_ATTR; 150Sdukestatic int generic_pop_i (int a); 160Sdukestatic long generic_pop_l (long a); 170Sduke 180Sdukestatic 192362Sohairint sse4a_pop_i (int a) 202362Sohair{ 212362Sohair return __builtin_popcount (a); 220Sduke} 230Sduke 240Sdukestatic 250Sdukelong sse42_pop_l (long a) 260Sduke{ 270Sduke return __builtin_popcountl (a); 280Sduke} 290Sduke 300Sdukestatic 310Sdukeint generic_pop_i (int a) 320Sduke{ 330Sduke return __builtin_popcount (a); 340Sduke} 350Sduke 360Sdukestatic 370Sdukelong generic_pop_l (long a) 380Sduke{ 390Sduke return __builtin_popcountl (a); 400Sduke} 410Sduke 420Sdukeint five = 5; 430Sdukelong seven = 7; 440Sduke 450Sdukeint main () 460Sduke{ 470Sduke if (sse4a_pop_i (five) != 2) 480Sduke abort (); 490Sduke 500Sduke if (sse42_pop_l (seven) != 3L) 510Sduke abort (); 520Sduke 530Sduke if (generic_pop_i (five) != 2) 540Sduke abort (); 550Sduke 560Sduke if (generic_pop_l (seven) != 3L) 570Sduke abort (); 580Sduke 590Sduke exit (0); 600Sduke} 610Sduke 620Sduke/* { dg-final { scan-assembler "popcntl" { target { ! *-*-darwin* } } } } */ 630Sduke/* { dg-final { scan-assembler "popcntq" { target { ! *-*-darwin* } } } } */ 640Sduke/* { dg-final { scan-assembler-times "popcnt" 2 { target *-*-darwin* } } } */ 650Sduke/* { dg-final { scan-assembler "call\t(.*)sse4a_pop_i" } } */ 660Sduke/* { dg-final { scan-assembler "call\t(.*)sse42_pop_l" } } */ 670Sduke/* { dg-final { scan-assembler "call\t(.*)popcountdi2" } } */ 680Sduke