Messages in this thread | | | Date | Wed, 30 Apr 2008 11:19:31 -0700 | From | "Ray Lee" <> | Subject | Re: Improved Swaping Method In sort.c |
| |
On Wed, Apr 30, 2008 at 11:09 AM, Soumyadip Das Mahapatra <dip_kernel@yahoo.co.in> 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.
| |