From patchwork Wed Dec 12 13:46:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 205538 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 773D72C0093 for ; Thu, 13 Dec 2012 01:25:16 +1100 (EST) Received: from localhost ([::1]:54540 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Timgp-000384-LY for incoming@patchwork.ozlabs.org; Wed, 12 Dec 2012 08:49:35 -0500 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=D7a6LJz1TtX0ifMy4NRoRMo7mhg0i6Zuu+p+D+mS9kc=; b=V1cdd1YOv8HmJZIfSUtD1gbTdLIDMo1DvMsYdC7/DQ6sAchBhVa/iAquJpYgRAcahC qCsuSZQWaUCUxc3zGz4zEZJcoqd1X2FvuMb0MR8t37cLhaJu7k8M7WBeZml3N1AQzh+1 ltG3HNy13Cu8RKKhXDnsVy51j1Tsxcjg/lTIiuGPnwWlC/rwD9zvuzvxZtUYR2tC3PpX FfAj2fF+I5gozDtlOjF2Bo6HpMMBsU4FQk4Eg15cINuFZDDfHmgunmAfVu1VotEoZTeI q+BmN8EOQs+7HyY5vILnykN8ztbvNP6eWC3f4OITViP2+aR0R4kAZ3lJ2sM8njLbPRAZ om7g== Received: by 10.50.45.137 with SMTP id n9mr13335997igm.25.1355320018330; Wed, 12 Dec 2012 05:46:58 -0800 (PST) Received: from yakj.usersys.redhat.com (93-34-219-150.ip51.fastwebnet.it. [93.34.219.150]) by mx.google.com with ESMTPS id fv6sm1786818igc.17.2012.12.12.05.46.55 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 12 Dec 2012 05:46:56 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 12 Dec 2012 14:46:20 +0100 Message-Id: <1355319999-30627-2-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.0.1 In-Reply-To: <1355319999-30627-1-git-send-email-pbonzini@redhat.com> References: <1355319999-30627-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.179 Cc: kwolf@redhat.com, jcody@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH 01/20] 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 Reviewed-by: Eric Blake --- 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 +}