Skip to content

Commit

Permalink
eal: add rte ffs32 and rte ffs64 inline functions
Browse files Browse the repository at this point in the history
provide toolchain abstraction for __builtin_ffs{,l,ll} gcc built-in
intrinsics.

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
Signed-off-by: 0-day Robot <robot@bytheb.org>
  • Loading branch information
Tyler Retzlaff authored and ovsrobot committed Mar 20, 2024
1 parent 68c6855 commit 0e5bd8c
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/eal/include/rte_bitops.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,28 @@ rte_popcount64(uint64_t v)
return (unsigned int)__popcnt64(v);
}

static inline unsigned int
rte_ffs32(uint32_t v)
{
unsigned long rv;

if (0 == _BitScanForward(&rv, v))
return 0;

return (unsigned int)rv + 1;
}

static inline unsigned int
rte_ffs64(uint64_t v)
{
unsigned long rv;

if (0 == _BitScanForward64(&rv, v))
return 0;

return (unsigned int)rv + 1;
}

#else

/**
Expand Down Expand Up @@ -491,6 +513,18 @@ rte_popcount64(uint64_t v)
return (unsigned int)__builtin_popcountll(v);
}

static inline unsigned int
rte_ffs32(uint32_t v)
{
return (unsigned int)__builtin_ffs(v);
}

static inline unsigned int
rte_ffs64(uint64_t v)
{
return (unsigned int)__builtin_ffsll(v);
}

#endif

/**
Expand Down

0 comments on commit 0e5bd8c

Please sign in to comment.