From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:58018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvWqA-0006rR-SC for qemu-devel@nongnu.org; Wed, 16 Jan 2013 12:31:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvWq9-0000x3-DM for qemu-devel@nongnu.org; Wed, 16 Jan 2013 12:31:54 -0500 Received: from mail-ie0-f172.google.com ([209.85.223.172]:54790) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvWq9-0000wq-8g for qemu-devel@nongnu.org; Wed, 16 Jan 2013 12:31:53 -0500 Received: by mail-ie0-f172.google.com with SMTP id c13so2962125ieb.17 for ; Wed, 16 Jan 2013 09:31:52 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 16 Jan 2013 18:31:08 +0100 Message-Id: <1358357479-7912-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1358357479-7912-1-git-send-email-pbonzini@redhat.com> References: <1358357479-7912-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v2 01/12] host-utils: add ffsl List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com We can provide fast versions based on the other functions defined by host-utils.h. Some care is required on glibc, which provides ffsl already. Signed-off-by: Paolo Bonzini --- include/qemu/host-utils.h | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index 81c9a75..2a32be4 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -26,6 +26,7 @@ #define HOST_UTILS_H 1 #include "qemu/compiler.h" /* QEMU_GNUC_PREREQ */ +#include /* ffsl */ #if defined(__x86_64__) #define __HAVE_FAST_MULU64__ @@ -237,4 +238,29 @@ static inline int ctpop64(uint64_t val) #endif } +/* glibc does not provide an inline version of ffsl, so always define + * ours. We need to give it a different name, however. + */ +#ifdef __GLIBC__ +#define ffsl qemu_ffsl +#endif +static inline int ffsl(long val) +{ + if (!val) { + return 0; + } + +#if QEMU_GNUC_PREREQ(3, 4) + return __builtin_ctzl(val) + 1; +#else + if (sizeof(long) == 4) { + return ctz32(val) + 1; + } else if (sizeof(long) == 8) { + return ctz64(val) + 1; + } else { + abort(); + } +#endif +} + #endif -- 1.7.1