From patchwork Mon Jan 21 16:09:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 214206 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 245712C0082 for ; Tue, 22 Jan 2013 03:25:34 +1100 (EST) Received: from localhost ([::1]:45922 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxKBg-0001Y0-3R for incoming@patchwork.ozlabs.org; Mon, 21 Jan 2013 11:25:32 -0500 Received: from eggs.gnu.org ([208.118.235.92]:49215) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxKBT-0001LA-9B for qemu-devel@nongnu.org; Mon, 21 Jan 2013 11:25:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TxKBR-0004cW-Kk for qemu-devel@nongnu.org; Mon, 21 Jan 2013 11:25:18 -0500 Received: from mail-ea0-f179.google.com ([209.85.215.179]:55510) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TxJwe-0008TZ-6w for qemu-devel@nongnu.org; Mon, 21 Jan 2013 11:10:00 -0500 Received: by mail-ea0-f179.google.com with SMTP id d12so1694498eaa.38 for ; Mon, 21 Jan 2013 08:09:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=a2ouueNFilK08oMO2yCn2ofA0/A8VFxBbIn7vz1OILc=; b=a7V6Exeb0E3JcgvMBDGibsNYW9/7Guw4pwXnPloCxslIm85GVwGJOdCr5bMXV580NE BLTS63RgVWVSHoV2s8ENI6Hf5sLxR6q9v0ayXc8+Fc2DeLJI805KBMc2DuIWm7XV+stm HkrJY0RZj8fhOiYLXGpAXxi72V1v8gWsFILMwDFZskNMw8BNkXKtJLqkJgd3d6+qxJ2L Scvhvkpo5VA2lWFINnA7jkXQ9HChsj+nSFvAlZJz2iIQlKBNg3YEp30k7o8wJS652NJD hmbtvGh0EbzkhR3rxTzSa89XS7i9I4Mgy7fpKunI97XDPFE1Oqh3J8WCAqxX7OO8DHw8 zcqQ== X-Received: by 10.14.211.136 with SMTP id w8mr16865537eeo.7.1358784599342; Mon, 21 Jan 2013 08:09:59 -0800 (PST) Received: from yakj.lan (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id q5sm7892408eeo.17.2013.01.21.08.09.57 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 21 Jan 2013 08:09:58 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 21 Jan 2013 17:09:39 +0100 Message-Id: <1358784590-16288-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1358784590-16288-1-git-send-email-pbonzini@redhat.com> References: <1358784590-16288-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.215.179 Cc: kwolf@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v3 01/12] host-utils: add ffsl X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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. Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- include/qemu/host-utils.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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