On Wed, May 13 2015, Daniel Wagner <daniel.wag...@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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to