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