From: Jan Kara <jack@suse.cz>
To: Zhan Jianyu <nasa4836@gmail.com>
Cc: Jan Kara <jack@suse.cz>,
axboe@kernel.dk, hch@lst.de, viro@zeniv.linux.org.uk,
kmo@daterainc.com, namjae.jeon@samsung.com,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] blkdev: use an efficient way to check merge flags
Date: Thu, 3 Apr 2014 14:45:42 +0200 [thread overview]
Message-ID: <20140403124542.GA14107@quack.suse.cz> (raw)
In-Reply-To: <CAHz2CGWd70k+eSzcdMdAkjwpYZB1BQ8mKT3f2EfpMM2NsFtn-A@mail.gmail.com>
On Thu 03-04-14 16:00:44, Zhan Jianyu wrote:
> On Thu, Apr 3, 2014 at 2:13 AM, Jan Kara <jack@suse.cz> wrote:
> > OK, but have you checked the generated code is actually any better? This
> > is something I'd expect a compiler might be able to optimize anyway. And the
> > original code looks more readable to me.
>
> Hi, Jan,
>
> I've disassemble the code on my x86_64 box
> (it's inline though, I just look at its call site),
> and found that this patch DOES make it more efficient.
>
> Orig asm snippt with
> patch asm snippt
> ============ ================
>
> mov %edx,%ecx mov %rdx,%r9
> xor %r8d,%ecx xor %r8d,%r8d
> test $0x80,%cl and $0x380,%r9d
> jne 14c5 <blk_rq_merge_ok+0x15> test $0x380,%ecx
> and $0x3,%ch sete %r8b
> jne 14c5 <blk_rq_merge_ok+0x15> cmp %r8,%r9
>
> je 14b5 <blk_rq_merge_ok+0x15>
>
> This saves a branch.
>
> Furthermore, I found that gcc is smart enough to try to optimize the
> code, so if we do
> like this, it will generate the most optimal and smallest code :
>
>
> static inline bool blk_check_merge_flags(unsigned int flags1,
> ¦unsigned int flags2)
> {
> return ((flags1 ^ flags2) &
> (REQ_DISCARD | REQ_SECURE | REQ_WRITE_SAME))
> == 0;
> }
>
> this gives out :
>
> mov %edx,%r8d
> xor %ecx,%r8d
> and $0x380,%r8d
> jne 14a5 <blk_rq_merge_ok+0x15>
>
> But yes, it compromises readibility.
OK, I'd expect gcc is more clever ;). Thanks for the comparison. Anyway
if that function is performance sensitive, we can use your optimization.
Just add a comment there that we want to check whether the three flags are
the same in both flags and that checking your way generates better code.
Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
next prev parent reply other threads:[~2014-04-03 12:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-02 15:19 Jianyu Zhan
2014-04-02 18:13 ` Jan Kara
2014-04-03 8:00 ` Zhan Jianyu
2014-04-03 12:45 ` Jan Kara [this message]
2014-04-03 13:37 Jianyu Zhan
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=20140403124542.GA14107@quack.suse.cz \
--to=jack@suse.cz \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=kmo@daterainc.com \
--cc=linux-kernel@vger.kernel.org \
--cc=namjae.jeon@samsung.com \
--cc=nasa4836@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
all inboxes | Powered by JetHome®