mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yan-Jie Wang <yanjiewtw@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] lib/list_sort: reduce if-statements
Date: Wed, 29 Mar 2023 09:02:35 +0800	[thread overview]
Message-ID: <df16fdf4-bb0f-ee58-0c7a-4b3d5ee98959@gmail.com> (raw)
In-Reply-To: <20230325123216.226120-1-yanjiewtw@gmail.com>

On Sat, Mar 25, 2023 at 8:32 PM Yan-Jie Wang <yanjiewtw@gmail.com> wrote:
> 
> Reduce if-statements in merge and merge_final functions by using 
> indirect pointers and bitwise operations.
> 
> This will make the code more elegant and reduce the number of branch
>  instructions in compiled code.
> 
> Signed-off-by: Yan-Jie Wang <yanjiewtw@gmail.com> ---

After performing some tests, I found that the merge algorithm I proposed
in this patch is not faster than the original one.

The number of branch instructions executed per loop is still the same
(two branch instructions per loop) since the compiler will generate a
branch instruction for `node = cmp(priv, a, b) <= 0 ? &a : &b;`.

In addition, there are more memory access in my proposed one because the
use of the indirect pointer, `node`, forces the compiler to put the
local variables, `a` and `b`, in memory. This will slow down the
performance.

This is the result of the compiled assembly:
   https://godbolt.org/z/vqorfz967

The test I wrote to evaluate the performance:
   https://github.com/yanjiew1/linux23q1-listsort_merge

I would like to thank Ching-Chun (Jim) Huang for providing advice for
this patch.


Yan-Jie Wang

      reply	other threads:[~2023-03-29  1:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-25  9:16 [PATCH] " Yan-Jie Wang
2023-03-25 12:18 ` [PATCH v2] " Yan-Jie Wang
2023-03-25 12:32 ` [PATCH v3] " Yan-Jie Wang
2023-03-29  1:02   ` Yan-Jie Wang [this message]

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=df16fdf4-bb0f-ee58-0c7a-4b3d5ee98959@gmail.com \
    --to=yanjiewtw@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®