sort.c (c95baf12f5077419db01313ab61c2aac007d40cd) sort.c (9dbbc3b9d09d6deba9f3b9e1d5b355032ed46a75)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * A fast, small, non-recursive O(n log n) sort for the Linux kernel
4 *
5 * This performs n*log2(n) + 0.37*n + o(n) comparisons on average,
6 * and 1.5*n*log2(n) + O(n) in the (very contrived) worst case.
7 *
8 * Glibc qsort() manages n*log2(n) - 1.26*n for random inputs (1.63*n

--- 37 unchanged lines hidden (view full) ---

46 * @a: pointer to the first element to swap
47 * @b: pointer to the second element to swap
48 * @n: element size (must be a multiple of 4)
49 *
50 * Exchange the two objects in memory. This exploits base+index addressing,
51 * which basically all CPUs have, to minimize loop overhead computations.
52 *
53 * For some reason, on x86 gcc 7.3.0 adds a redundant test of n at the
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * A fast, small, non-recursive O(n log n) sort for the Linux kernel
4 *
5 * This performs n*log2(n) + 0.37*n + o(n) comparisons on average,
6 * and 1.5*n*log2(n) + O(n) in the (very contrived) worst case.
7 *
8 * Glibc qsort() manages n*log2(n) - 1.26*n for random inputs (1.63*n

--- 37 unchanged lines hidden (view full) ---

46 * @a: pointer to the first element to swap
47 * @b: pointer to the second element to swap
48 * @n: element size (must be a multiple of 4)
49 *
50 * Exchange the two objects in memory. This exploits base+index addressing,
51 * which basically all CPUs have, to minimize loop overhead computations.
52 *
53 * For some reason, on x86 gcc 7.3.0 adds a redundant test of n at the
54 * bottom of the loop, even though the zero flag is stil valid from the
54 * bottom of the loop, even though the zero flag is still valid from the
55 * subtract (since the intervening mov instructions don't alter the flags).
56 * Gcc 8.1.0 doesn't have that problem.
57 */
58static void swap_words_32(void *a, void *b, size_t n)
59{
60 do {
61 u32 t = *(u32 *)(a + (n -= 4));
62 *(u32 *)(a + n) = *(u32 *)(b + n);

--- 210 unchanged lines hidden ---
55 * subtract (since the intervening mov instructions don't alter the flags).
56 * Gcc 8.1.0 doesn't have that problem.
57 */
58static void swap_words_32(void *a, void *b, size_t n)
59{
60 do {
61 u32 t = *(u32 *)(a + (n -= 4));
62 *(u32 *)(a + n) = *(u32 *)(b + n);

--- 210 unchanged lines hidden ---