From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 10094 invoked from network); 31 May 2023 14:49:01 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 31 May 2023 14:49:01 -0000 Received: (qmail 28036 invoked by uid 550); 31 May 2023 14:48:50 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 27977 invoked from network); 31 May 2023 14:48:49 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=AszSWz5kZPuZ2v4CB4tQqmPVHzrMRHRCzsqJPVqwXB4=; b=aWhNw8P4vw1olF+8QV3CugG2UDTEt9/zIx/QkgI52F5vZCzZ+A7zFanz CvydOR3hmti3PYvbU5A6VgB67vsWiThIXPzPkEkT0NHL2nVSBSVjXnpcH AGT4IlwLDgLl35atO0kI48qNvggvikrgtX5lhuRAmkKWCA8Xj2i6QmORP Y=; Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=Jens.Gustedt@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.00,207,1681164000"; d="scan'208";a="57467755" From: Jens Gustedt To: musl@lists.openwall.com Date: Wed, 31 May 2023 16:48:33 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [C23 stdbit.h 1/2] implement low level popcount --- src/internal/atomic.h | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/internal/atomic.h b/src/internal/atomic.h index 96c1552d..39c47ed5 100644 --- a/src/internal/atomic.h +++ b/src/internal/atomic.h @@ -330,4 +330,49 @@ static inline int a_clz_32(uint32_t x) } #endif +#ifndef a_popcount_14 +#define a_popcount_14 a_popcount_14 +static inline int a_popcount_14(uint64_t x) +{ + x &= UINT64_C(0x3FFF); + return (x * UINT64_C(0x200040008001) & UINT64_C(0x111111111111111)) % 0xf; +} +#endif + +#ifndef a_popcount_8 +#define a_popcount_8 a_popcount_8 +static inline int a_popcount_8(uint64_t x) +{ + x &= UINT64_C(0xFF); + return a_popcount_14(x); +} +#endif + +#ifndef a_popcount_16 +#define a_popcount_16 a_popcount_16 +static inline int a_popcount_16(uint64_t x) +{ + x &= UINT64_C(0xFFFF); + return a_popcount_14(x) + a_popcount_14(x>>14); +} +#endif + +#ifndef a_popcount_32 +#define a_popcount_32 a_popcount_32 +static inline int a_popcount_32(uint64_t x) +{ + x &= UINT64_C(0xFFFFFFFF); + return a_popcount_14(x) + a_popcount_14(x>>14) + a_popcount_14(x>>28); +} +#endif + +#ifndef a_popcount_64 +#define a_popcount_64 a_popcount_64 +static inline int a_popcount_64(uint64_t x) +{ + return a_popcount_14(x) + a_popcount_14(x>>14) + a_popcount_14(x>>28) + + a_popcount_14(x>>42) + a_popcount_14(x>>56); +} +#endif + #endif -- 2.34.1