2016-12-21 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / bmi-bextr-2.c
blob2ce62596673334b901f4dd95140fc595043912b0
1 /* { dg-do run { target { bmi } } } */
2 /* { dg-require-effective-target bmi } */
3 /* { dg-options "-O2 -mbmi -fno-inline" } */
5 #include <x86intrin.h>
7 #include "bmi-check.h"
9 unsigned calc_bextr_u32 (unsigned src1, unsigned src2)
11 unsigned res = 0;
12 unsigned char start = (src2 & 0xff);
13 unsigned char len = (int) ((src2 >> 8) & 0xff);
14 if (start < 32) {
15 unsigned i;
16 unsigned last = (start+len) < 32 ? start+len : 32;
18 src1 >>= start;
19 for (i=start; i<last; ++i) {
20 res |= (src1 & 1) << (i-start);
21 src1 >>= 1;
25 return res;
28 static void
29 bmi_test ()
31 unsigned i;
32 unsigned char start, len;
33 unsigned src1 = 0xfacec0ff;
34 unsigned res, res_ref, src2;
36 for (i=0; i<5; ++i) {
37 start = (i * 1983) % 32;
38 len = i + (i * 1983) % 32;
40 src1 = src1 * 3;
41 src2 = start | (((unsigned)len) << 8);
43 res_ref = calc_bextr_u32 (src1, src2);
44 res = __bextr_u32 (src1, src2);
46 if (res != res_ref)
47 abort();