mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: faster strcpy()
       [not found] <E0ySfV5-00058I-00@imladris.demon.co.uk>
@ 1998-04-24 10:26 ` Philip Blundell
  1998-04-25 22:44   ` Alexander Kjeldaas
  0 siblings, 1 reply; 3+ messages in thread
From: Philip Blundell @ 1998-04-24 10:26 UTC (permalink / raw)
  To: David Woodhouse; +Cc: Meelis Roos, linux-kernel

>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

p.



-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: faster strcpy()
  1998-04-24 10:26 ` faster strcpy() Philip Blundell
@ 1998-04-25 22:44   ` Alexander Kjeldaas
       [not found]     ` <19980426013108.48608@lucifer.guardian.no>
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Kjeldaas @ 1998-04-25 22:44 UTC (permalink / raw)
  To: Philip Blundell, David Woodhouse; +Cc: Meelis Roos, linux-kernel

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: faster strcpy()
       [not found]     ` <19980426013108.48608@lucifer.guardian.no>
@ 1998-04-26 15:17       ` Pavel Machek
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Machek @ 1998-04-26 15:17 UTC (permalink / raw)
  To: Alexander Kjeldaas
  Cc: Philip Blundell, David Woodhouse, Meelis Roos, linux-kernel

Hi!

> > 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)
> > 
> 
> Hmm.. two things obviously escaped me:
> 
> 1) The above fails horribly and detects 0x80 as a null.

It does not matter too much: you usually want 

word_has_probably_nullbyte(), since you usually want to know where the
nullbyte is and copy rest byte-by-byte.

								Pavel
-- 
I'm really pavel@atrey.karlin.mff.cuni.cz. 	   Pavel
Look at http://atrey.karlin.mff.cuni.cz/~pavel/ ;-).

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1998-04-26 17:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <E0ySfV5-00058I-00@imladris.demon.co.uk>
1998-04-24 10:26 ` faster strcpy() Philip Blundell
1998-04-25 22:44   ` Alexander Kjeldaas
     [not found]     ` <19980426013108.48608@lucifer.guardian.no>
1998-04-26 15:17       ` Pavel Machek

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®