1fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey#ifndef strings_h
2fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey#define strings_h
3fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey
4fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey/* MSVC doesn't define ffs/ffsl. This dummy strings.h header is provided
5fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey * for both */
6fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey#include <intrin.h>
7fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey#pragma intrinsic(_BitScanForward)
8fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommeystatic __forceinline int ffsl(long x)
9fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey{
10fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey	unsigned long i;
11fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey
12fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey	if (_BitScanForward(&i, x))
13fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey		return (i + 1);
14fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey	return (0);
15fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey}
16fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey
17fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommeystatic __forceinline int ffs(int x)
18fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey{
19fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey
20fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey	return (ffsl(x));
21fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey}
22fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey
23fd97b1dfc76647c3f90f28dc63cc987041fe20dfMike Hommey#endif
24