[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <201903140941.x2E9ffkx024340@sdf.org>
Date: Thu, 14 Mar 2019 09:41:41 GMT
From: George Spelvin <lkml@....org>
To: andriy.shevchenko@...ux.intel.com, lkml@....org
Cc: akpm@...ux-foundation.org, daniel.wagner@...mens.com,
dchinner@...hat.com, don.mullis@...il.com, geert@...ux-m68k.org,
linux-kernel@...r.kernel.org, linux@...musvillemoes.dk,
st5pub@...dex.ru
Subject: Re: [PATCH 4/5] lib/list_sort: Simplify and remove MAX_LIST_LENGTH_BITS
On Thu, 14 Mar 2019 at 11:10:41 +0200, Andy Shevchenko wrote:
> On Tue, Mar 05, 2019 at 03:06:44AM +0000, George Spelvin wrote:
>> + /* Do merges corresponding to set lsbits in count */
>
>> + for (bit = 1; count & bit; bit <<= 1) {
>> + cur = merge(priv, (cmp_func)cmp, pending, cur);
>> + pending = pending->prev; /* Untouched by merge() */
>> }
>
> Wouldn't be it the same to
>
> bit = ffz(count);
> while (bit--) {
> ...
> }
> ?
>
> Though I dunno which one is generating better code.
Yes, it's the same. But count is an incrementing counter, so the
pattern of return values from ffz() is 01020103010201040102010301020105...,
which has mean value 1/2 + 1/4 + 1/8 + 1/16 +... = 1.
So spending one instruction on ffz() to save one instruction per loop
iteration is an even trade, and if the processor doesn't have an ffz()
instruction, it's a loss.
There's a third possible implementation:
>> + for (bit = count; bit & 1; bit >>= 1) {
...which works fine, too. (It even saves a few bytes of code, so I
might switch to it.) I used the form I did because my test code
verified that the length of the lists being merged equalled "bit".
The other forms don't have that property.
Thank you for looking at the code!
Powered by blists - more mailing lists