public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Yury <yury.norov@gmail.com>
Cc: klimov.linux@gmail.com, davem@davemloft.net,
	akpm@linux-foundation.org, hannes@stressinduktion.org,
	dborkman@redhat.com, laijs@cn.fujitsu.com,
	takahiro.akashi@linaro.org, valentinrothberg@gmail.com,
	linux@horizon.com, msalter@redhat.com, chris@chris-wilson.co.uk,
	tgraf@suug.ch, linux-kernel@vger.kernel.org,
	Yury Norov <y.norov@samsung.com>
Subject: Re: [PATCH v2 1/3] lib: find_*_bit reimplementation
Date: Thu, 05 Feb 2015 16:01:26 +0100	[thread overview]
Message-ID: <87pp9os8qh.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <54D2A2B9.1020206@gmail.com> (Yury's message of "Thu, 05 Feb 2015 01:52:41 +0300")

On Wed, Feb 04 2015, Yury <yury.norov@gmail.com> wrote:

> On 02.02.2015 13:43, Rasmus Villemoes wrote:
>>> @@ -23,86 +50,22 @@
>>>  unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
>>>  			    unsigned long offset)
>>>  {
>>> -	const unsigned long *p = addr + BITOP_WORD(offset);
>>> -	unsigned long result = offset & ~(BITS_PER_LONG-1);
>>> -	unsigned long tmp;
>>> -
>>>  	if (offset >= size)
>>>  		return size;
>> Why can't this ...
>>
>>
>>> -	size -= result;
>>> -	offset %= BITS_PER_LONG;
>>> -	if (offset) {
>>> -		tmp = *(p++);
>>> -		tmp &= (~0UL << offset);
>>> -		if (size < BITS_PER_LONG)
>>> -			goto found_first;
>>> -		if (tmp)
>>> -			goto found_middle;
>>> -		size -= BITS_PER_LONG;
>>> -		result += BITS_PER_LONG;
>>> -	}
>>> -	while (size & ~(BITS_PER_LONG-1)) {
>>> -		if ((tmp = *(p++)))
>>> -			goto found_middle;
>>> -		result += BITS_PER_LONG;
>>> -		size -= BITS_PER_LONG;
>>> -	}
>>> -	if (!size)
>>> -		return result;
>>> -	tmp = *p;
>>>  
>>> -found_first:
>>> -	tmp &= (~0UL >> (BITS_PER_LONG - size));
>>> -	if (tmp == 0UL)		/* Are any bits set? */
>>> -		return result + size;	/* Nope. */
>>> -found_middle:
>>> -	return result + __ffs(tmp);
>>> +	return min(_find_next_bit(addr, size, offset, 1), size);
>> ... and this be part of _find_next_bit? Can find_next_bit not be simply
>> 'return _find_next_bit(addr, size, offset, 1);', and similarly for
>> find_next_zero_bit? Btw., passing true and false for the boolean
>> parameter may be a little clearer.
> I moved size checkers out of '_find_next_bit' to let user call it from his code
> if he knows for sure that size/offset pair is valid. This may help save a couple
> of clocks. I think, I'll walk over the code to find how many such places we have.
> If not too much / not in critical paths, checks may be moved into the function.

But _find_next_bit is static, so outsiders can't call it... The branches
are easily predicted and hence almost free, so I think it's better to do
the code deduplication and move the bounds checking inside
_find_next_bit, so that find_next_bit is literally just 'return
_find_next_bit(addr, size, offset, 0ul);' and find_next_zero_bit is
'return _find_next_bit(addr, size, offset, ~0ul);'.

Rasmus

  reply	other threads:[~2015-02-05 15:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-31 20:58 [PATCH v2 1/3] lib: find_*_bit reimplementation yury.norov
2015-01-31 20:58 ` [PATCH v2 2/3] lib: move find_last_bit to lib/find_next_bit.c yury.norov
2015-01-31 20:58 ` [PATCH v2 3/3] lib: rename lib/find_next_bit.c to lib/find_bit.c yury.norov
2015-02-02 11:09   ` Rasmus Villemoes
2015-02-02  3:17 ` [PATCH v2 1/3] lib: find_*_bit reimplementation George Spelvin
2015-02-04 23:07   ` Yury
2015-02-02 10:43 ` Rasmus Villemoes
2015-02-02 11:47   ` George Spelvin
2015-02-02 12:56     ` Rasmus Villemoes
2015-02-04 23:45       ` Yury
2015-02-05 14:51         ` Rasmus Villemoes
2015-02-04 22:52   ` Yury
2015-02-05 15:01     ` Rasmus Villemoes [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-02-05 23:07 Alexey Klimov

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=87pp9os8qh.fsf@rasmusvillemoes.dk \
    --to=linux@rasmusvillemoes.dk \
    --cc=akpm@linux-foundation.org \
    --cc=chris@chris-wilson.co.uk \
    --cc=davem@davemloft.net \
    --cc=dborkman@redhat.com \
    --cc=hannes@stressinduktion.org \
    --cc=klimov.linux@gmail.com \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@horizon.com \
    --cc=msalter@redhat.com \
    --cc=takahiro.akashi@linaro.org \
    --cc=tgraf@suug.ch \
    --cc=valentinrothberg@gmail.com \
    --cc=y.norov@samsung.com \
    --cc=yury.norov@gmail.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