glibc/glibc-rh2248502-2.patch
Florian Weimer 0413a67417 Auto-sync with upstream branch master
Upstream commit: 5dd3bda59c2d9da138f0d98808d087cdb95cdc17:

- Revert back to old qsort/qsort_r implementation (#2248502)
- Adjust test build competition check to match new DejaGnu-style message.

- sysdeps: sem_open: Clear O_CREAT when semaphore file is expected to exist [BZ #30789]
- Add SEGV_CPERR from Linux 6.6 to bits/siginfo-consts.h
- linux: Sync Linux 6.6 elf.h
- linux: Add HWCAP2_HBC from Linux 6.6 to AArch64 bits/hwcap.h
- linux: Add FSCONFIG_CMD_CREATE_EXCL from Linux 6.6 to sys/mount.h
- linux: Add MMAP_ABOVE4G from Linux 6.6 to sys/mman.h
- Update kernel version to 6.6 in header constant tests
- Update syscall lists for Linux 6.6
- Format test results closer to what DejaGnu does
- AArch64: Cleanup ifuncs
- Use correct subdir when building tst-rfc3484* for mach and arm
- stdlib: Add more qsort{_r} coverage
- stdlib: qsort: Move some macros to inline function
- stdlib: Move insertion sort out qsort
- stdlib: Optimization qsort{_r} swap implementation
- string: Add internal memswap implementation
- crypt: Remove manul entry for --enable-crypt
- Use Linux 6.6 in build-many-glibcs.py
- crypt: Remove libcrypt support
- sparc: Remove optimize md5, sha256, and sha512
- build-many-glibcs: Fix traililing whitespace
- AArch64: Add support for MOPS memcpy/memmove/memset
- Move getnameinfo from 'inet' to 'nss'
- Move getaddrinfo from 'posix' into 'nss'
- Move 'services' routines from 'inet' into 'nss'
- Move 'rpc' routines from 'inet' into 'nss'
- Move 'protocols' routines from 'inet' into 'nss'
- Move 'networks' routines from 'inet' into 'nss'
- Move 'netgroup' routines from 'inet' into 'nss'
- Move 'hosts' routines from 'inet' into 'nss'
- Move 'ethers' routines from 'inet' into 'nss'
- Move 'aliases' routines from 'inet' into 'nss'
- Remove 'shadow' and merge into 'nss'
- Remove 'pwd' and merge into 'nss'
- Remove 'gshadow' and merge into 'nss'
- Remove 'grp' and merge into 'nss' and 'posix'
- malloc: Fix tst-tcfree3 build csky-linux-gnuabiv2 with fortify source
- test-container: disable ld.so system cache on DSO detection
- aarch64: Add vector implementations of exp10 routines
- aarch64: Add vector implementations of log10 routines
- aarch64: Add vector implementations of log2 routines
- aarch64: Add vector implementations of exp2 routines
- aarch64: Add vector implementations of tan routines
- elf: ldconfig should skip temporary files created by package managers
- tst-spawn-cgroup.c: Fix argument order of UNSUPPORTED message.
- Add NT_PPC_DEXCR and NT_PPC_HASHKEYR from Linux 6.5 to elf.h
- s390: Fix undefined behaviour in feenableexcept, fedisableexcept [BZ #30960]
- elf: Do not print the cache entry if --inhibit-cache is used
2023-11-07 16:22:46 +01:00

167 lines
4.8 KiB
Diff

Revert "stdlib: Implement introsort for qsort (BZ 19305)"
This reverts commit 274a46c9b25ab733a1fb9fb1497f1beecae30193.
diff --git a/stdlib/qsort.c b/stdlib/qsort.c
index d5f205affc4371cb..80706b335722f721 100644
--- a/stdlib/qsort.c
+++ b/stdlib/qsort.c
@@ -98,7 +98,6 @@ typedef struct
{
char *lo;
char *hi;
- size_t depth;
} stack_node;
/* The stack needs log (total_elements) entries (we could even subtract
@@ -108,85 +107,22 @@ typedef struct
enum { STACK_SIZE = CHAR_BIT * sizeof (size_t) };
static inline stack_node *
-push (stack_node *top, char *lo, char *hi, size_t depth)
+push (stack_node *top, char *lo, char *hi)
{
top->lo = lo;
top->hi = hi;
- top->depth = depth;
return ++top;
}
static inline stack_node *
-pop (stack_node *top, char **lo, char **hi, size_t *depth)
+pop (stack_node *top, char **lo, char **hi)
{
--top;
*lo = top->lo;
*hi = top->hi;
- *depth = top->depth;
return top;
}
-/* NB: N is inclusive bound for BASE. */
-static inline void
-siftdown (void *base, size_t size, size_t k, size_t n,
- enum swap_type_t swap_type, __compar_d_fn_t cmp, void *arg)
-{
- while (k <= n / 2)
- {
- size_t j = 2 * k;
- if (j < n && cmp (base + (j * size), base + ((j + 1) * size), arg) < 0)
- j++;
-
- if (cmp (base + (k * size), base + (j * size), arg) >= 0)
- break;
-
- do_swap (base + (size * j), base + (k * size), size, swap_type);
- k = j;
- }
-}
-
-static inline void
-heapify (void *base, size_t size, size_t n, enum swap_type_t swap_type,
- __compar_d_fn_t cmp, void *arg)
-{
- size_t k = n / 2;
- while (1)
- {
- siftdown (base, size, k, n, swap_type, cmp, arg);
- if (k-- == 0)
- break;
- }
-}
-
-/* A non-recursive heapsort, used on introsort implementation as a fallback
- routine with worst-case performance of O(nlog n) and worst-case space
- complexity of O(1). It sorts the array starting at BASE and ending at
- END, with each element of SIZE bytes. The SWAP_TYPE is the callback
- function used to swap elements, and CMP is the function used to compare
- elements. */
-static void
-heapsort_r (void *base, void *end, size_t size, enum swap_type_t swap_type,
- __compar_d_fn_t cmp, void *arg)
-{
- const size_t count = ((uintptr_t) end - (uintptr_t) base) / size;
-
- if (count < 2)
- return;
-
- size_t n = count - 1;
-
- /* Build the binary heap, largest value at the base[0]. */
- heapify (base, size, n, swap_type, cmp, arg);
-
- /* On each iteration base[0:n] is the binary heap, while base[n:count]
- is sorted. */
- while (n > 0)
- {
- do_swap (base, base + (n * size), size, swap_type);
- n--;
- siftdown (base, size, 0, n, swap_type, cmp, arg);
- }
-}
static inline void
insertion_sort_qsort_partitions (void *const pbase, size_t total_elems,
@@ -272,7 +208,7 @@ _quicksort (void *const pbase, size_t total_elems, size_t size,
const size_t max_thresh = MAX_THRESH * size;
- if (total_elems <= 1)
+ if (total_elems == 0)
/* Avoid lossage with unsigned arithmetic below. */
return;
@@ -284,26 +220,15 @@ _quicksort (void *const pbase, size_t total_elems, size_t size,
else
swap_type = SWAP_BYTES;
- /* Maximum depth before quicksort switches to heapsort. */
- size_t depth = 2 * (sizeof (size_t) * CHAR_BIT - 1
- - __builtin_clzl (total_elems));
-
if (total_elems > MAX_THRESH)
{
char *lo = base_ptr;
char *hi = &lo[size * (total_elems - 1)];
stack_node stack[STACK_SIZE];
- stack_node *top = push (stack, NULL, NULL, depth);
+ stack_node *top = stack + 1;
while (stack < top)
{
- if (depth == 0)
- {
- heapsort_r (lo, hi, size, swap_type, cmp, arg);
- top = pop (top, &lo, &hi, &depth);
- continue;
- }
-
char *left_ptr;
char *right_ptr;
@@ -367,7 +292,7 @@ _quicksort (void *const pbase, size_t total_elems, size_t size,
{
if ((size_t) (hi - left_ptr) <= max_thresh)
/* Ignore both small partitions. */
- top = pop (top, &lo, &hi, &depth);
+ top = pop (top, &lo, &hi);
else
/* Ignore small left partition. */
lo = left_ptr;
@@ -378,13 +303,13 @@ _quicksort (void *const pbase, size_t total_elems, size_t size,
else if ((right_ptr - lo) > (hi - left_ptr))
{
/* Push larger left partition indices. */
- top = push (top, lo, right_ptr, depth - 1);
+ top = push (top, lo, right_ptr);
lo = left_ptr;
}
else
{
/* Push larger right partition indices. */
- top = push (top, left_ptr, hi, depth - 1);
+ top = push (top, left_ptr, hi);
hi = right_ptr;
}
}