diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-07-01 08:39:38 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-07-01 08:39:38 +1000 |
commit | 68d1c19455f596a09d9dcf40279ae9cf5a9c71de (patch) | |
tree | 58a2b3d7d212527bf740c14e56c88bb6e6b80f2d /lib/windows/include/strings.h | |
parent | ce68aad07890796f9498d2d216da7cd779329e3a (diff) |
Throw away 32-bit support
Diffstat (limited to 'lib/windows/include/strings.h')
-rw-r--r-- | lib/windows/include/strings.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/windows/include/strings.h b/lib/windows/include/strings.h new file mode 100644 index 0000000..a3ee250 --- /dev/null +++ b/lib/windows/include/strings.h @@ -0,0 +1,59 @@ +#ifndef strings_h +#define strings_h + +/* MSVC doesn't define ffs/ffsl. This dummy strings.h header is provided + * for both */ +#ifdef _MSC_VER +# include <intrin.h> +# pragma intrinsic(_BitScanForward) +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)); +} + +# ifdef _M_X64 +# pragma intrinsic(_BitScanForward64) +# endif + +static __forceinline int ffsll(unsigned __int64 x) +{ + unsigned long i; +#ifdef _M_X64 + if (_BitScanForward64(&i, x)) + return (i + 1); + return (0); +#else +// Fallback for 32-bit build where 64-bit version not available +// assuming little endian + union { + unsigned __int64 ll; + unsigned long l[2]; + } s; + + s.ll = x; + + if (_BitScanForward(&i, s.l[0])) + return (i + 1); + else if(_BitScanForward(&i, s.l[1])) + return (i + 33); + return (0); +#endif +} + +#else +# define ffsll(x) __builtin_ffsll(x) +# define ffsl(x) __builtin_ffsl(x) +# define ffs(x) __builtin_ffs(x) +#endif + +#endif /* strings_h */ |