1 /* { dg-do run { target bmi2 } } */
2 /* { dg-options "-mbmi2 -O2" } */
3 
4 #include <x86intrin.h>
5 #include "bmi2-check.h"
6 
7 __attribute__((noinline))
8 unsigned
calc_bzhi_u32(unsigned a,int l)9 calc_bzhi_u32 (unsigned a, int l)
10 {
11   unsigned res = a;
12   int i;
13   for (i = 0; i < 32 - l; ++i)
14     res &= ~(1 << (31 - i));
15 
16   return res;
17 }
18 
19 static void
bmi2_test()20 bmi2_test ()
21 {
22   unsigned i;
23   unsigned src = 0xce7ace0f;
24   unsigned res, res_ref;
25 
26   for (i = 0; i < 5; ++i) {
27     src = src * (i + 1);
28 
29     res_ref = calc_bzhi_u32 (src, i * 2);
30     res = _bzhi_u32 (src, i * 2);
31 
32     if (res != res_ref)
33       abort();
34   }
35 }
36