From patchwork Sun Feb 9 20:51:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilia Mirkin X-Patchwork-Id: 3614301 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DB1199F2D6 for ; Sun, 9 Feb 2014 20:51:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1019420163 for ; Sun, 9 Feb 2014 20:51:51 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id B5564200E5 for ; Sun, 9 Feb 2014 20:51:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CF4B6FA4F3; Sun, 9 Feb 2014 12:51:41 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qa0-f53.google.com (mail-qa0-f53.google.com [209.85.216.53]) by gabe.freedesktop.org (Postfix) with ESMTP id 04DCFFA4E7; Sun, 9 Feb 2014 12:51:38 -0800 (PST) Received: by mail-qa0-f53.google.com with SMTP id cm18so8375418qab.40 for ; Sun, 09 Feb 2014 12:51:36 -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; bh=CDkiVqUWvkc+PFwHnEq6yyxcsrGT+j9eBng7f7WIBPE=; b=FoLZkNcM9JhNiCuOEhhn96icPIlqZROh6ugy5Pg9mzkIiQoVhgdZ/QvSfdXv0KYigV zahcK+Et/vesmi76v52T9pSmA0At+1GXPehWmHqv+G1KulJt4nwvH8JHL25Qk+auVggJ Hv6fIcu0GKL5PfQkdWOg8RwYzX6237PQIwYMmeYDfS2C/cMFIt4VU4szxsufPUVv1Vyi 6+k3aYeVpnB4PREk7LN2fQ/4hRMN9ZvBls4HY4XLu2rcr7ei8NSkNr3LxCj+VCMNhsBE aTl/TCNle5a4rf3xnLvATf+K2aaeTgJnqDsCjAUIHBbuzkg4ccKkY7R/I3HJLNHeD0vT cJUA== X-Received: by 10.140.21.179 with SMTP id 48mr39339280qgl.78.1391979096206; Sun, 09 Feb 2014 12:51:36 -0800 (PST) Received: from athos.24.29.103.16 (cpe-74-71-29-187.nyc.res.rr.com. [74.71.29.187]) by mx.google.com with ESMTPSA id m14sm10041354qax.9.2014.02.09.12.51.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 09 Feb 2014 12:51:35 -0800 (PST) From: Ilia Mirkin To: Ben Skeggs , nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm/nouveau: replace ffsll with __ffs64 Date: Sun, 9 Feb 2014 15:51:24 -0500 Message-Id: <1391979085-8012-1-git-send-email-imirkin@alum.mit.edu> X-Mailer: git-send-email 1.8.3.2 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The ffsll function is a lot slower than the __ffs64 built-in which compiles to a single instruction on 64-bit. It's also nice to avoid custom versions of standard functions. Note that __ffs == ffs - 1. Signed-off-by: Ilia Mirkin --- I wrote a user-space program to test these out and make sure that the functions behaved as expected. The logic in abi16 had to be flipped around a bit since __ffs doesn't distinguish between 0 and 1. There's a minor difference in that init->channel is going to get returned as 0 for ENOSPC vs -1, but I can't imagine that'd matter. drivers/gpu/drm/nouveau/core/core/parent.c | 2 +- drivers/gpu/drm/nouveau/core/os.h | 11 ----------- drivers/gpu/drm/nouveau/nouveau_abi16.c | 4 ++-- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/nouveau/core/core/parent.c b/drivers/gpu/drm/nouveau/core/core/parent.c index 313380c..dee5d12 100644 --- a/drivers/gpu/drm/nouveau/core/core/parent.c +++ b/drivers/gpu/drm/nouveau/core/core/parent.c @@ -49,7 +49,7 @@ nouveau_parent_sclass(struct nouveau_object *parent, u16 handle, mask = nv_parent(parent)->engine; while (mask) { - int i = ffsll(mask) - 1; + int i = __ffs64(mask); if (nv_iclass(parent, NV_CLIENT_CLASS)) engine = nv_engine(nv_client(parent)->device); diff --git a/drivers/gpu/drm/nouveau/core/os.h b/drivers/gpu/drm/nouveau/core/os.h index 191e739..3cd6120 100644 --- a/drivers/gpu/drm/nouveau/core/os.h +++ b/drivers/gpu/drm/nouveau/core/os.h @@ -23,17 +23,6 @@ #include -static inline int -ffsll(u64 mask) -{ - int i; - for (i = 0; i < 64; i++) { - if (mask & (1ULL << i)) - return i + 1; - } - return 0; -} - #ifndef ioread32_native #ifdef __BIG_ENDIAN #define ioread16_native ioread16be diff --git a/drivers/gpu/drm/nouveau/nouveau_abi16.c b/drivers/gpu/drm/nouveau/nouveau_abi16.c index 900fae0..b701117 100644 --- a/drivers/gpu/drm/nouveau/nouveau_abi16.c +++ b/drivers/gpu/drm/nouveau/nouveau_abi16.c @@ -270,8 +270,8 @@ nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS) return nouveau_abi16_put(abi16, -EINVAL); /* allocate "abi16 channel" data and make up a handle for it */ - init->channel = ffsll(~abi16->handles); - if (!init->channel--) + init->channel = __ffs64(~abi16->handles); + if (~abi16->handles == 0) return nouveau_abi16_put(abi16, -ENOSPC); chan = kzalloc(sizeof(*chan), GFP_KERNEL);