Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2004-07-10 05:52:51


> I've looked at the generated (optimized) assembly of main, using both
> foo1 and foo2. The assembly is identical in both cases. No doubt I
> could come up with examples where the assembly is different. But I'm
> having more trouble coming up with a situation where the performance
> difference is enough that I'd want to start lacing my generic code with
> call_traits for this purpose. However if you have such examples, I'm
> interested in pursuing this further.

It started out as an optimisation, but even where the assembly is different,
current processors are so fast at loads and stores, that the difference
between pass by reference (involving one extra load in some cases) and pass
by value is minimal. Except possibly in one case: if the value passed is
used inside a loop, then passing by value may suppress the "aliasing issue"
that "restrict" also addresses:

template <class T>
void fill_n(T* data, int len, call_traits<T>::call_type val)
{
while(len)
{
data[len--] == val; // if val is a reference it gets re-loaded every time
rather than cached in a register
}
}

John.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk