public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v5 0/6] Use introsort for qsort
@ 2023-07-13 13:25 Adhemerval Zanella
  2023-07-13 13:25 ` [PATCH v5 1/6] stdlib: Optimization qsort{_r} swap implementation Adhemerval Zanella
                   ` (5 more replies)
  0 siblings, 6 replies; 17+ messages in thread
From: Adhemerval Zanella @ 2023-07-13 13:25 UTC (permalink / raw)
  To: libc-alpha

The main motivation to use introsort is to make it fully AS-Safe and
AC-Safe, with a limited stack size requirement, to remove the use
of malloc (which troublesome since it seems some program do longjmp
from the callback comparison program), and keep worst-case scenario
bounded to O(n*ln(n)) (instead of potentially quadradic as for the
quicksort).

The implementation does not aim to be the state-of-the-art sort
algorithm, rather I used a well understood introsort (used on
libstdc++, for instance) and leverage the current quicksort
implementation along with a heapsort one from Linux kernel.

Performance-wise, the introsort does fall short compare to
mergesort [1].  I have not added the benchmark because I see that
this should not be focus of this patch. I have added some simple
optimization, also used by Linux kernel heapsort.

Changes from v4
- Use enum for swap function selection.
- Simplify is_aligned.
- Renamed insertsort.

[1] https://sourceware.org/pipermail/libc-alpha/2021-September/130698.html

Adhemerval Zanella (6):
  stdlib: Optimization qsort{_r} swap implementation
  stdlib: Move insertion sort out qsort
  stdlib: qsort: Move some macros to inline function
  stdlib: Implement introsort with qsort (BZ 19305)
  stdlib: Remove use of mergesort on qsort (BZ 21719)
  stdlib: Add more qsort{_r} coverage

 include/stdlib.h    |   2 -
 manual/argp.texi    |   2 +-
 manual/locale.texi  |   3 +-
 manual/search.texi  |   7 +-
 stdlib/Makefile     |   3 +-
 stdlib/msort.c      | 309 ----------------------------------------
 stdlib/qsort.c      | 337 +++++++++++++++++++++++++++++++++-----------
 stdlib/tst-qsort3.c | 298 +++++++++++++++++++++++++++++++++++++++
 8 files changed, 562 insertions(+), 399 deletions(-)
 delete mode 100644 stdlib/msort.c
 create mode 100644 stdlib/tst-qsort3.c

-- 
2.34.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2023-07-18 14:13 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-13 13:25 [PATCH v5 0/6] Use introsort for qsort Adhemerval Zanella
2023-07-13 13:25 ` [PATCH v5 1/6] stdlib: Optimization qsort{_r} swap implementation Adhemerval Zanella
2023-07-13 22:17   ` Paul Eggert
2023-07-14  1:01     ` Paul Eggert
2023-07-14 12:06       ` Adhemerval Zanella Netto
2023-07-17 16:57   ` Alexander Monakov
2023-07-17 17:29     ` Paul Eggert
2023-07-17 18:07       ` Adhemerval Zanella Netto
2023-07-17 18:58         ` Paul Eggert
2023-07-17 19:06           ` Adhemerval Zanella Netto
2023-07-18 14:01     ` Adhemerval Zanella Netto
2023-07-18 14:13       ` Adhemerval Zanella Netto
2023-07-13 13:25 ` [PATCH v5 2/6] stdlib: Move insertion sort out qsort Adhemerval Zanella
2023-07-13 13:25 ` [PATCH v5 3/6] stdlib: qsort: Move some macros to inline function Adhemerval Zanella
2023-07-13 13:25 ` [PATCH v5 4/6] stdlib: Implement introsort with qsort (BZ 19305) Adhemerval Zanella
2023-07-13 13:25 ` [PATCH v5 5/6] stdlib: Remove use of mergesort on qsort (BZ 21719) Adhemerval Zanella
2023-07-13 13:25 ` [PATCH v5 6/6] stdlib: Add more qsort{_r} coverage Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).