2012-04-30 18:38:31 +08:00
|
|
|
#ifndef strings_h
|
|
|
|
#define strings_h
|
|
|
|
|
|
|
|
/* MSVC doesn't define ffs/ffsl. This dummy strings.h header is provided
|
|
|
|
* for both */
|
2015-07-24 04:56:25 +08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# include <intrin.h>
|
|
|
|
# pragma intrinsic(_BitScanForward)
|
2012-04-30 18:38:31 +08: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-07-24 04:56:25 +08:00
|
|
|
#else
|
|
|
|
# define ffsl(x) __builtin_ffsl(x)
|
|
|
|
# define ffs(x) __builtin_ffs(x)
|
2012-04-30 18:38:31 +08:00
|
|
|
#endif
|
2015-07-24 04:56:25 +08:00
|
|
|
|
|
|
|
#endif /* strings_h */
|