lkml.org 
[lkml]   [2008]   [Apr]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 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.


\
 
 \ /
  Last update: 2008-04-30 20:23    [W:0.867 / U:0.372 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site