25 lines · c
1#include <isl_config.h>2 3#if !HAVE_DECL_FFS && !HAVE_DECL___BUILTIN_FFS && HAVE_DECL__BITSCANFORWARD4#include <intrin.h>5 6/* Implementation of ffs in terms of _BitScanForward.7 *8 * ffs returns the position of the least significant bit set in i,9 * with the least significant bit is position 1, or 0 if not bits are set.10 *11 * _BitScanForward returns 1 if mask is non-zero and sets index12 * to the position of the least significant bit set in i,13 * with the least significant bit is position 0.14 */15int isl_ffs(int i)16{17 unsigned char non_zero;18 unsigned long index, mask = i;19 20 non_zero = _BitScanForward(&index, mask);21 22 return non_zero ? 1 + index : 0;23}24#endif25