Re: While we're at it
Dean Anderson <[email protected]> Wed, 7 Apr 2010 16:16:39 -0400 (EDT)
| Newsgroups | gmane.network.djbdns |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 5 Apr 2010, Colm MacCárthaigh wrote: > The very next paragraph explicitly mentions pipelining, so I don't > agree with you that it has been omitted. Ok. > I certainly don't call out that the L2 cache would contain the whole > word, but this seems like an odd thing to call out. A register would > contain the whole word, never mind any of the caches. The L1 and L2 > caches are both several orders of magnitude larger than a word. In total, the L1 & L2 cache are of course larger. And a register _could_ contain a word, but doesn't do so in this case. In this case, it contains a byte, which is compared to 0. It doesn't make the comparison 4 times on the same byte and there are no unnecessary comparisons, which is sort of implied in your description. But a complete word is brought into L2 cache to read one byte. When aligned the next 3 tests access L2 cache at high speed and are pipelined. A conditional jump to do one test at a time would slow it down because the pipeline is flushed when the branch is taken. > Loop-unrolling is a very separate thing from caching optimisation,and > is usually in opposition to it. Note that unrolled instructions > require storage too, and so compete for cache line space. Agree. Some middle ground is appropriate: not too much unrolled. But zero unrolling isn't ideal in many cases. > > Show me a memory allocator that gives back unaligned memory, and I'll > > show you how to fix that. Most of the time, we can be expect the memory > > to be word-aligned. In the rare case it isn't, it won't matter too much. > > The issue is not that an allocator may return unaligned memory, but > that you may wish to count the length of a string that does not start > at the alignment boundary. For one trivial, but realistic, example; > > char * string = "Hello World"; // probably a word-aligned pointer > int firstwordlength = strlen(string) - strlen(strtok(string, " ")); > // second call is unaligned Sure. But one wants code that is fast in the most common case, and works in the less common case. -- Av8 Internet Prepared to pay a premium for better service? www.av8.net faster, more reliable, better service 617 256 5494