Re: While we're at it

Dean Anderson <[email protected]> Thu, 1 Apr 2010 15:37:44 -0400 (EDT)
Newsgroups gmane.network.djbdns
Message-ID <[email protected]>
Clue: How many bytes fit in a word?  The start of the array is probably
word-aligned.  A really good compiler might even figure out that it can
load the word in a register and test all at once.

		--Dean

On Wed, 31 Mar 2010, Colm MacCárthaigh wrote:

> On Wed, Mar 31, 2010 at 3:40 PM, Hugo Monteiro <[email protected]> wrote:
> > Why 4, and not more then? Is 4 the an average of something? Bare in mind
> > we're talking about strings and not only words.
> 
> I think it's essentially arbitrary. Originally I thought that some
> compilers might be intelligent enough to compress it into a neat
> word-wize test, but have found no evidence of this in machine code
> emitted by gcc or icc.
> 
> In a dynamic or semi-interpretted language (such as Java) it's
> possible to do run-time statistical profiling and change the balance
> between memory consumption Vs jumps based on observed average string
> length and memory availability. (at some point the amount of memory
> consumed by the unrolled code will cross a caching boundary and become
> a source of serious latency). But in statically compiled languages
> such as C, fewer such tricks are available - one could choose a value
> based on a more-widely measured average - but just picking 4 seems
> like an ok thing to do too - it hardly matters for the type of usage
> patterns DJB's daemons have.
> 
> Security and portability are more important goals than performance for
> str_len.c, so it doesn't avail of any of the modern tricks that are
> available (such as the SSE instruction set). Though I think any modern
> compiler would do a better job of unrolling than putting it explicitly
> in the code. Also, some compilers do allow you to feed them profiling
> hints, which they use to make decisions such as to what degree a loop
> should be unrolled.
> 
> 

-- 
Av8 Internet   Prepared to pay a premium for better service?
www.av8.net         faster, more reliable, better service
617 256 5494