All of lore.kernel.org
 help / color / mirror / Atom feed
From: akpm@linux-foundation.org
To: daniel.wagner@bmw-carit.de, linux@rasmusvillemoes.dk,
	mm-commits@vger.kernel.org
Subject: + lib-sort-add-64-bit-swap-function-v2-fix.patch added to -mm tree
Date: Tue, 19 May 2015 16:17:32 -0700	[thread overview]
Message-ID: <555bc48c.oux4O2dPVZWbNY0F%akpm@linux-foundation.org> (raw)


The patch titled
     Subject: lib/sort: Move the alignment check into a function
has been added to the -mm tree.  Its filename is
     lib-sort-add-64-bit-swap-function-v2-fix.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/lib-sort-add-64-bit-swap-function-v2-fix.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/lib-sort-add-64-bit-swap-function-v2-fix.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Daniel Wagner <daniel.wagner@bmw-carit.de>
Subject: lib/sort: Move the alignment check into a function

Rasmus Villemoes suggestes to move the aliment check into a separate
function in order to improve the readability.

Furthermore, let's avoid the switch statement since gcc might mess it
up. My gcc 4.9.2 produces the same code for the x86_64
configuration. That is

	switch (size) {
		case 4:
			if (alignment_ok(base, 4))
				swap_func = u32_swap;
			       break;
		case 8:
			if (alignment_ok(base, 8))
				swap_func = u64_swap;
			break;
		}
		if (!swap_func)
			swap_func = generic_swap;
	}

resulted into the same object code.

Link: https://lkml.org/lkml/2015/5/15/89
Signed-off-by: Daniel Wagner <daniel.wagner@bmw-carit.de>
Suggested-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 lib/sort.c |   30 +++++++++---------------------
 1 file changed, 9 insertions(+), 21 deletions(-)

diff -puN lib/sort.c~lib-sort-add-64-bit-swap-function-v2-fix lib/sort.c
--- a/lib/sort.c~lib-sort-add-64-bit-swap-function-v2-fix
+++ a/lib/sort.c
@@ -8,6 +8,12 @@
 #include <linux/export.h>
 #include <linux/sort.h>
 
+static int alignment_ok(const void *base, int align)
+{
+	return IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) ||
+		((unsigned long)base & (align - 1)) == 0;
+}
+
 static void u32_swap(void *a, void *b, int size)
 {
 	u32 t = *(u32 *)a;
@@ -58,29 +64,11 @@ void sort(void *base, size_t num, size_t
 	int i = (num/2 - 1) * size, n = num * size, c, r;
 
 	if (!swap_func) {
-#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
-		switch (size) {
-		case 4:
+		if (size == 4 && alignment_ok(base, 4))
 			swap_func = u32_swap;
-			break;
-		case 8:
+		else if (size == 8 && alignment_ok(base, 8))
 			swap_func = u64_swap;
-			break;
-		}
-#else
-		switch (size) {
-		case 4:
-			if (((unsigned long)base & 3) == 0)
-				swap_func = u32_swap;
-			break;
-		case 8:
-			if (((unsigned long)base & 7) == 0)
-				swap_func = u64_swap;
-			break;
-		}
-#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */

                 reply	other threads:[~2015-05-19 23:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=555bc48c.oux4O2dPVZWbNY0F%akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=daniel.wagner@bmw-carit.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mm-commits@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.