strings.h 490 B

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