Skip to contentSkip to conversation

win32: Add missing function ffs

PATCH In review Stefan Weil 3 participants 6 messages Jun 11, 2010 – Jun 27, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 win32: Add missing function ffs

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.

---
 osdep.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
osdep.c +15 -0
index abbc8a2..50b38e3 100644
@@ -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)
 
Signature · 1 line
1.5.6.5
#1 lore raw
Quoted 27 lines · 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.

---
 osdep.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
osdep.c +4 -0
index abbc8a2..50b38e3 100644
@@ -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;

osdep.c int qemu_create_pidfile(const char *filename) · line 183

Quoted 10 lines
osdep.c +10 -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~

#2 lore raw

PATCH 1/1 win32: Add missing function ffs

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 <[email protected]>
---
 osdep.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
osdep.c +7 -0
index abbc8a2..dbf872a 100644
@@ -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)
 
Signature · 1 line
1.7.1
#4 lore raw
In reply to Stefan Weil

Am 12.06.2010 16:07, schrieb Stefan Weil:

Quoted 27 lines

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<[email protected]>
---
  osdep.c |    7 +++++++
  1 files changed, 7 insertions(+), 0 deletions(-)
osdep.c +0 -0
index abbc8a2..dbf872a 100644
@@ -167,6 +167,13 @@ int qemu_create_pidfile(const char *filename)
 
  #ifdef _WIN32
 

osdep.c int qemu_create_pidfile(const char *filename) · line 179

Quoted 10 lines
osdep.c +7 -0
+/* 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

Applied
#5 lore raw

Thanks, applied.

Quoted 47 lines · Stefan Weil

Am 12.06.2010 16:07, schrieb Stefan Weil:

Quoted 28 lines

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<[email protected]>

---
 osdep.c |    7 +++++++

 1 files changed, 7 insertions(+), 0 deletions(-)
osdep.c +0 -0
index abbc8a2..dbf872a 100644
@@ -167,6 +167,13 @@ int qemu_create_pidfile(const char *filename)
 
  #ifdef _WIN32
 

osdep.c int qemu_create_pidfile(const char *filename) · line 179

Quoted 10 lines
osdep.c +7 -0
+/* 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