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