| Message ID | 20231002193311.3985890-1-adhemerval.zanella@linaro.org (mailing list archive) |
|---|---|
| Headers |
Return-Path: <libc-alpha-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 246C8385703A for <patchwork@sourceware.org>; Mon, 2 Oct 2023 19:33:32 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id EDF233858D32 for <libc-alpha@sourceware.org>; Mon, 2 Oct 2023 19:33:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EDF233858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1c6219307b2so1263575ad.1 for <libc-alpha@sourceware.org>; Mon, 02 Oct 2023 12:33:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696275195; x=1696879995; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=Tefp8KSETvBwSp+XNOqAE7XmhBW0dOChPizDCJgskDM=; b=tlMCI1Up1VGJZl7JgrEBYm2oMon/I/GGjQpRYLKLK6ursS8W5skUaYt+htgicg1weE jg0KVWDkDgS9RIvLcguXba0nIWbIwLL1GVhEg8h7lOKOPNwNbhqdKtFc59DiFUfrslD7 5peZKOt08n7zAL9ddi50+DP+YTA2vmF3QDTU+dYaGWf8HzH2FWhQ136K5tzOZglO75cz WLFLfpLR5J56uYQG3ZVCq7YSgqN7roBbqQrzQjXpmppsdZKuOIR4/O/H3N4iO45wq5A1 JmFkA2frUnNpbv0k9Y5500nLTMwOjVrApWcYQDO7kId/8mX/oHSxr4qjvJ7xgzHjZg1y 7WYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696275195; x=1696879995; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Tefp8KSETvBwSp+XNOqAE7XmhBW0dOChPizDCJgskDM=; b=SOKeNQWwOPwkACulT56DVY3KiiDKuOrriWwKXWHoq26spKTBW0t9+zApp8GfKXfvRV BFsFwvLogAigwEu74WEOBK20I6s+NbdBT0rfWuZ9e66dyx5YxgFtPA4Zjvmtu72Y2cEQ CpZ/x/4Vrzrp5aRRnCD0W9LCPnUpzMETVyVAV395ykZ18Qi9pDlEe+Q5+SaEUP6811ZG cb5UQfBTu7kUsNmKfCkn+nrjc/V2NmDX4rS9FUnwSBKJrJ1j45dWkfhXExuaic3mTruX 04/xEnlo1f3UeglYS1gblH1TKr3BurA//+K7kcCnZMop0Tu5YB49k/8BZt1wJ9OdCxYT 7ZRg== X-Gm-Message-State: AOJu0Yx//CUzOnf9Jtam2vqFVJVkwus3hr3sz8pH++BtLIPHz3zqvAJk SttZGFfnSu6hUsL/V0+AbadK/z/D0PRWBI5jOvFdiQ== X-Google-Smtp-Source: AGHT+IE82kOfeMnZFq7g8wYeKGYQYN9+tBI+M8v+nBFh6kTvDagTCYI8926mTCnx/EqzUOkBnkdcdw== X-Received: by 2002:a17:902:efc4:b0:1c0:e12e:8e39 with SMTP id ja4-20020a170902efc400b001c0e12e8e39mr7772338plb.35.1696275195452; Mon, 02 Oct 2023 12:33:15 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c1:feaf:8f32:80e:c10a:4836]) by smtp.gmail.com with ESMTPSA id u10-20020a170902b28a00b001c7453fae33sm6982828plr.280.2023.10.02.12.33.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 12:33:14 -0700 (PDT) From: Adhemerval Zanella <adhemerval.zanella@linaro.org> To: libc-alpha@sourceware.org, Noah Goldstein <goldstein.w.n@gmail.com>, Paul Eggert <eggert@cs.ucla.edu>, Florian Weimer <fweimer@redhat.com> Subject: [PATCH v8 0/7] Use introsort for qsort Date: Mon, 2 Oct 2023 16:33:04 -0300 Message-Id: <20231002193311.3985890-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org |
| Series |
Use introsort for qsort
|
|
Message
Adhemerval Zanella Netto
Oct. 2, 2023, 7:33 p.m. UTC
The motivation for using introsort is to make it fully AS-safe and
AC-Safe, with a limited stack size requirement, to remove the use of
malloc (which is troublesome since it seems some programs 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, instead it uses used a well-understood introsort (used on
libstdc++, for instance) and leveraged the current quicksort
implementation along with a heapsort one from Linux kernel.
Performance-wise, the introsort does fall short compared to the
mergesort [1]. I have not added a benchmark because I think this should
not be the focus of this patch.
Changes from v7:
- Move __memswap to a static inline on its own header.
- Improve some comments.
Changes from v6:
- Added internal __memswap symbol.
- Improved tst-qsort3 with a reference implementation and a new
duplicated input.
Changes from v5:
- Rewrite heapsort to a custom implementation.
- Use may_alias attribute on swap optimization.
Changes from v4
- Use enum for swap function selection.
- Simplify is_aligned.
- Renamed insertsort.
Adhemerval Zanella (7):
string: Add internal memswap implementation
stdlib: Optimization qsort{_r} swap implementation
stdlib: Move insertion sort out qsort
stdlib: qsort: Move some macros to inline function
stdlib: Implement introsort for qsort (BZ 19305)
stdlib: Remove use of mergesort on qsort (BZ 21719)
stdlib: Add more qsort{_r} coverage
include/stdlib.h | 2 -
include/string.h | 3 +
manual/argp.texi | 2 +-
manual/locale.texi | 3 +-
manual/search.texi | 7 +-
stdlib/Makefile | 3 +-
stdlib/msort.c | 309 -----------------------------------
stdlib/qsort.c | 315 +++++++++++++++++++++++++++---------
stdlib/tst-qsort3.c | 366 ++++++++++++++++++++++++++++++++++++++++++
string/Makefile | 13 ++
string/memswap.c | 41 +++++
string/test-memswap.c | 191 ++++++++++++++++++++++
12 files changed, 856 insertions(+), 399 deletions(-)
delete mode 100644 stdlib/msort.c
create mode 100644 stdlib/tst-qsort3.c
create mode 100644 string/memswap.c
create mode 100644 string/test-memswap.c