public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella <adhemerval.zanella@linaro.org>
To: libc-alpha@sourceware.org
Subject: [PATCH v5 0/6] Use introsort for qsort
Date: Thu, 13 Jul 2023 10:25:34 -0300	[thread overview]
Message-ID: <20230713132540.2854320-1-adhemerval.zanella@linaro.org> (raw)

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


             reply	other threads:[~2023-07-13 13:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-13 13:25 Adhemerval Zanella [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230713132540.2854320-1-adhemerval.zanella@linaro.org \
    --to=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).