On Sat, Oct 27, 2007 at 03:06:21 +1000, skaller wrote: > err .. what about the heap??
The heap are objects for which the addresses were taken. So they can be shared. But I haven't yet seen that the optimization we discuss is being applied to the object accessed though the pointer (see my reply to Michael Matz). Maybe this is just a coincidence. I was beaten already for repeating myself, but please let me do that once more :). First, I have a strong believe (though I didn't test it) that if (C) val->mem; runs faster than mem->reg; if (C) val->reg; reg->mem; (short) jump will cost less then unconditional load/store when they are not needed (especially the store). BTW, it would be interesting to measure if short jumps are as bad as long jumps, i.e. whether CPU pipeline is flushed when jump target is already in it. Second, in situation like loop if (C) val->mem; i.e. when there are lots of conditional stores, only one final store matters. And current optimization employs this: mem->reg; loop if (C) val->reg; reg->mem; // One final store. But at the cost of additional register this final store can be made conditional (there are cases when even that register is not needed, but that requires thorough analysis of val's possible values, i.e. reg could be initialized to some "invalid" value and then checked for it). Registers are a valuable resource, yes. But so is the correct program result. Since GCC is correct wrt all standards, next comes its usability in not-yet-standardized domains. > And what do you do if you do not KNOW what the storage class is, > which is the case 99.99% of the time in C++ member functions? I'm not quite sure what you mean here. If extern vs static---that's of no concern. What matters is whether the object can possibly be accessed from another thread, and this has nothing specific to C++. -- Tomash Brechko