(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
i386/
funcspec-3.c
       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" } */
       7  
       8  extern void exit (int);
       9  extern void abort (void);
      10  
      11  #define SSE4A_ATTR __attribute__((__target__("arch=amdfam10")))
      12  #define SSE42_ATTR __attribute__((__target__("sse4.2")))
      13  
      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);
      18  
      19  static
      20  int sse4a_pop_i (int a)
      21  {
      22    return __builtin_popcount (a);
      23  }
      24  
      25  static
      26  long sse42_pop_l (long a)
      27  {
      28    return __builtin_popcountl (a);
      29  }
      30  
      31  static
      32  int generic_pop_i (int a)
      33  {
      34    return __builtin_popcount (a);
      35  }
      36  
      37  static
      38  long generic_pop_l (long a)
      39  {
      40    return __builtin_popcountl (a);
      41  }
      42  
      43  int five = 5;
      44  long seven = 7;
      45  
      46  int main ()
      47  {
      48    if (sse4a_pop_i (five) != 2)
      49      abort ();
      50  
      51    if (sse42_pop_l (seven) != 3L)
      52      abort ();
      53  
      54    if (generic_pop_i (five) != 2)
      55      abort ();
      56  
      57    if (generic_pop_l (seven) != 3L)
      58      abort ();
      59  
      60    exit (0);
      61  }
      62  
      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(\[^\n\r\]*)sse4a_pop_i" } } */
      67  /* { dg-final { scan-assembler "call\t(\[^\n\r\]*)sse42_pop_l" } } */
      68  /* { dg-final { scan-assembler "call\t(\[^\n\r\]*)popcountdi2" } } */