From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:59283) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Timgc-0002zD-8W for qemu-devel@nongnu.org; Wed, 12 Dec 2012 08:49:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TimgW-00042b-Ep for qemu-devel@nongnu.org; Wed, 12 Dec 2012 08:49:22 -0500 Received: from mail-ie0-f179.google.com ([209.85.223.179]:34124) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TimeI-0003hq-SM for qemu-devel@nongnu.org; Wed, 12 Dec 2012 08:46:58 -0500 Received: by mail-ie0-f179.google.com with SMTP id k14so1748179iea.24 for ; Wed, 12 Dec 2012 05:46:58 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Wed, 12 Dec 2012 14:46:20 +0100 Message-Id: <1355319999-30627-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1355319999-30627-1-git-send-email-pbonzini@redhat.com> References: <1355319999-30627-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 01/20] 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, jcody@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 --- host-utils.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/host-utils.h b/host-utils.h index 821db93..231d580 100644 --- a/host-utils.h +++ b/host-utils.h @@ -24,6 +24,7 @@ */ #include "compiler.h" /* QEMU_GNUC_PREREQ */ +#include /* ffsl */ #if defined(__x86_64__) #define __HAVE_FAST_MULU64__ @@ -234,3 +235,28 @@ static inline int ctpop64(uint64_t val) return 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 +} -- 1.8.0.1