Re: Improved Swaping Method In sort.c

From: Ray Lee
Date: Wed Apr 30 2008 - 14:19:43 EST


On Wed, Apr 30, 2008 at 11:09 AM, Soumyadip Das Mahapatra
<dip_kernel@xxxxxxxxxxx> wrote:
> Thanks Jan,
> Actually it should be
> static void u32_swap(void *a, void *b)
> {
> *(u32 *)b ^= *(u32 *)a;
> *(u32 *)a ^= *(u32 *)b;
> *(u32 *)b ^= *(u32 *)a;
> }
> But this code saves memory equaling two integers. What about that ?

The above prevents gcc from storing the intermediary in a register. So
you're trading fast register access for slow memory access.

Really, you shouldn't be prosing optimizations unless you do two
things: check the output of gcc (on at least one platform, but really
should be several), and include timings of before/after.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/