From: Jens Gustedt <Jens.Gustedt@inria.fr>
To: musl@lists.openwall.com
Subject: [musl] [C23 stdbit.h 1/2] implement low level popcount
Date: Wed, 31 May 2023 16:48:33 +0200 [thread overview]
Message-ID: <b2c7636ef64d2f839adf7b970b9334d438a44fc3.1685538619.git.Jens.Gustedt@inria.fr> (raw)
In-Reply-To: <cover.1685538619.git.Jens.Gustedt@inria.fr>
---
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
next prev parent reply other threads:[~2023-05-31 14:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-31 14:48 [musl] [C23 stdbit.h 0/2] just one big C file Jens Gustedt
2023-05-31 14:48 ` Jens Gustedt [this message]
2023-05-31 14:48 ` [musl] [C23 stdbit.h 2/2] C23: add the bit and byte utilities Jens Gustedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b2c7636ef64d2f839adf7b970b9334d438a44fc3.1685538619.git.Jens.Gustedt@inria.fr \
--to=jens.gustedt@inria.fr \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).