From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=36194 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1ONBt4-0002zZ-8B for qemu-devel@nongnu.org; Fri, 11 Jun 2010 17:35:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1ONBt2-0002Ub-IH for qemu-devel@nongnu.org; Fri, 11 Jun 2010 17:35:38 -0400 Received: from mail-pv0-f173.google.com ([74.125.83.173]:34864) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1ONBt2-0002UV-Bm for qemu-devel@nongnu.org; Fri, 11 Jun 2010 17:35:36 -0400 Received: by pvg3 with SMTP id 3so923467pvg.4 for ; Fri, 11 Jun 2010 14:35:35 -0700 (PDT) Sender: Richard Henderson Message-ID: <4C12AC11.4090402@twiddle.net> Date: Fri, 11 Jun 2010 14:35:13 -0700 From: Richard Henderson MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH] win32: Add missing function ffs References: <1276289867-8014-1-git-send-email-weil@mail.berlios.de> In-Reply-To: <1276289867-8014-1-git-send-email-weil@mail.berlios.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Weil Cc: QEMU Developers 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 > --- > 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~