From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) by sourceware.org (Postfix) with ESMTPS id 1E242385B52D for ; Sat, 28 Oct 2023 01:31:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E242385B52D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1E242385B52D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698456704; cv=none; b=Nzj5EIFlvkplSFy8PSPB5q62VL2sDdR/l2LOmiINx2H7v/TrwVgCOAukvs70M12UFGLEHUIFo3XixUhsTZBJVJnEJUDPWwk3SINpx0RioiYFex8rXlaCmcYZvTfzF9MIDoWCnKOomnm2zCXmfegkZcC9W66UdcYB4d+ubkY6xNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698456704; c=relaxed/simple; bh=LYzI6tL1tJmXD0RcRNHnhxCGP623nHRHsvGbl5CpEk0=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=GzsuFh2YC5075KxMaM28SOE2cYwhAv0XZ6YlxYpQZgSTRDOdskL/Moqf1SPgHQ9Emc2IlMineRnpEPiQjqtnuevhQe84Afo7hIrJKCmJunWz+E1dnoquAQHWuRQdFS/U3WHnoJt05f9Kl3ztNQkrjc/tV3CQdKvZ9nwfkX39mcc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-1e9a757e04eso1912934fac.0 for ; Fri, 27 Oct 2023 18:31:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698456701; x=1699061501; 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=6wDLh9NPtThWhfvtQJhOk1vw10+hJzm2bzKpqb/oq+8=; b=VwngJi9pn5NrFV6NF0qOAlFvqRCejcSrWO0SVdQ1lCPuBvUDbTBtFfeTqGqELfTkyC SrERyWqp6Rj6lW7VoMkU5soZtAYdxJpkLfX7CHHv4IKxK38EKVKwzMsggUoaHUOri4/w uTrKaa84ihCGHAViwlFdK1YcsQP0dU2p+zC+Mk7xr41SQyoU29sLl5uyx2Nm6IwV1gec 02Izqec/5QA/kPBn+nYIuH2vxt6QJJ5CKCpnDfKheucVay1dhxlM9nty/JNBbfLMGN3s I4BE8v+Aoo9Ry+COIMJiFgSkcY50meq6xsLXniVV92GbWwGyOUdaO8rUC6MGxO4QPEX5 agBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698456701; x=1699061501; 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=6wDLh9NPtThWhfvtQJhOk1vw10+hJzm2bzKpqb/oq+8=; b=iBwcNZYAE3Hxe9UlBB8hfcs9u+51PqsqdgWumgHxoymRo1KKEGs1Scn7tz8x95W2Qd hats+6AHaDXd/jn5IiEeAVqPRcLYDKMBA6J3ZULNyBz1WjdMBceSqVCLjB7pHa3nFS2t azgyIoMkxNCAH/pjSECIHt+6cmHPulmKTX3MJUAbaBScGmRolxrVQDOulollEw1Zg0wa 35l6dBpCT7FVMnRUSMcYEX6q4/f7vkpZkZ7LWoXkgvAftzo3Uz98Lij5TYZeO1lbXerf PtNfaLVDBS4y1QtO3+O51kEsAkpY7ckEr2mNt4EydVccAAWrJ5OF4YuyezGtMlPO459Q nNdg== X-Gm-Message-State: AOJu0Yx6BCviPax7+j66XJPKMR3BJtx8IbaeCjAodP9eoHGUk8S1iSeo Ubj8/FrQKVCSQX9LhfOTu7ytPauXsHiJLvyDd6Y= X-Google-Smtp-Source: AGHT+IFk1mpPaNG0/89YwEjcapfMsXUJHeGA2rVZGBY6Ks1/4hVwxk84+8l/9sxKc4dXxepoBrSLzKPJc1JE3HS8o44= X-Received: by 2002:a05:6871:3721:b0:1e9:ad95:907a with SMTP id no33-20020a056871372100b001e9ad95907amr4254957oac.17.1698456701257; Fri, 27 Oct 2023 18:31:41 -0700 (PDT) MIME-Version: 1.0 References: <20231003122251.3325435-1-adhemerval.zanella@linaro.org> In-Reply-To: From: Noah Goldstein Date: Fri, 27 Oct 2023 20:31:29 -0500 Message-ID: Subject: Re: [PATCH v8 0/7] Use introsort for qsort To: Adhemerval Zanella Netto 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 Fri, Oct 27, 2023 at 3:25=E2=80=AFPM Adhemerval Zanella Netto wrote: > > > > On 03/10/23 15:13, Noah Goldstein wrote: > > 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 shou= ld > >> 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. > > Thanks for the review, may I get reviewed-by ;) ? LGTM with nit about memswap tests. Reviewed-by: Noah Goldstein