| 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 long long |
| 12 |
calc_mul_u32 (unsigned volatile a, unsigned b) |
| 13 |
{ |
| 14 |
unsigned long long res = 0; |
| 15 |
int i; |
| 16 |
for (i = 0; i < b; ++i) |
| 17 |
res += a; |
| 18 |
|
| 19 |
return res; |
| 20 |
} |
| 21 |
|
| 22 |
__attribute__((noinline)) |
| 23 |
unsigned calc_mulx_u32 (unsigned x, unsigned y, unsigned *res_h) |
| 24 |
{ |
| 25 |
return (unsigned) _mulx_u32 (x, y, res_h); |
| 26 |
} |
| 27 |
|
| 28 |
static void |
| 29 |
bmi2_test () |
| 30 |
{ |
| 31 |
unsigned i; |
| 32 |
unsigned a = 0xce7ace0; |
| 33 |
unsigned b = 0xfacefff; |
| 34 |
unsigned res_l, res_h; |
| 35 |
unsigned long long res, res_ref; |
| 36 |
|
| 37 |
for (i = 0; i < 5; ++i) { |
| 38 |
a = a * (i + 1); |
| 39 |
b = b / (i + 1); |
| 40 |
|
| 41 |
res_ref = calc_mul_u32 (a, b); |
| 42 |
res_l = calc_mulx_u32 (a, b, &res_h); |
| 43 |
|
| 44 |
res = ((unsigned long long) res_h << 32) | res_l; |
| 45 |
|
| 46 |
if (res != res_ref) |
| 47 |
abort(); |
| 48 |
} |
| 49 |
} |