This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: swap (a, b) suggestion
>>>>> "RH" == Richard Henderson <rth@cygnus.com> writes:
RH> On Sat, Jan 03, 1998 at 06:11:23PM -0500, Eric Buddington wrote:
>> For integer values, the following works, and is significantly
>> faster:
>>
>> template <class T>
>> inline void swap(T& a, T& b) {
>> a ^= b;
>> b ^= a;
>> a ^= b;
>> }
RH> If it is faster at all I'll warrent it is only so for depressingly
RH> register starved machines.
Perhaps the optimization should be made in a different place -- Make
the optimizer recognize the sequence "tmp = a; a = b; b = tmp" and do
it the most efficient way. The instruction combiner or the peephole
optimizer could be made to catch this.
Benny