qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: Stefan Weil <weil@mail.berlios.de>
Cc: QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] win32: Add missing function ffs
Date: Fri, 11 Jun 2010 14:35:13 -0700	[thread overview]
Message-ID: <4C12AC11.4090402@twiddle.net> (raw)
In-Reply-To: <1276289867-8014-1-git-send-email-weil@mail.berlios.de>

On 06/11/2010 01:57 PM, Stefan Weil wrote:
> mingw32 does not include function ffs.
> 
> Commit c6d29ad6e24533cc3762e1d654275607e1d03058 added a
> declaration for ffs, but an implementation was missing.
> 
> For compilations with optimization, the compiler creates
> inline code, so the implementation is not always needed.
> 
> Without optimization, linking fails without this patch.
> 
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
> ---
>  osdep.c |   15 +++++++++++++++
>  1 files changed, 15 insertions(+), 0 deletions(-)
> 
> diff --git a/osdep.c b/osdep.c
> index abbc8a2..50b38e3 100644
> --- a/osdep.c
> +++ b/osdep.c
> @@ -167,6 +167,21 @@ int qemu_create_pidfile(const char *filename)
>  
>  #ifdef _WIN32
>  
> +/* mingw32 needs ffs for compilations without optimization. */
> +int ffs(int i)
> +{
> +    int position = 0;
> +    if (i != 0) {
> +        for (position = 1; i != 0; position++) {
> +            if (i & 1) {
> +                break;
> +            }
> +            i >>= 1;
> +        }
> +    }
> +    return position;
> +}

This is confusingly written.  You've already tested for zero.

  for (pos = 1; (i & 1) == 0; pos++) {
    i >>= 1;
  }

That said, is there any reason not to just do

int ffs(int i)
{
    return __builtin_ffs(i);
}

?


r~

  reply	other threads:[~2010-06-11 21:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-11 20:57 [Qemu-devel] [PATCH] win32: Add missing function ffs Stefan Weil
2010-06-11 21:35 ` Richard Henderson [this message]
2010-06-12 14:07   ` Stefan Weil
2010-06-12 15:52     ` [Qemu-devel] " Richard Henderson
2010-06-24 20:50     ` Stefan Weil
2010-06-27 20:25       ` Blue Swirl

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=4C12AC11.4090402@twiddle.net \
    --to=rth@twiddle.net \
    --cc=qemu-devel@nongnu.org \
    --cc=weil@mail.berlios.de \
    /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).