From 98d334bd945b038b7340af451ed7873143076a4b Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Mon, 15 Oct 2018 09:33:41 +0200 Subject: [PATCH] MINOR: tools: add a new function atleast2() to test masks for more than 1 bit For threads it's common to have to check if a mask contains more than one bit set. Let's have this "atleast2()" function report this. --- include/common/standard.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/common/standard.h b/include/common/standard.h index fabe97276..3e13f301c 100644 --- a/include/common/standard.h +++ b/include/common/standard.h @@ -801,6 +801,12 @@ static inline unsigned int my_popcountl(unsigned long a) return cnt; } +/* returns non-zero if has at least 2 bits set */ +static inline unsigned long atleast2(unsigned long a) +{ + return a & (a - 1); +} + /* Simple ffs implementation. It returns the position of the lowest bit set to * one. It is illegal to call it with a==0 (undefined result). */