2012-05-15 09:27:12 -04:00
|
|
|
#ifndef strings_h
|
|
|
|
#define strings_h
|
|
|
|
|
|
|
|
/* MSVC doesn't define ffs/ffsl. This dummy strings.h header is provided
|
|
|
|
* for both */
|
2015-10-06 10:18:30 -04:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# include <intrin.h>
|
|
|
|
# pragma intrinsic(_BitScanForward)
|
2012-05-15 09:27:12 -04:00
|
|
|
static __forceinline int ffsl(long x)
|
|
|
|
{
|
|
|
|
unsigned long i;
|
|
|
|
|
|
|
|
if (_BitScanForward(&i, x))
|
|
|
|
return (i + 1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline int ffs(int x)
|
|
|
|
{
|
|
|
|
|
|
|
|
return (ffsl(x));
|
|
|
|
}
|
|
|
|
|
2015-10-06 10:18:30 -04:00
|
|
|
#else
|
|
|
|
# define ffsl(x) __builtin_ffsl(x)
|
|
|
|
# define ffs(x) __builtin_ffs(x)
|
2012-05-15 09:27:12 -04:00
|
|
|
#endif
|
2015-10-06 10:18:30 -04:00
|
|
|
|
|
|
|
#endif /* strings_h */
|