mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: Andreas Gruenbacher <agruen@suse.de>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
	mpm@selenic.com, Andrew Morton <akpm@osdl.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/8] lib/sort: Heapsort implementation of sort()
Date: Thu, 03 Feb 2005 15:19:31 -0800	[thread overview]
Message-ID: <7v1xbxkz98.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <1107342847.21040.18.camel@winden.suse.de> (Andreas Gruenbacher's message of "Wed, 02 Feb 2005 12:14:07 +0100")

>>>>> "AG" == Andreas Gruenbacher <agruen@suse.de> writes:

AG> On Wed, 2005-02-02 at 11:50, Herbert Xu wrote:
>> What if a/b aren't aligned?

AG> If people sort arrays that are unaligned even though the
AG> element size is a multiple of sizeof(long) (or sizeof(u32)
AG> as Matt proposes), they are just begging for bad
AG> performance.

If the user of your sort routine is dealing with an array of
this shape:

    struct { char e[8]; } a[]

the alignment for the normal access (e.g. a[ix].e[iy]) would not
matter and they are not begging for bad performance, are they?
It is only this swap routine, which is internal to the
implementation of sort, that is begging for it, methinks.  

Is unaligned access inside of the kernel get fixed up on all
architectures?  If not, this would not just be a performance
issue but becomes a correctness issue.

How about something like this to be a bit more defensive:

static inline void swap(void *a, void *b, int size)
{
       if (((unsigned long)a | (unsigned long)b | size) % sizeof(long)) {
	       char t;
	       do {
		       t = *(char *)a;
		       *(char *)a++ = *(char *)b;
		       *(char *)b++ = t;
	       } while (--size > 0);
       } else {
	       long t;
	       do {
		       t = *(long *)a;
		       *(long *)a = *(long *)b;
		       *(long *)b = t;
		       size -= sizeof(long);
	       } while (size > sizeof(long));
       }
}


  reply	other threads:[~2005-02-03 23:23 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-31  7:34 [PATCH 0/8] lib/sort: Add generic sort to lib/ Matt Mackall
2005-01-31  7:34 ` [PATCH 1/8] lib/sort: Heapsort implementation of sort() Matt Mackall
2005-01-31  7:34   ` [PATCH 2/8] lib/sort: Replace qsort in XFS Matt Mackall
2005-01-31  7:35     ` [PATCH 3/8] lib/sort: Replace qsort in NFS ACL code Matt Mackall
2005-01-31  7:35       ` [PATCH 4/8] lib/sort: Kill qsort() Matt Mackall
2005-01-31  7:35         ` [PATCH 5/8] lib/sort: Replace open-coded O(pids**2) bubblesort in cpusets Matt Mackall
2005-01-31  7:35           ` [PATCH 6/8] lib/sort: Replace insertion sort in exception tables Matt Mackall
2005-01-31  7:35             ` [PATCH 7/8] lib/sort: Replace insertion sort in IA64 " Matt Mackall
2005-01-31  7:35               ` [PATCH 8/8] lib/sort: Use generic sort on x86_64 Matt Mackall
2005-01-31 12:02           ` [PATCH 5/8] lib/sort: Replace open-coded O(pids**2) bubblesort in cpusets Paul Jackson
2005-01-31 17:16   ` [PATCH 1/8] lib/sort: Heapsort implementation of sort() Andreas Gruenbacher
2005-01-31 17:30     ` Paulo Marques
2005-02-01 17:54       ` Andreas Gruenbacher
2005-02-01 18:11         ` linux-os
2005-02-01 19:04           ` linux-os
2005-02-01 19:47           ` Andreas Gruenbacher
2005-01-31 19:30     ` Matt Mackall
2005-02-01 17:50       ` Andreas Gruenbacher
2005-02-02  1:00         ` Horst von Brand
2005-02-02 10:50     ` Herbert Xu
2005-02-02 11:14       ` Andreas Gruenbacher
2005-02-03 23:19         ` Junio C Hamano [this message]
2005-02-01  2:10   ` Horst von Brand
2005-02-01 22:29   ` [PATCH 2/8] lib/sort: Replace qsort in XFS Chris Wedgwood
2005-02-01 22:22     ` Randy.Dunlap
2005-02-02  4:31       ` Zan Lynx
2005-02-02 10:48         ` Herbert Xu
2005-02-01 22:48     ` Matt Mackall
2005-02-27 13:17   ` [PATCH 1/8] lib/sort: Heapsort implementation of sort() Andreas Gruenbacher
2005-02-27 21:25     ` Matt Mackall
2005-02-27 21:53       ` Andreas Gruenbacher
2005-02-27 22:10         ` Andreas Gruenbacher
2005-03-01 13:23       ` Andreas Gruenbacher
2005-03-01 19:06       ` Christophe Saout
2005-03-01 20:12         ` Matt Mackall
2005-03-01 21:47           ` Andrew Morton
2005-01-31 11:52 Alexey Dobriyan
2005-01-31 16:53 ` Matt Mackall

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=7v1xbxkz98.fsf@assigned-by-dhcp.cox.net \
    --to=junkio@cox.net \
    --cc=agruen@suse.de \
    --cc=akpm@osdl.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpm@selenic.com \
    /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

all inboxes | Powered by JetHome®