From patchwork Wed Jan 16 17:31:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 212859 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 A121E2C0040 for ; Thu, 17 Jan 2013 04:32:09 +1100 (EST) Received: from localhost ([::1]:34775 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvWqN-0006xm-Ne for incoming@patchwork.ozlabs.org; Wed, 16 Jan 2013 12:32:07 -0500 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) 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=9iUfGcCG9cDhIb/sr3IFPFSPXO1CR+lLfBZ9bjSN+nA=; b=DPT7FSuxNbWnFI7+LjloXdWf4I+y3yTOefzlBg31Vx9sHQNteg7+BzF4V6IcDBBK1h 2buZeQqz7uuku0rcMN7z/8CRNlUYfnk8LaijObMU0W43Ygiu6D9uoWWKT9TJX8DuZ6vC WywmNhKiYiXNrGC02X/UBFm3n1l592zU9As/KTVyBW0Fn8TrsN+53eX2lpjf1ROqsnRI 1CenaEfIPrVmXHsTlwkx3T7AQJaRWE8SnuSBKbPMwKlE2nNNmGXtgPKQr6I56Sqp7UPx pKZw3erTLtC8PQ9Dflk4fNtX62qtOD8BbcxTF7cE+vGXvKMyf9tkNMMmMnSFjRWbrqtu 11vw== X-Received: by 10.50.237.3 with SMTP id uy3mr1327845igc.28.1358357512812; Wed, 16 Jan 2013 09:31:52 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-179-137.ip50.fastwebnet.it. [93.34.179.137]) by mx.google.com with ESMTPS id xn10sm4810446igb.4.2013.01.16.09.31.50 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 16 Jan 2013 09:31:51 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 16 Jan 2013 18:31:08 +0100 Message-Id: <1358357479-7912-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1358357479-7912-1-git-send-email-pbonzini@redhat.com> References: <1358357479-7912-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.223.172 Cc: kwolf@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v2 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. 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