win32: Add missing function ffs
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
@@ -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
Quoted 27 lines · Stefan Weil
mingw32 does not include function ffs.
Commit
c6d29ad6e24533cc3762e1d654275607e1d03058added 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 <[email protected]>--- osdep.c | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-)osdep.c +4
-0@@ -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~
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
--- osdep.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
osdep.c +7 -0
@@ -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
Quoted 4 lines · Stefan Weil
v2: Use
__builtin_ffsas suggested by Richard HendersonCc Richard Henderson <[email protected]>Signed-off-by Stefan Weil <[email protected]>
r~
Am 12.06.2010 16:07, schrieb Stefan Weil:
Quoted 27 lines
mingw32 does not include function ffs.
Commit
c6d29ad6e24533cc3762e1d654275607e1d03058added 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_ffsas suggested by Richard HendersonCc Richard Henderson<[email protected]>Signed-off-by Stefan Weil<[email protected]>--- osdep.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)osdep.c +0
-0@@ -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
Blue Swirl
AppliedThanks, 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
c6d29ad6e24533cc3762e1d654275607e1d03058added 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_ffsas suggested by Richard HendersonCc Richard Henderson<[email protected]>Signed-off-by Stefan Weil<[email protected]>---
osdep.c | 7 +++++++1 files changed, 7 insertions(+), 0 deletions(-)osdep.c +0
-0@@ -167,6 +167,13 @@ int qemu_create_pidfile(const char *filename) #ifdef _WIN32osdep.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