blob: 7f63493eb7389a18516f8f126c3c55dc80f0bde6 [file] [log] [blame]
/* { dg-do run } */
/* { dg-require-effective-target ctz } */
/* { dg-options "-O2 -fno-tree-ch -fdump-tree-optimized" } */
#define PREC (__CHAR_BIT__ * __SIZEOF_INT__)
int
__attribute__ ((noinline, noclone))
foo (unsigned int b) {
int c = 0;
if (b == 0)
return PREC;
while (!(b & 1)) {
b >>= 1;
c++;
}
return c;
}
int main()
{
if (foo(0) != PREC)
__builtin_abort ();
if (foo(1 << (PREC - 1)) != PREC - 1)
__builtin_abort ();
if (foo(96) != 5)
__builtin_abort ();
if (foo(35) != 0)
__builtin_abort ();
return 0;
}
/* { dg-final { scan-tree-dump-times "__builtin_ctz|\\.CTZ" 1 "optimized" } } */