From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
Peter Crosthwaite <peter.crosthwaite@xilinx.com>,
Markus Armbruster <armbru@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH v3 6/9] sd: convert sd_normal_command() ffs(3) call to ctz32()
Date: Mon, 23 Mar 2015 15:29:28 +0000 [thread overview]
Message-ID: <1427124571-28598-7-git-send-email-stefanha@redhat.com> (raw)
In-Reply-To: <1427124571-28598-1-git-send-email-stefanha@redhat.com>
ffs() cannot be replaced with ctz32() when the argument might be zero,
because ffs(0) returns 0 while ctz32(0) returns 32.
The ffs(3) call in sd_normal_command() is a special case though. It can
be converted to ctz32() + 1 because the argument is never zero:
if (!(req.arg >> 8) || (req.arg >> (ctz32(req.arg & ~0xff) + 1))) {
~~~~~~~~~~~~~~~
^--------------- req.arg cannot be zero
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
hw/sd/sd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index f955265..8abf0c9 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -796,8 +796,9 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,
sd->vhs = 0;
/* No response if not exactly one VHS bit is set. */
- if (!(req.arg >> 8) || (req.arg >> ffs(req.arg & ~0xff)))
+ if (!(req.arg >> 8) || (req.arg >> (ctz32(req.arg & ~0xff) + 1))) {
return sd->spi ? sd_r7 : sd_r0;
+ }
/* Accept. */
sd->vhs = req.arg;
--
2.1.0
next prev parent reply other threads:[~2015-03-23 15:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-23 15:29 [Qemu-devel] [PATCH v3 0/9] Convert ffs(3) to ctz32() Stefan Hajnoczi
2015-03-23 15:29 ` [Qemu-devel] [PATCH v3 1/9] bt-sdp: fix broken uuids power-of-2 calculation Stefan Hajnoczi
2015-03-23 15:29 ` [Qemu-devel] [PATCH v3 2/9] hw/arm/nseries: convert ffs(3) to ctz32() Stefan Hajnoczi
2015-03-23 15:29 ` [Qemu-devel] [PATCH v3 3/9] uninorth: " Stefan Hajnoczi
2015-03-23 15:29 ` [Qemu-devel] [PATCH v3 4/9] Convert (ffs(val) - 1) to ctz32(val) Stefan Hajnoczi
2015-03-23 15:29 ` [Qemu-devel] [PATCH v3 5/9] Convert ffs() != 0 callers to ctz32() Stefan Hajnoczi
2015-03-23 15:29 ` Stefan Hajnoczi [this message]
2015-03-23 15:29 ` [Qemu-devel] [PATCH v3 7/9] omap_intc: convert ffs(3) to ctz32() in omap_inth_sir_update() Stefan Hajnoczi
2015-03-23 15:40 ` Paolo Bonzini
2015-03-24 13:36 ` Stefan Hajnoczi
2015-03-23 15:29 ` [Qemu-devel] [PATCH v3 8/9] os-win32: drop ffs(3) prototype Stefan Hajnoczi
2015-03-23 15:29 ` [Qemu-devel] [PATCH v3 9/9] checkpatch: complain about ffs(3) calls Stefan Hajnoczi
2015-03-25 13:09 ` [Qemu-devel] [PATCH v3 0/9] Convert ffs(3) to ctz32() Stefan Hajnoczi
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=1427124571-28598-7-git-send-email-stefanha@redhat.com \
--to=stefanha@redhat.com \
--cc=armbru@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.crosthwaite@xilinx.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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.
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).