mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rakib Mullick <rakib.mullick@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	Matthew Wilcox <mawilcox@microsoft.com>,
	Yury Norov <ynorov@caviumnetworks.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Subject: [PATCH]  lib: Avoid redundant sizeof checking in __bitmap_weight() calculation.
Date: Tue, 14 Nov 2017 12:57:31 +0600	[thread overview]
Message-ID: <20171114065731.3602-1-rakib.mullick@gmail.com> (raw)

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.

However, it's unnecessary to do it in case of __bitmap_weight() calculation
inside the loop. We can detect whether to use hweight32() or hweight64()
upfront and call respective function directly. It also reduces the
vmlinux size.

    Before the patch:
   text	   data	    bss	    dec	    hex	filename
12901332	7798930	14541816	35242078	219c05e	vmlinux

    After the patch:
   text	   data	    bss	    dec	    hex	filename
12901331	7798930	14541816	35242077	219c05d	vmlinux

Signed-off-by: Rakib Mullick <rakib.mullick@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Matthew Wilcox <mawilcox@microsoft.com>
Cc: Yury Norov <ynorov@caviumnetworks.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>
 
---
Patch was created against torvald's tree (commit 43ff2f4db9d0f764).

 lib/bitmap.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

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;
+
+	if (is32) {
+		for (k = 0; k < lim; k++)
+			w += hweight32(bitmap[k]);
+	} else {
+		for (k = 0; k < lim; k++)
+			w += hweight64(bitmap[k]);
+	}
 
 	if (bits % BITS_PER_LONG)
 		w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
-- 
2.9.3

             reply	other threads:[~2017-11-14  6:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-14  6:57 Rakib Mullick [this message]
2017-11-14  7:23 ` Rasmus Villemoes
2017-11-14  8:59   ` Rakib Mullick

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171114065731.3602-1-rakib.mullick@gmail.com \
    --to=rakib.mullick@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mawilcox@microsoft.com \
    --cc=mchehab@kernel.org \
    --cc=ynorov@caviumnetworks.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome