From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x36.google.com (mail-oa1-x36.google.com [IPv6:2001:4860:4864:20::36]) by sourceware.org (Postfix) with ESMTPS id 6FE3E3858D20 for ; Tue, 3 Oct 2023 18:13:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FE3E3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oa1-x36.google.com with SMTP id 586e51a60fabf-1dd830ed844so815110fac.2 for ; Tue, 03 Oct 2023 11:13:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696356810; x=1696961610; darn=sourceware.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ztuEE0ZqJNolNR14KPYp6Z/FLvODI65xFUgCt28o9gE=; b=c8p2IOEGARSbPxw5d6eLwIKtJzg5CU3Bb0eslzjwyve8Sdjr6YtgbrKxndOBB026fr stfARevHapd8TSdp8e5mqapwDOg5W1eg9oEyk1V7xSSWkwPIFkPRyvscq7dc5tTG3oAy Es+BLi9U+5GoI+B9qEwFXMjwCi6LxkmwR2ZdTSNzyPbFzplpFZFInfWqGhw68n2hH5vt Xj0mLdzTSwnrnstAzXknR1aCbpcXA7RnjhpMAVuSZrTQyQddYzqL8J7r1YsS9N0NUb+F GiwJ5OaurP3ibf4otTnV5XoF/A6h3VfL558ZG55VA6d6aIxvFfODkFPT6SdvZAKwl9YU 3tSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696356810; x=1696961610; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ztuEE0ZqJNolNR14KPYp6Z/FLvODI65xFUgCt28o9gE=; b=wKb7IsgvxzhkO7sadg6YN2kDHZ2N/ol5qjuGcaeFWlAGgO87BcIR2pv1ICdZGvR6Zw ycGlFlJd9LJJFHrQ7W9SJFOLd2ist5IIcg1M3r6yIFMSHHxQ4MMRA/hkjRyF0pXYLGcF Rjilnv3s0iSAjfCYOzHgPu56IS1nFDVOdk4DD2F4akMT5G9oO6tbFgEplJ2yO/HPhIlM DNONCoPEJ/EPAdQBLVAggKS4bKtlua1dhQxlZi31Rka9JJ+usoeEpVKMqhKuhDhZ1FvS i+VrClfrJ3XyFIrVqyjiANlz3Sa+0KZkYJQFVBzr5ZMIVJUJULPpaeo75wbfk0F5VXob J3WA== X-Gm-Message-State: AOJu0YwcQn37QJJD9HX3WqZF6vp7eWMJ23h6gqcFt+SrdV+nNs8IVLQ/ GZbVUOfodlQyOBUT+CG500emtVpCdkRE+SRIKOo= X-Google-Smtp-Source: AGHT+IFt71j+xSsYGj4yFKozOl99eC/j0OLUxyjzCr0l2GAFsbScqA5TeNFTPRqwXz3TEXCIH36xfAscyx4EBdspQZ8= X-Received: by 2002:a05:6870:89a5:b0:1c8:c27f:7d9b with SMTP id f37-20020a05687089a500b001c8c27f7d9bmr393225oaq.27.1696356809750; Tue, 03 Oct 2023 11:13:29 -0700 (PDT) MIME-Version: 1.0 References: <20231003122251.3325435-1-adhemerval.zanella@linaro.org> In-Reply-To: <20231003122251.3325435-1-adhemerval.zanella@linaro.org> From: Noah Goldstein Date: Tue, 3 Oct 2023 11:13:18 -0700 Message-ID: Subject: Re: [PATCH v8 0/7] Use introsort for qsort To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, Paul Eggert , Florian Weimer Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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 List-Id: On Tue, Oct 3, 2023 at 5:22=E2=80=AFAM Adhemerval Zanella wrote: > > 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. > > PS: this is a update for > https://sourceware.org/pipermail/libc-alpha/2023-October/151887.html > which should be ignored. > > 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 - > manual/argp.texi | 2 +- > manual/locale.texi | 3 +- > manual/search.texi | 7 +- > stdlib/Makefile | 3 +- > stdlib/msort.c | 309 -------------------------------- > stdlib/qsort.c | 318 +++++++++++++++++++++++++-------- > stdlib/tst-qsort3.c | 366 ++++++++++++++++++++++++++++++++++++++ > string/Makefile | 12 ++ > string/test-memswap.c | 192 ++++++++++++++++++++ > sysdeps/generic/memswap.h | 41 +++++ > 11 files changed, 856 insertions(+), 399 deletions(-) > delete mode 100644 stdlib/msort.c > create mode 100644 stdlib/tst-qsort3.c > create mode 100644 string/test-memswap.c > create mode 100644 sysdeps/generic/memswap.h > > -- > 2.34.1 > Minus the nit about the memswap changes, this series looks good.