linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Akinobu Mita <akinobu.mita@gmail.com>
Cc: linux-kernel@vger.kernel.org, Anders Larsen <al@alarsen.net>,
	Alasdair Kergon <agk@redhat.com>,
	dm-devel@redhat.com, linux-fsdevel@vger.kernel.org,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	linux-media@vger.kernel.org, Mark Fasheh <mfasheh@suse.com>,
	Joel Becker <jlbec@evilplan.org>,
	ocfs2-devel@oss.oracle.com, Jan Kara <jack@suse.cz>,
	linux-ext4@vger.kernel.org,
	Andreas Dilger <adilger.kernel@dilger.ca>,
	"Theodore Ts'o" <tytso@mit.edu>, Matthew Wilcox <matthew@wil.cx>
Subject: Re: [PATCH v3 1/9] string: introduce memweight
Date: Mon, 11 Jun 2012 16:17:25 -0700	[thread overview]
Message-ID: <20120611161725.84330925.akpm@linux-foundation.org> (raw)
In-Reply-To: <1339203038-13069-1-git-send-email-akinobu.mita@gmail.com>

On Sat,  9 Jun 2012 09:50:30 +0900
Akinobu Mita <akinobu.mita@gmail.com> wrote:

> memweight() is the function that counts the total number of bits set
> in memory area.  Unlike bitmap_weight(), memweight() takes pointer
> and size in bytes to specify a memory area which does not need to be
> aligned to long-word boundary.
> 
> ...
>
> +/**
> + * memweight - count the total number of bits set in memory area
> + * @ptr: pointer to the start of the area
> + * @bytes: the size of the area
> + */
> +size_t memweight(const void *ptr, size_t bytes)
> +{
> +	size_t w = 0;

Calling the return value "ret" is a useful convention and fits well here.

> +	size_t longs;
> +	const unsigned char *bitmap = ptr;
> +
> +	for (; bytes > 0 && ((unsigned long)bitmap) % sizeof(long);
> +			bytes--, bitmap++)
> +		w += hweight8(*bitmap);
> +
> +	longs = bytes / sizeof(long);
> +	if (longs) {
> +		BUG_ON(longs >= INT_MAX / BITS_PER_LONG);
> +		w += bitmap_weight((unsigned long *)bitmap,
> +				longs * BITS_PER_LONG);
> +		bytes -= longs * sizeof(long);
> +		bitmap += longs * sizeof(long);
> +	}
> +	/*
> +	 * The reason that this last loop is distinct from the preceding
> +	 * bitmap_weight() call is to compute 1-bits in the last region smaller
> +	 * than sizeof(long) properly on big-endian systems.
> +	 */
> +	for (; bytes > 0; bytes--, bitmap++)
> +		w += hweight8(*bitmap);
> +
> +	return w;
> +}
> +EXPORT_SYMBOL(memweight);

diff -puN lib/string.c~string-introduce-memweight-fix lib/string.c
--- a/lib/string.c~string-introduce-memweight-fix
+++ a/lib/string.c
@@ -833,18 +833,18 @@ EXPORT_SYMBOL(memchr_inv);
  */
 size_t memweight(const void *ptr, size_t bytes)
 {
-	size_t w = 0;
+	size_t ret = 0;
 	size_t longs;
 	const unsigned char *bitmap = ptr;
 
 	for (; bytes > 0 && ((unsigned long)bitmap) % sizeof(long);
 			bytes--, bitmap++)
-		w += hweight8(*bitmap);
+		ret += hweight8(*bitmap);
 
 	longs = bytes / sizeof(long);
 	if (longs) {
 		BUG_ON(longs >= INT_MAX / BITS_PER_LONG);
-		w += bitmap_weight((unsigned long *)bitmap,
+		ret += bitmap_weight((unsigned long *)bitmap,
 				longs * BITS_PER_LONG);
 		bytes -= longs * sizeof(long);
 		bitmap += longs * sizeof(long);
@@ -855,8 +855,8 @@ size_t memweight(const void *ptr, size_t
 	 * than sizeof(long) properly on big-endian systems.
 	 */
 	for (; bytes > 0; bytes--, bitmap++)
-		w += hweight8(*bitmap);
+		ret += hweight8(*bitmap);
 
-	return w;
+	return ret;
 }
 EXPORT_SYMBOL(memweight);
_


  parent reply	other threads:[~2012-06-11 23:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-09  0:50 [PATCH v3 1/9] string: introduce memweight Akinobu Mita
2012-06-09  0:50 ` [PATCH v3 7/9] ext2: use memweight() Akinobu Mita
2012-06-12  9:14   ` Jan Kara
2012-06-09  0:50 ` [PATCH v3 8/9] ext3: " Akinobu Mita
2012-06-12  9:14   ` Jan Kara
2012-06-09  0:50 ` [PATCH v3 9/9] ext4: " Akinobu Mita
2012-06-11 23:17 ` Andrew Morton [this message]
2012-06-20 23:12 ` [PATCH v3 1/9] string: introduce memweight Tony Luck
2012-06-21  9:07   ` Akinobu Mita

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=20120611161725.84330925.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=adilger.kernel@dilger.ca \
    --cc=agk@redhat.com \
    --cc=akinobu.mita@gmail.com \
    --cc=al@alarsen.net \
    --cc=dm-devel@redhat.com \
    --cc=jack@suse.cz \
    --cc=jlbec@evilplan.org \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=mfasheh@suse.com \
    --cc=ocfs2-devel@oss.oracle.com \
    --cc=tytso@mit.edu \
    /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;
as well as URLs for NNTP newsgroup(s).