From: David Miller <davem@davemloft.net>
To: torvalds@linux-foundation.org
Cc: James.Bottomley@hansenpartnership.com, geert@linux-m68k.org,
linux-arch@vger.kernel.org
Subject: Re: Arch maintainers Ahoy!
Date: Wed, 23 May 2012 16:36:44 -0400 (EDT) [thread overview]
Message-ID: <20120523.163644.875474822428763332.davem@davemloft.net> (raw)
In-Reply-To: <CA+55aFy78h5z1fnW+TovTQ4wUBauUW4i7=Z583tbQVMhsWvTAQ@mail.gmail.com>
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Wed, 23 May 2012 11:46:54 -0700
> On Wed, May 23, 2012 at 11:35 AM, David Miller <davem@davemloft.net> wrote:
>>
>> FWIW, when I code this end case in assembler on sparc64 I just go for
>> a bunch of conditional moves, so I'll try to come up with something
>> similar to the above that gcc will emit reasonably.
>
> .. and yes, it's possible that the keep-it-simple-and-stupid code you
> posted first will actually generate better code if gcc can change it
> all to cmov's.
I toyed around with some of the ideas we discussed but gcc really
mishandled all the approaches I tried.
It seemed to, no matter what I did, want to reload the Mycroft
constants in the tail code even though it had them all readily
available in registers for the word-at-a-time loop body.
We, of course, can't just use the already calculated has_zero() mask
value to figure out has_zero_32() and has_zero_16(). This is because
carrying can cause 0x80 values to end up in the mask at the locations
adjacent to the real zero byte.
As discussed in the past and as implemented in fs/namei.c, on
little-endian it's trivial the mask out the uninteresting 0x80 bytes
with that:
mask = (mask - 1) & ~mask;
thing.
What I think we can do on big-endian is this:
1) In the loop, use the test:
(x + 0xfefefeff) & ~(x | 0x7f7f7f7f)
It's the same effective cost as the current test (on sparc
it would be ADD, OR, ANDNCC).
We make sure to calculate the "x | 0x7f7f7f7f" part into
a variable which is not clobbered by the rest of the test.
This is so we can reuse it in #2.
2) Once we find a word containing the zero byte, do a:
~(((x & 0x7f7f7f7f) + 0x7f7f7f7f) | x | 0x7f7f7f7f)
and that "x | 0x7f7f7f7f" part is already calculated and thus
can be cribbed the place we left it in #1 above.
And now we'll have exactly a 0x80 where there is a zero byte,
and no bleeding of 0x80 values into adjacent byte positions.
Once we have that we can just test that mask directly for the
zero byte location search code.
next prev parent reply other threads:[~2012-05-23 20:37 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-21 16:50 Arch maintainers Ahoy! (was Re: x86: faster strncpy_from_user()) Linus Torvalds
2012-05-23 5:46 ` Arch maintainers Ahoy! David Miller
2012-05-23 8:02 ` Geert Uytterhoeven
2012-05-23 9:40 ` James Bottomley
2012-05-23 15:15 ` Linus Torvalds
2012-05-23 17:21 ` David Miller
2012-05-23 17:32 ` Linus Torvalds
2012-05-23 18:16 ` David Miller
2012-05-23 18:27 ` Linus Torvalds
2012-05-23 18:35 ` David Miller
2012-05-23 18:44 ` Linus Torvalds
2012-05-23 18:46 ` Linus Torvalds
2012-05-23 20:36 ` David Miller [this message]
2012-05-23 21:01 ` Linus Torvalds
2012-05-24 2:11 ` David Miller
2012-05-24 5:25 ` Paul Mackerras
2012-05-24 5:56 ` David Miller
2012-05-24 9:40 ` David Howells
2012-05-24 15:53 ` Linus Torvalds
2012-06-13 11:08 ` Michael Cree
2012-06-13 14:51 ` Linus Torvalds
2012-05-24 16:45 ` David Howells
2012-05-24 16:56 ` Linus Torvalds
2012-05-24 17:16 ` David Howells
2012-05-23 17:19 ` David Miller
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=20120523.163644.875474822428763332.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=James.Bottomley@hansenpartnership.com \
--cc=geert@linux-m68k.org \
--cc=linux-arch@vger.kernel.org \
--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).