From: Michael Cree <mcree@orcon.net.nz>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
git@vger.kernel.org, Nicolas Pitre <nico@fluxnic.net>
Subject: Re: [PATCH maint-1.6.5 v2] block-sha1: avoid pointer conversion that violates alignment constraints
Date: Mon, 16 Jul 2012 21:53:53 +1200 [thread overview]
Message-ID: <5003E4B1.605@orcon.net.nz> (raw)
In-Reply-To: <20120715212731.GG1986@burratino>
On 16/07/12 09:27, Jonathan Nieder wrote:
> Michael Cree wrote:
>
>> On 15/07/2012, at 8:50 AM, Jonathan Nieder wrote:
>
>>> gcc takes full advantage by converting the get_be32
>>> calls back to a load and bswap and producing a whole bunch of
>>> unaligned access traps.
>>
>> Alpha does not have a bswap (or similar) instruction.
> [...]
>> . If the pointer is unaligned
>> then two neighbouring aligned 32bit loads are required to ensure
>> that all four bytes are loaded. If the pointer is aligned then a
>> single 32bit load gets all the four bytes. Having never looked at
>> the generated assembler code, I nevertheless suspect that is the
>> guts of the optimisation --- the compiler can eliminate an access to
>> memory if it knows the pointer is aligned.
>
> How about:
>
> gcc takes full advantage by using a single 32-bit load,
> resulting in a whole bunch of unaligned access traps.
Yes, that's good.
I just checked the generated assembler and I am correct except that I
underestimated the number of memory accesses for the a priori known
unaligned data case. It is actually doing four long-word memory access,
i.e. a memory access for each individual byte despite that it only needs
to do a maximum of two, so the optimisation for the a priori known
aligned data saves three memory accesses, not just one. (And probably
also saves on a load-load replay trap on the EV6 and later CPUs, i.e., a
complete and very costly replay of the whole pipeline when the CPU
realises just in the nick of time that it has cocked up the
interrelationships between reordered load instructions.)
Cheers
Michael.
prev parent reply other threads:[~2012-07-16 9:54 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20120713233957.6928.87541.reportbug@electro.phys.waikato.ac.nz>
[not found] ` <20120714002950.GA3159@burratino>
[not found] ` <5000CBCA.8020607@orcon.net.nz>
[not found] ` <20120714021856.GA3062@burratino>
[not found] ` <50010B84.5030606@orcon.net.nz>
2012-07-14 7:59 ` [PATCH maint-1.6.5] block-sha1: avoid unaligned accesses on some big-endian systems Jonathan Nieder
2012-07-14 19:11 ` Linus Torvalds
2012-07-14 19:50 ` Jonathan Nieder
2012-07-14 19:55 ` Linus Torvalds
2012-07-14 20:50 ` [PATCH maint-1.6.5 v2] block-sha1: avoid pointer conversion that violates alignment constraints Jonathan Nieder
2012-07-14 20:56 ` Linus Torvalds
2012-07-14 21:57 ` [PATCH] block-sha1: put macro arguments in parentheses Jonathan Nieder
2012-07-15 20:58 ` [PATCH maint-1.6.5 v2] block-sha1: avoid pointer conversion that violates alignment constraints Michael Cree
2012-07-15 21:27 ` Jonathan Nieder
2012-07-16 9:53 ` Michael Cree [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=5003E4B1.605@orcon.net.nz \
--to=mcree@orcon.net.nz \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=nico@fluxnic.net \
--cc=torvalds@linux-foundation.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).