| 1 |
/* { dg-do run { target bmi } } */ |
| 2 |
/* { dg-options "-O2 -mbmi -fno-inline" } */ |
| 3 |
|
| 4 |
#include <x86intrin.h> |
| 5 |
|
| 6 |
#include "bmi-check.h" |
| 7 |
|
| 8 |
unsigned calc_bextr_u32 (unsigned src1, unsigned src2) |
| 9 |
{ |
| 10 |
unsigned res = 0; |
| 11 |
unsigned char start = (src2 & 0xff); |
| 12 |
unsigned char len = (int) ((src2 >> 8) & 0xff); |
| 13 |
if (start < 32) { |
| 14 |
unsigned i; |
| 15 |
unsigned last = (start+len) < 32 ? start+len : 32; |
| 16 |
|
| 17 |
src1 >>= start; |
| 18 |
for (i=start; i<last; ++i) { |
| 19 |
res |= (src1 & 1) << (i-start); |
| 20 |
src1 >>= 1; |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
return res; |
| 25 |
} |
| 26 |
|
| 27 |
static void |
| 28 |
bmi_test () |
| 29 |
{ |
| 30 |
unsigned i; |
| 31 |
unsigned char start, len; |
| 32 |
unsigned src1 = 0xfacec0ff; |
| 33 |
unsigned res, res_ref, src2; |
| 34 |
|
| 35 |
for (i=0; i<5; ++i) { |
| 36 |
start = (i * 1983) % 32; |
| 37 |
len = i + (i * 1983) % 32; |
| 38 |
|
| 39 |
src1 = src1 * 3; |
| 40 |
src2 = start | (((unsigned)len) << 8); |
| 41 |
|
| 42 |
res_ref = calc_bextr_u32 (src1, src2); |
| 43 |
res = __bextr_u32 (src1, src2); |
| 44 |
|
| 45 |
if (res != res_ref) |
| 46 |
abort(); |
| 47 |
} |
| 48 |
} |