|
From: Albert C. <al...@us...> - 2005-01-24 04:41:08
|
On Sun, 2005-01-23 at 19:52 -0800, Howard Chu wrote: > Albert Cahalan wrote: > > >if(foo) foo=0; // foo was uninitialized > > > >This code is rather odd I admit, but it is has perfectly > >well-defined behavior. It initializes foo to 0, skipping > >the store if foo is already 0. > > > Doesn't seem like it's worth spending any time to fix this. Better to > fix the source code, it's just silly. Always faster to just store the > value than to test/branch. It's not always faster. Typically, memory access is a bottleneck. Not all the world has branch penalties like a Pentium 4. Suppose that foo is on a cache line that was already fetched for loads, so that isn't a complicating concern. The cost of doing the write will be: 1. cache line invalidates on other CPUs (and future reloads) 2. slowness in other code, as the write-out occupies the bus That all said, I ditched the code for excessive obscurity. (it IS in a hot path though, so I ought to benchmark) |