From: Sergei Shtylyov <sshtylyov@ru.mvista.com>
To: Jeff Garzik <jgarzik@pobox.com>
Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org,
alan@lxorguk.ukuu.org.uk
Subject: Re: [PATCH 2/2 resend] libata-sff: avoid byte swapping in ata_sff_data_xfer()
Date: Sun, 15 Feb 2009 23:09:22 +0300 [thread overview]
Message-ID: <49987672.2050102@ru.mvista.com> (raw)
In-Reply-To: <4998717A.2090507@pobox.com>
Jeff Garzik wrote:
>> Handling of the trailing byte in ata_sff_data_xfer() is suboptimal
>> bacause:
>> - it always initializes the padding buffer to 0 which is not really
>> needed in
>> both the read and write cases;
>> - it has to use memcpy() to transfer a single byte from/to the padding
>> buffer;
> Have you looked at the assembly, before deciding it is suboptiomal?
I'm estimating the code itself, not what the compiler can do to fix it. :-)
> gcc optimizes tiny arrays and structures quite well, and is well capable
> of seeing one path where the initialization is clobbered without a
> single read, and another code path where it is used.
The initialier just shouldn't have been there in the first place,
clobbered or not. And let's looks at what gcc gave me:
.L504:
.loc 1 727 0
testb $1, %bl #, buflen
jne .L511 #,
[...]
.L511:
.LBB635:
.loc 1 731 0
movl 8(%ebp), %eax # rw,
.loc 1 729 0
leal (%esi,%ebx), %ebx #, tmp72
.LVL440:
.loc 1 728 0
.LBB635:
.loc 1 731 0
movl 8(%ebp), %eax # rw,
.loc 1 729 0
leal (%esi,%ebx), %ebx #, tmp72
.LVL440:
.loc 1 728 0
movw $0, -14(%ebp) #, align_buf
.loc 1 731 0
testl %eax, %eax #
jne .L507 #,
.loc 1 732 0
movl -20(%ebp), %eax # data_addr, data_addr
call ioread16 #
movw %ax, -14(%ebp) # D.29224, align_buf
.LBB629:
.LBB630:
.loc 4 60 0
movzbl -14(%ebp), %eax #, tmp73
movb %al, -1(%ebx) # tmp73,
.L509:
.LBE630:
.LBE629:
.loc 1 738 0
addl $1, %edi #, words
jmp .L505 #
.L507:
.LBB631:
.LBB632:
.loc 4 60 0
movzbl -1(%ebx), %eax #, tmp74
.LBE632:
.LBE631:
.loc 1 736 0
movzwl -14(%ebp), %eax # align_buf, align_buf
call iowrite16 #
jmp .L509 #
As you can see, it happily assigned 0 to align_buf[0] at .LVL440,
regardless of the value of 'rw'.
> As for memcpy, for small and/or constant values that is quite often a
> compiler builtin. It is rarely useful, these days, to convert a memcpy() to a hand-rolled
version of same.
Here memcpy() just shouldn't have appeared in the first place. But indeed,
gcc did optimize it away.
> Jeff
MBR, Sergei
next prev parent reply other threads:[~2009-02-15 20:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-15 19:30 [PATCH 2/2 resend] libata-sff: avoid byte swapping in ata_sff_data_xfer() Sergei Shtylyov
2009-02-15 19:48 ` Jeff Garzik
2009-02-15 20:09 ` Sergei Shtylyov [this message]
2009-02-17 18:07 ` Sergei Shtylyov
2009-04-07 9:15 ` Sergei Shtylyov
2009-06-01 19:31 ` Sergei Shtylyov
2009-06-11 18:19 ` Jeff Garzik
2009-06-11 18:28 ` Sergei Shtylyov
2009-04-08 6:33 ` Jeff Garzik
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=49987672.2050102@ru.mvista.com \
--to=sshtylyov@ru.mvista.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=jgarzik@pobox.com \
--cc=linux-ide@vger.kernel.org \
--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;
as well as URLs for NNTP newsgroup(s).