--- zzzz-none-000/linux-3.10.107/lib/sort.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/lib/sort.c 2021-02-04 17:41:59.000000000 +0000 @@ -4,10 +4,15 @@ * Jan 23 2005 Matt Mackall */ -#include -#include +#include +#include #include -#include + +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) { @@ -16,6 +21,13 @@ *(u32 *)b = t; } +static void u64_swap(void *a, void *b, int size) +{ + u64 t = *(u64 *)a; + *(u64 *)a = *(u64 *)b; + *(u64 *)b = t; +} + static void generic_swap(void *a, void *b, int size) { char t; @@ -51,8 +63,14 @@ /* pre-scale counters for performance */ int i = (num/2 - 1) * size, n = num * size, c, r; - if (!swap_func) - swap_func = (size == 4 ? u32_swap : generic_swap); + 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; + } /* heapify */ for ( ; i >= 0; i -= size) { @@ -85,6 +103,7 @@ EXPORT_SYMBOL(sort); #if 0 +#include /* a simple boot-time regression test */ int cmpint(const void *a, const void *b)