linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: mateusznosek0@gmail.com
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	viro@zeniv.linux.org.uk
Subject: Re: [RFC PATCH] fs: micro-optimization remove branches by adjusting flag values
Date: Mon, 14 Sep 2020 19:06:29 +0100	[thread overview]
Message-ID: <20200914180629.GT6583@casper.infradead.org> (raw)
In-Reply-To: <20200914174338.9808-1-mateusznosek0@gmail.com>

On Mon, Sep 14, 2020 at 07:43:38PM +0200, mateusznosek0@gmail.com wrote:
> From: Mateusz Nosek <mateusznosek0@gmail.com>
> 
> When flags A and B have equal values than the following code
> 
> if(flags1 & A)
> 	flags2 |= B;
> 
> is equivalent to
> 
> flags2 |= (flags1 & A);
> 
> The latter code should generate less instructions and be faster as one
> branch is omitted in it.

[citation needed]

$ cat test.c 
int a(int x)
{
	int y = 0;

	if (x & 1)
		y |= 1;
	if (x & 2)
		y |= 2;

	return y;
}

$ objdump -d test.o
0000000000000000 <a>:
   0:   89 f8                   mov    %edi,%eax
   2:   83 e0 03                and    $0x3,%eax
   5:   c3                      retq   

Please stop submitting uglifying patches without checking they actually
improve anything.  GCC is smarter than you think it is.

  reply	other threads:[~2020-09-14 18:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-14 17:43 [RFC PATCH] fs: micro-optimization remove branches by adjusting flag values mateusznosek0
2020-09-14 18:06 ` Matthew Wilcox [this message]
2020-09-15  0:38   ` Al Viro
2020-09-15  0:31 ` Al Viro

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=20200914180629.GT6583@casper.infradead.org \
    --to=willy@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mateusznosek0@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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).