All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] win32: Add missing function ffs
@ 2010-06-11 20:57 Stefan Weil
  2010-06-11 21:35 ` Richard Henderson
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Weil @ 2010-06-11 20:57 UTC (permalink / raw)
  To: QEMU Developers

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;
+}
+
 /* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
 #define _W32_FT_OFFSET (116444736000000000ULL)
 
-- 
1.5.6.5

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH] win32: Add missing function ffs
  2010-06-11 20:57 [Qemu-devel] [PATCH] win32: Add missing function ffs Stefan Weil
@ 2010-06-11 21:35 ` Richard Henderson
  2010-06-12 14:07   ` Stefan Weil
  0 siblings, 1 reply; 6+ messages in thread
From: Richard Henderson @ 2010-06-11 21:35 UTC (permalink / raw)
  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 <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~

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH] win32: Add missing function ffs
  2010-06-11 21:35 ` Richard Henderson
@ 2010-06-12 14:07   ` Stefan Weil
  2010-06-12 15:52     ` [Qemu-devel] " Richard Henderson
  2010-06-24 20:50     ` Stefan Weil
  0 siblings, 2 replies; 6+ messages in thread
From: Stefan Weil @ 2010-06-12 14:07 UTC (permalink / raw)
  To: QEMU Developers; +Cc: Richard Henderson

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.

v2: Use __builtin_ffs as suggested by Richard Henderson

Cc: Richard Henderson <rth@twiddle.net>
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
---
 osdep.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/osdep.c b/osdep.c
index abbc8a2..dbf872a 100644
--- a/osdep.c
+++ b/osdep.c
@@ -167,6 +167,13 @@ int qemu_create_pidfile(const char *filename)
 
 #ifdef _WIN32
 
+/* mingw32 needs ffs for compilations without optimization. */
+int ffs(int i)
+{
+    /* Use gcc's builtin ffs. */
+    return __builtin_ffs(i);
+}
+
 /* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
 #define _W32_FT_OFFSET (116444736000000000ULL)
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] Re: [PATCH] win32: Add missing function ffs
  2010-06-12 14:07   ` Stefan Weil
@ 2010-06-12 15:52     ` Richard Henderson
  2010-06-24 20:50     ` Stefan Weil
  1 sibling, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2010-06-12 15:52 UTC (permalink / raw)
  To: Stefan Weil; +Cc: QEMU Developers

On 06/12/2010 07:07 AM, Stefan Weil wrote:
> v2: Use __builtin_ffs as suggested by Richard Henderson
> 
> Cc: Richard Henderson <rth@twiddle.net>
> Signed-off-by: Stefan Weil <weil@mail.berlios.de>

Acked-by: Richard Henderson <rth@twiddle.net>


r~

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] Re: [PATCH] win32: Add missing function ffs
  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
  1 sibling, 1 reply; 6+ messages in thread
From: Stefan Weil @ 2010-06-24 20:50 UTC (permalink / raw)
  To: Anthony Liguori; +Cc: QEMU Developers

Am 12.06.2010 16:07, schrieb Stefan Weil:
> 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.
>
> v2: Use __builtin_ffs as suggested by Richard Henderson
>
> Cc: Richard Henderson<rth@twiddle.net>
> Signed-off-by: Stefan Weil<weil@mail.berlios.de>
> ---
>   osdep.c |    7 +++++++
>   1 files changed, 7 insertions(+), 0 deletions(-)
>
> diff --git a/osdep.c b/osdep.c
> index abbc8a2..dbf872a 100644
> --- a/osdep.c
> +++ b/osdep.c
> @@ -167,6 +167,13 @@ int qemu_create_pidfile(const char *filename)
>
>   #ifdef _WIN32
>
> +/* mingw32 needs ffs for compilations without optimization. */
> +int ffs(int i)
> +{
> +    /* Use gcc's builtin ffs. */
> +    return __builtin_ffs(i);
> +}
> +
>   /* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
>   #define _W32_FT_OFFSET (116444736000000000ULL)
>
>    

Ping. The patch should be applied to qemu master.

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] Re: [PATCH] win32: Add missing function ffs
  2010-06-24 20:50     ` Stefan Weil
@ 2010-06-27 20:25       ` Blue Swirl
  0 siblings, 0 replies; 6+ messages in thread
From: Blue Swirl @ 2010-06-27 20:25 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Anthony Liguori, QEMU Developers

Thanks, applied.

On Thu, Jun 24, 2010 at 8:50 PM, Stefan Weil <weil@mail.berlios.de> wrote:
> Am 12.06.2010 16:07, schrieb Stefan Weil:
>>
>> 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.
>>
>> v2: Use __builtin_ffs as suggested by Richard Henderson
>>
>> Cc: Richard Henderson<rth@twiddle.net>
>> Signed-off-by: Stefan Weil<weil@mail.berlios.de>
>> ---
>>  osdep.c |    7 +++++++
>>  1 files changed, 7 insertions(+), 0 deletions(-)
>>
>> diff --git a/osdep.c b/osdep.c
>> index abbc8a2..dbf872a 100644
>> --- a/osdep.c
>> +++ b/osdep.c
>> @@ -167,6 +167,13 @@ int qemu_create_pidfile(const char *filename)
>>
>>  #ifdef _WIN32
>>
>> +/* mingw32 needs ffs for compilations without optimization. */
>> +int ffs(int i)
>> +{
>> +    /* Use gcc's builtin ffs. */
>> +    return __builtin_ffs(i);
>> +}
>> +
>>  /* Offset between 1/1/1601 and 1/1/1970 in 100 nanosec units */
>>  #define _W32_FT_OFFSET (116444736000000000ULL)
>>
>>
>
> Ping. The patch should be applied to qemu master.
>
> Thanks,
> Stefan
>
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-06-27 20:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-11 20:57 [Qemu-devel] [PATCH] win32: Add missing function ffs Stefan Weil
2010-06-11 21:35 ` Richard Henderson
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.