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