Received: by 10.223.164.202 with SMTP id h10csp204409wrb; Mon, 13 Nov 2017 23:26:29 -0800 (PST) X-Google-Smtp-Source: AGs4zMapJRWAKa0OhGLU27gW+9MQRHID/wfRkSWwiQeijHz5vDylb6BuNFDp3PLu7pJ1NVdC821G X-Received: by 10.98.110.73 with SMTP id j70mr12750812pfc.146.1510644389324; Mon, 13 Nov 2017 23:26:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510644389; cv=none; d=google.com; s=arc-20160816; b=Fy4raM3opC9MI+0I8lPQAGsJ17KAxDIaU6xPvuSRjs8x/N809DDQKj+Iq9F6++7M4/ S9TGH8cxCj6b4SgAoB5oh/bs8qqudEb9txnFtVrgIxlzAcUv3RdH3sX+KglouaSPr2Jg piNihOZ0vSJR0zvqiThRnGXBikPVXzu+OvTMrFt+yMzA22mw8rqeUVREeXi/IXTYR2Eo ZlxaX4D3bVGcXDZaIxeec2BvTvF958JFw7EM3wwol5s/c4pJOGJf+2UOrRRIEB3I1x1F OBhK5sQRUSEdFB3qKn+JuDmSm2CulZabbHOql19g2w/jsouYSdDu9rZNi+A9gyT3vC42 6jaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=7ywxBBy2n+ZpQeJz7unvj8WQMG18p/ro6sRTY0Ps5Ro=; b=nO3XSzyQwyfpLhzSmdreQWLhdzV7/xTTtwZUEEwu+VQ5yq1e2QPtzB1Jg3q+qoU9Qz N/uFZRj5b+f7dTbghZuAxZm5NdMnf2rz97j7t12BtsEZyO0X/JiZsNj2fmkhnAJ8/pPn +Acuga//lvB8pqMcHi9Mh5kpsqcA2pDJU/pfPEgI63Wl+6UpBGDN3BZul4/r64fgI8ck VOw6phAQhFdfQYDnf/04L0gN2MixCrDIFNAKEwbifkgYnsW1+nTkN0xx4WgxVkXarRW1 2mh/tPXW7BZ+/7tC32WjSOFpSKjHpm9Md6ABm2lClp5DT2OHt4es76AzI5UdSN3nNPBo 17KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=YQL606NZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x21si3771099pge.567.2017.11.13.23.26.16; Mon, 13 Nov 2017 23:26:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=YQL606NZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753494AbdKNHXw (ORCPT + 89 others); Tue, 14 Nov 2017 02:23:52 -0500 Received: from mail-it0-f49.google.com ([209.85.214.49]:53476 "EHLO mail-it0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752907AbdKNHXp (ORCPT ); Tue, 14 Nov 2017 02:23:45 -0500 Received: by mail-it0-f49.google.com with SMTP id m191so12442345itg.2 for ; Mon, 13 Nov 2017 23:23:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=7ywxBBy2n+ZpQeJz7unvj8WQMG18p/ro6sRTY0Ps5Ro=; b=YQL606NZviqEqfB/rfboFOXV/MATljDC2jhbqniCg3x5U6t65lLmgdyAbYNlIokqYv L5r897C9IK54+KnMsQUsRmuO82YIUs8G+uyUlS4eobdYULhn6svPI8eFj0h8tupbch8u W5QDa2VidZ0GvUaoRVb9+KjL567Wxu5qz8UvE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=7ywxBBy2n+ZpQeJz7unvj8WQMG18p/ro6sRTY0Ps5Ro=; b=H31xu1SUkYzdRBTcb3BpfRI41fIdGb47uTglt5OhDM6v17RV9UzCfd/vEa0DblAsLg 1/wBAudoOms/wQNeEuZnZhfx59BpcalDGwhXIKaY6rABW+SF6Gf8qPyQcCuQlOlELpx/ iGmqAOatN7bfRVzJm/J92mxIqtfPDw3qIh+ES3oGXDaXu8RYUep0H6Pm7XxMt3OMEmw2 rYTQYSG6fcUMDW/YMWvn4V6Zn4nQ/0Gk1XHE9UXOOivXnY4B0YRQixUOrY/YDuNQKVpD KgUppK3u7GVCNX5j6P3LkPSinyPK1BxmU95pliFsPqtMO+mpg/r2/+qjPFYSYRW2hhnB r8Nw== X-Gm-Message-State: AJaThX45sYy2awFjEY3uuMAPwp5Mh2EgBGu93ScE52v5KIaTp8G0ytWX OumTJaYZg05yAOB7jUggWN9WG0wspsHf1XbCdshyTg== X-Received: by 10.36.196.10 with SMTP id v10mr14190609itf.39.1510644225082; Mon, 13 Nov 2017 23:23:45 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.83.2 with HTTP; Mon, 13 Nov 2017 23:23:44 -0800 (PST) In-Reply-To: <20171114065731.3602-1-rakib.mullick@gmail.com> References: <20171114065731.3602-1-rakib.mullick@gmail.com> From: Rasmus Villemoes Date: Tue, 14 Nov 2017 08:23:44 +0100 Message-ID: Subject: Re: [PATCH] lib: Avoid redundant sizeof checking in __bitmap_weight() calculation. To: Rakib Mullick Cc: linux-kernel@vger.kernel.org, Andrew Morton , Matthew Wilcox , Yury Norov , Mauro Carvalho Chehab Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 14 November 2017 at 07:57, Rakib Mullick wrote: > Currently, during __bitmap_weight() calculation hweight_long() is used. > Inside a hweight_long() a check has been made to figure out whether a > hweight32() or hweight64() version to use. > > diff --git a/lib/bitmap.c b/lib/bitmap.c > index d8f0c09..552096f 100644 > --- a/lib/bitmap.c > +++ b/lib/bitmap.c > @@ -241,10 +241,15 @@ EXPORT_SYMBOL(__bitmap_subset); > int __bitmap_weight(const unsigned long *bitmap, unsigned int bits) > { > unsigned int k, lim = bits/BITS_PER_LONG; > - int w = 0; > - > - for (k = 0; k < lim; k++) > - w += hweight_long(bitmap[k]); > + int w = 0, is32 = sizeof(bitmap[0]) ? 1 : 0; > + hint: sizeof() very rarely evaluates to zero... So this is the same as "is32 = 1". So the patch as-is is broken (and may explain the 1-byte delta in vmlinux). But even if this condition is fixed, the patch doesn't change anything, since the sizeof() evaluation is done at compile-time, regardless of whether it happens inside the inlined hweight_long or outside. So it is certainly not worth it to duplicate the loop. Rasmus From 1584269473230290707@xxx Fri Nov 17 00:05:06 +0000 2017 X-GM-THRID: 1584269473230290707 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread