mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: musl@lists.openwall.com
Subject: [PATCH] a_ctz_32: Instead of a subtraction by 31, use an xor
Date: Thu,  7 Nov 2019 18:39:54 -0800	[thread overview]
Message-ID: <20191108023955.4402-1-rosenp@gmail.com> (raw)

This reduces produced assembly from a mov and sub to a single xor.

Tested with godbolt: https://godbolt.org/z/Qz-Qr5

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 src/internal/atomic.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/internal/atomic.h b/src/internal/atomic.h
index f938879b..196b3fb1 100644
--- a/src/internal/atomic.h
+++ b/src/internal/atomic.h
@@ -256,7 +256,7 @@ static inline void a_crash()
 static inline int a_ctz_32(uint32_t x)
 {
 #ifdef a_clz_32
-	return 31-a_clz_32(x&-x);
+	return a_clz_32(x&-x)^31;
 #else
 	static const char debruijn32[32] = {
 		0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13,
-- 
2.23.0



             reply	other threads:[~2019-11-08  2:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-08  2:39 Rosen Penev [this message]
2019-12-12 15:10 ` Alexander Monakov
2019-12-12 15:17   ` Rich Felker

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=20191108023955.4402-1-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --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).