Blame isl-0.16.1/isl_ffs.c

Packit fb9d21
#include <isl_config.h>
Packit fb9d21
Packit fb9d21
#if !HAVE_DECL_FFS && !HAVE_DECL___BUILTIN_FFS && HAVE_DECL__BITSCANFORWARD
Packit fb9d21
#include <intrin.h>
Packit fb9d21
Packit fb9d21
/* Implementation of ffs in terms of _BitScanForward.
Packit fb9d21
 *
Packit fb9d21
 * ffs returns the position of the least significant bit set in i,
Packit fb9d21
 * with the least significant bit is position 1, or 0 if not bits are set.
Packit fb9d21
 *
Packit fb9d21
 * _BitScanForward returns 1 if mask is non-zero and sets index
Packit fb9d21
 * to the position of the least significant bit set in i,
Packit fb9d21
 * with the least significant bit is position 0.
Packit fb9d21
 */
Packit fb9d21
int isl_ffs(int i)
Packit fb9d21
{
Packit fb9d21
	unsigned char non_zero;
Packit fb9d21
	unsigned long index, mask = i;
Packit fb9d21
Packit fb9d21
	non_zero = _BitScanForward(&index, mask);
Packit fb9d21
Packit fb9d21
	return non_zero ? 1 + index : 0;
Packit fb9d21
}
Packit fb9d21
#endif