diff --git a/inline.h b/inline.h index be5ce02895be..9cc54c865e6c 100644 --- a/inline.h +++ b/inline.h @@ -731,6 +731,21 @@ Perl_is_utf8_invariant_string_loc(const U8* const s, STRLEN len, const U8 ** ep) # endif #endif +#if U32SIZE == INTSIZE && defined(HAS_FFS) +# define PERL_FFS32 ffs +#elif U32SIZE == LONGSIZE && defined(HAS_FFSL) +# define PERL_FFS32 ffsl +#endif +#ifdef HAS_QUAD +# if U64SIZE == INTSIZE && defined(HAS_FFS) +# define PERL_FFS64 ffs +# elif U64SIZE == LONGSIZE && defined(HAS_FFSL) +# define PERL_FFS64 ffsl +# elif U64SIZE == LONGLONGSIZE && defined(HAS_FFSLL) +# define PERL_FFS64 ffsll +# endif +#endif + #if defined(_MSC_VER) && _MSC_VER >= 1400 # include # pragma intrinsic(_BitScanForward) @@ -771,6 +786,10 @@ Perl_lsbit_pos64(U64 word) return (unsigned)index; } +# elif defined(PERL_FFS64) + + return PERL_FFS64(word) - 1; /* ffs() returns bit position indexed from 1 */ + # else /* Here, we didn't find a fast method for finding the lsb. Fall back to @@ -823,6 +842,10 @@ Perl_lsbit_pos32(U32 word) return (unsigned)index; } +#elif defined(PERL_FFS32) + + return PERL_FFS32(word) - 1; + #else return single_1bit_pos32(word & (~word + 1));