1  /* { dg-do run } */
       2  /* { dg-options "-O3 -mdejagnu-cpu=power7" } */
       3  /* { dg-require-effective-target lp64 } */
       4  /* { dg-require-effective-target vsx_hw } */
       5  /* { dg-require-effective-target ppc_cpu_supports_hw } */
       6  
       7  #define NO_WARN_X86_INTRINSICS 1
       8  #include <x86intrin.h>
       9  #include "bmi2-check.h"
      10  
      11  __attribute__((noinline))
      12  unsigned
      13  calc_pext_u32 (unsigned a, unsigned mask)
      14  {
      15    unsigned res = 0;
      16    int i, k = 0;
      17  
      18    for (i = 0; i < 32; ++i)
      19      if (mask & (1 << i)) {
      20        res |= ((a & (1 << i)) >> i) << k;
      21        ++k;
      22      }
      23  
      24    return res;
      25  }
      26  
      27  static void
      28  bmi2_test ()
      29  {
      30    unsigned i;
      31    unsigned src = 0xce7acc;
      32    unsigned res, res_ref;
      33  
      34    for (i = 0; i < 5; ++i) {
      35      src = src * (i + 1);
      36  
      37      res_ref = calc_pext_u32 (src, ~(i * 3));
      38      res = _pext_u32 (src, ~(i * 3));
      39  
      40      if (res != res_ref)
      41        abort();
      42    }
      43  }