From: Alexander Kjeldaas <astor@guardian.no>
To: Philip Blundell <pb@nexus.co.uk>,
David Woodhouse <Dave@imladris.demon.co.uk>
Cc: Meelis Roos <mroos@tartu.cyber.ee>, linux-kernel@vger.rutgers.edu
Subject: Re: faster strcpy()
Date: Sun, 26 Apr 1998 00:44:28 +0200 [thread overview]
Message-ID: <19980426004428.17045@lucifer.guardian.no> (raw)
In-Reply-To: <E0ySfgI-0006zV-00@spring.nexus.co.uk>; from Philip Blundell on Fri, Apr 24, 1998 at 11:26:09AM +0100
On Fri, Apr 24, 1998 at 11:26:09AM +0100, Philip Blundell wrote:
> >It's something like subtracting 0x01010101 from the dword and oring with
> >0x80808080 to detect the carry, but that's not quite it. Perhaps you do
>
> /* The following magic check was designed by A. Mycroft. It yields a */
> /* nonzero value if the argument w has a zero byte in it somewhere. The */
> /* messy constants have been unfolded a bit in this code so that they */
> /* get preloaded into registers before relevant loops. */
>
> #ifdef _copywords
> # define ONES_WORD 0x01010101
> # define EIGHTS_WORD (ones_word << 7)
> # define nullbyte_prologue_() \
> int ones_word = ONES_WORD;
> # define word_has_nullbyte(w) (((w) - ones_word) & ~(w) & EIGHTS_WORD)
> #endif
>
I'm not sure why Mycroft used '& ~(w)' in the above. Unless something
obvious escapes me, you can optimize the above down to 3
instructions. Both codepaths have a dependency chain of 3
instructions.
#define word_has_nullbyte(w) ((((w) - 0x01010101) ^ (w)) & 0x80808080)
astor
--
Alexander Kjeldaas, Guardian Networks AS, Trondheim, Norway
http://www.guardian.no/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
next prev parent reply other threads:[~1998-04-25 22:25 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E0ySfV5-00058I-00@imladris.demon.co.uk>
1998-04-24 10:26 ` Philip Blundell
1998-04-25 22:44 ` Alexander Kjeldaas [this message]
[not found] ` <19980426013108.48608@lucifer.guardian.no>
1998-04-26 15:17 ` Pavel Machek
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=19980426004428.17045@lucifer.guardian.no \
--to=astor@guardian.no \
--cc=Dave@imladris.demon.co.uk \
--cc=linux-kernel@vger.rutgers.edu \
--cc=mroos@tartu.cyber.ee \
--cc=pb@nexus.co.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®