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