From: Rasmus Villemoes <linux@rasmusvillemoes.dk>
To: Daniel Wagner <daniel.wagner@bmw-carit.de>
Cc: akpm@linux-foundation.org, mm-commits@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] lib/sort: Add 64 bit swap function
Date: Fri, 15 May 2015 09:22:12 +0200 [thread overview]
Message-ID: <87egmiuwyj.fsf@rasmusvillemoes.dk> (raw)
In-Reply-To: <1431514812-9946-1-git-send-email-daniel.wagner@bmw-carit.de> (Daniel Wagner's message of "Wed, 13 May 2015 13:00:12 +0200")
On Wed, May 13 2015, Daniel Wagner <daniel.wagner@bmw-carit.de> wrote:
>
> - if (!swap_func)
> - swap_func = (size == 4 ? u32_swap : generic_swap);
> + if (!swap_func) {
> +#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)
> + switch (size) {
> + case 4:
> + swap_func = u32_swap;
> + break;
> + case 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 */
> +
> + if (!swap_func)
> + swap_func = generic_swap;
> + }
I was more thinking of something like
static int alignment_ok(const void *base, int align)
{
return IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) ||
((unsigned long)base & (align - 1)) == 0;
}
...
if (!swap_func) {
if (size == 4 && alignment_ok(base, 4))
swap_func = u32_swap;
else if (size == 8 && alignment_ok(base, 8))
swap_func = u64_swap;
else
swap_func = generic_swap;
}
It seems to generate the same code (I usually worry about how gcc messes
up switches), so this is just a readability thing.
Rasmus
prev parent reply other threads:[~2015-05-15 7:22 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <87egml7sn6.fsf@rasmusvillemoes.dk>
2015-05-13 11:00 ` Daniel Wagner
2015-05-13 11:28 ` Daniel Wagner
2015-05-13 21:46 ` Andrew Morton
2015-05-15 7:22 ` Rasmus Villemoes [this message]
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=87egmiuwyj.fsf@rasmusvillemoes.dk \
--to=linux@rasmusvillemoes.dk \
--cc=akpm@linux-foundation.org \
--cc=daniel.wagner@bmw-carit.de \
--cc=linux-kernel@vger.kernel.org \
--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 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®