lkml.org 
[lkml]   [1998]   [Apr]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: faster strcpy()
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

\
 
 \ /
  Last update: 2005-03-22 13:42    [W:0.050 / U:0.760 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site