OSDN Git Service

2011-08-19 Andrew Stubbs <ams@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.target / i386 / bmi-tzcnt-1.c
1 /* { dg-do run { target { bmi && { ! ia32 } } } } */
2 /* { dg-options "-O2 -mbmi -fno-inline" } */
3
4 #include <x86intrin.h>
5
6 #include "bmi-check.h"
7
8 long long calc_tzcnt_u64 (long long src)
9 {
10   int i;
11   int res = 0;
12
13   while ( (res<64) && ((src&1) == 0)) {
14     ++res;
15     src >>= 1;
16   }
17
18   return res;
19 }
20
21 static void
22 bmi_test ()
23 {
24   unsigned i;
25   long long src = 0xfacec0ffeefacec0;
26   long long res, res_ref;
27
28   for (i=0; i<5; ++i) {
29     src = i + src << i;
30
31     res_ref = calc_tzcnt_u64 (src);
32     res = __tzcnt_u64 (src);
33
34     if (res != res_ref)
35       abort();
36   }
37 }