summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.target/i386/bmi-bextr-4.c
blob: 2318847ae339de4013e6d82e4c6f8e97e183e818 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* { dg-do run { target { bmi } } } */
/* { dg-require-effective-target bmi  } */
/* { dg-options "-O2 -mbmi -fno-inline" } */

#include <x86intrin.h>

#include "bmi-check.h"

unsigned calc_bextr_u32 (unsigned src1, unsigned src2)
{
  unsigned res = 0;
  unsigned char start = (src2 & 0xff);
  unsigned char len = (int) ((src2 >> 8) & 0xff);
  if (start < 32) {
    unsigned i;
    unsigned last = (start+len) < 32 ? start+len : 32;

    src1 >>= start;
    for (i=start; i<last; ++i) {
      res |= (src1 & 1) << (i-start);
      src1 >>= 1;
    }
  }

  return res;
}

static void
bmi_test ()
{
  unsigned i;
  unsigned char start, len;
  unsigned src1 = 0xfacec0ff;
  unsigned res, res_ref, src2;

  for (i=0; i<5; ++i) {
    start = i * 4;
    len = i * 4;

    src1 = src1 * 3;
    src2 = (start & 0xff) | ((len & 0xff) << 8);

    res_ref = calc_bextr_u32 (src1, src2);
    res = _bextr_u32 (src1, start, len);

    if (res != res_ref)
      abort();
  }
}