[algogeeks] Re: strlen's algorithm

2006-02-21 Thread wade
can you explain that why the test you mentioned works? Consider ax+0xff changes the 0x100 bit iff the low-order byte of ax is not zero. ~ax always changes the 0x100 bit. (~ax^(ax+0xff)) 0x100 is zero iff both ~ax and ax+0xff have the same thing at the 0x100 position. You can extend

[algogeeks] Re: strlen's algorithm

2006-02-20 Thread Gene
This is highly optimized code that in the normal case loads 4 bytes at a time, checks if any of the 4 is z a null (0) and handles accordingly. If the string doesn't start on a 4-byte boundary, the str_misaligned counts 1, 2, or 3 characters until a null or alignment boundary is found. The