From: David Newall <davidn@davidnewall.com>
To: Soumyadip Das Mahapatra <dip_kernel@yahoo.co.in>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Improved Swapping Method In sort.c
Date: Thu, 01 May 2008 04:16:47 +0930 [thread overview]
Message-ID: <4818BE97.7030307@davidnewall.com> (raw)
In-Reply-To: <988568.21908.qm@web94102.mail.in2.yahoo.com>
Soumyadip Das Mahapatra wrote:
> static void u32_swap(void *a, void *b)
> {
> *(u32 *)b ^= *(u32 *)a ^= *(u32 *)b ^= *(u32 *)a;
> }
>
That was posted to comp.lang.c 20 years ago or more. It's not something
that the compiler is likely to be able to optimize (unlike the normal
swap, using a temporary variable.)
Another cute, temp-free swap, from the same era, is: b += a -= b; a = b - a.
next prev parent reply other threads:[~2008-04-30 18:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-30 17:09 Improved Swapping Method In sort.c Soumyadip Das Mahapatra
2008-04-30 17:30 ` Jan Engelhardt
2008-04-30 17:33 ` Jan Engelhardt
2008-04-30 18:03 ` Sami Farin
2008-04-30 18:46 ` David Newall [this message]
2008-05-02 5:05 ` H. Peter Anvin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4818BE97.7030307@davidnewall.com \
--to=davidn@davidnewall.com \
--cc=dip_kernel@yahoo.co.in \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox