From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2f.google.com (mail-oa1-x2f.google.com [IPv6:2001:4860:4864:20::2f]) by sourceware.org (Postfix) with ESMTPS id E01CA3858D38 for ; Sat, 28 Oct 2023 01:30:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E01CA3858D38 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 E01CA3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::2f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698456643; cv=none; b=oIsEzzkoxnYCb1FoUvRKWqm3BiUkk2eLYsiCo8vYeswUGdJMgPE5iJmdREFT6rHXkyd1x4YSfDKuAKUUIZNRfkO0ZF+IThU+WufNvt5TFdMqjH3z5qFxWiDGawqT/LsWwPEi4hAfyp8NLJ3izADPaDfrfHXueb2UCQJktfwRKTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698456643; c=relaxed/simple; bh=vaz4rwXECfN8herq9unGsQhFiLLcNcUa9LPFXxYv0s4=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=P+7CIzZvIbm4sK/ibey4TAKii5sji0eXpQDu3c0dz66J7kTVp3uD/J1jFkfpmw9f1vLKD3yDpTx2bfLWjFBq+amCj3/7YQh574OHf+vC6sGrGiwiRVKw1gwjIZUPLczyuNc8p54Z9ZznvWApMpKwzEM3SQQ46fdDXnyANLm10QQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oa1-x2f.google.com with SMTP id 586e51a60fabf-1e993765c1bso1682579fac.3 for ; Fri, 27 Oct 2023 18:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698456640; x=1699061440; 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=ci3KAViHhGmTzlKydDKlYX0xceFCVQ2+4vk6bAf8b2E=; b=HQl5ppnsuqzrPK0u/GIjCeHuts+LLy6gz5N/lpEX99dUh3xSq1SaUE55661j2q8Ofo 5tAbM/FXjW8uSIrnyLsCU3HqViRufd8YOFY7z1/ADt18OVc/UOu/iqhi1jgihUt/fp3D cl7RsjLXEFkpA5wRaCJ03no1npkt8C861U1MxstZbYCcPOnO4ApB42Jj4HM8gSUA5Dp6 ZuwsPCMuJYzRspqbSgGunGXqT72kIAXX0jD/YXgeJ0O+gd8NTPEy8a/CGtaa/Rw1kTT+ tYJ/C84sVp+oX1uixcS+KvT+di/J+xk0W0K9vBeSGiqgdZMqj4ck9LcuJEIVGW2EXFK+ NGgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698456640; x=1699061440; 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=ci3KAViHhGmTzlKydDKlYX0xceFCVQ2+4vk6bAf8b2E=; b=dcFhCX5s8twY3dgqAQ0z1n3Z2HoiViOvnR4qE4NTEqbSpT0uGJcsaZf/XYV7M4lcbK W3I0OoY/sYHt8WAZGAyytQtSyEAE9ohlKiGVdCXgOmkqYqc7k/Sy3dLiAewBesD9wkQt /7WZAFXD7cXbScI/gEkfNx7GIZ33csY3ozKVOASr5b+/3kcXlRkkC0CoKtsvY9yR4z7D 9E5id0IQfLgseQqRF28ikRxsQFMqE00M4Y1uiJr8boMfNUwPJfI8oGBc+DGPi5kC8H1b qHK93LFdglD6BAE4quoocFMiHQxjwPfKjjiLc/3TqXneaFFzL0kAGoJz6bsOgtGfOzrR SG1A== X-Gm-Message-State: AOJu0YzPZBRUh2p5ew4SQQoy7aoZt5su3ST6MEfPkko4kiE3bjw9xOuN +shVhpukkoydxQZmRdeV4sfltx0NLSTxi24zrhI= X-Google-Smtp-Source: AGHT+IGyLmx/tnmcN0+3ncQLbBTn7YXXp0sX0OJzIn8tACV2Fn01Ts7xL30XXVBIF4sQBC3hwioqlT/ONzEO8AGwT1c= X-Received: by 2002:a05:6871:64c3:b0:1e9:c86f:4d72 with SMTP id rk3-20020a05687164c300b001e9c86f4d72mr6175223oab.45.1698456640396; Fri, 27 Oct 2023 18:30:40 -0700 (PDT) MIME-Version: 1.0 References: <20231003122251.3325435-1-adhemerval.zanella@linaro.org> <20231003122251.3325435-2-adhemerval.zanella@linaro.org> <9fa121e7-434a-4f63-897b-b0cc09d38c35@linaro.org> <1b4a07e3-cf6d-4f71-9c07-a9079274e9fb@gmail.com> In-Reply-To: <1b4a07e3-cf6d-4f71-9c07-a9079274e9fb@gmail.com> From: Noah Goldstein Date: Fri, 27 Oct 2023 20:30:28 -0500 Message-ID: Subject: Re: [PATCH v8 1/7] string: Add internal memswap implementation To: Gabriel Ravier Cc: Adhemerval Zanella Netto , 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=-9.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,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 5:47=E2=80=AFPM Gabriel Ravier wrote: > > On 10/27/23 21:23, Adhemerval Zanella Netto wrote: > > > > On 03/10/23 14:42, Noah Goldstein wrote: > >> On Tue, Oct 3, 2023 at 5:22=E2=80=AFAM Adhemerval Zanella > >> wrote: > >>> The prototype is: > >>> > >>> void __memswap (void *restrict p1, void *restrict p2, size_t n) > >>> > >>> The function swaps the content of two memory blocks P1 and P2 of > >>> len N. Memory overlap is NOT handled. > >>> > >>> It will be used on qsort optimization. > >>> > >>> Checked on x86_64-linux-gnu and aarch64-linux-gnu. > >>> --- > >>> string/Makefile | 12 +++ > >>> string/test-memswap.c | 192 +++++++++++++++++++++++++++++++++++= +++ > >>> sysdeps/generic/memswap.h | 41 ++++++++ > >>> 3 files changed, 245 insertions(+) > >>> create mode 100644 string/test-memswap.c > >>> create mode 100644 sysdeps/generic/memswap.h > >>> > >>> diff --git a/string/Makefile b/string/Makefile > >>> index 8cdfd5b000..fb101db778 100644 > >>> --- a/string/Makefile > >>> +++ b/string/Makefile > >>> @@ -209,6 +209,18 @@ tests :=3D \ > >>> tst-xbzero-opt \ > >>> # tests > >>> > >>> +tests-static-internal :=3D \ > >>> + test-memswap \ > >>> +# tests-static-internal > >>> + > >>> +tests-internal :=3D \ > >>> + $(tests-static-internal) \ > >>> + # tests-internal > >>> + > >>> +tests-static :=3D \ > >>> + $(tests-static-internal) \ > >>> + # tests-static > >>> + > >>> # Both tests require the .mo translation files generated by msgfmt. > >>> tests-translation :=3D \ > >>> tst-strerror \ > >>> diff --git a/string/test-memswap.c b/string/test-memswap.c > >>> new file mode 100644 > >>> index 0000000000..162beb91e3 > >>> --- /dev/null > >>> +++ b/string/test-memswap.c > >>> @@ -0,0 +1,192 @@ > >>> +/* Test and measure memcpy functions. > >>> + Copyright (C) 2023 Free Software Foundation, Inc. > >>> + This file is part of the GNU C Library. > >>> + > >>> + The GNU C Library is free software; you can redistribute it and/o= r > >>> + modify it under the terms of the GNU Lesser General Public > >>> + License as published by the Free Software Foundation; either > >>> + version 2.1 of the License, or (at your option) any later version= . > >>> + > >>> + The GNU C Library is distributed in the hope that it will be usef= ul, > >>> + but WITHOUT ANY WARRANTY; without even the implied warranty of > >>> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > >>> + Lesser General Public License for more details. > >>> + > >>> + You should have received a copy of the GNU Lesser General Public > >>> + License along with the GNU C Library; if not, see > >>> + . */ > >>> + > >>> +#include > >>> +#include > >>> +#include > >>> + > >>> +#define TEST_MAIN > >>> +#define BUF1PAGES 3 > >>> +#include "test-string.h" > >>> + > >>> +static unsigned char *ref1; > >>> +static unsigned char *ref2; > >>> + > >>> +static void > >>> +do_one_test (unsigned char *p1, unsigned char *ref1, unsigned char *= p2, > >>> + unsigned char *ref2, size_t len) > >>> +{ > >>> + __memswap (p1, p2, len); > >>> + > >>> + TEST_COMPARE_BLOB (p1, len, ref2, len); > >>> + TEST_COMPARE_BLOB (p2, len, ref1, len); > >>> +} > >>> + > >>> +static inline void > >>> +do_test (size_t align1, size_t align2, size_t len) > >>> +{ > >>> + align1 &=3D page_size; > >>> + if (align1 + len >=3D page_size) > >>> + return; > >>> + > >>> + align2 &=3D page_size; > >>> + if (align2 + len >=3D page_size) > >>> + return; > >>> + > >>> + unsigned char *p1 =3D buf1 + align1; > >>> + unsigned char *p2 =3D buf2 + align2; > >>> + for (size_t repeats =3D 0; repeats < 2; ++repeats) > >>> + { > >>> + size_t i, j; > >>> + for (i =3D 0, j =3D 1; i < len; i++, j +=3D 23) > >>> + { > >>> + ref1[i] =3D p1[i] =3D j; > >>> + ref2[i] =3D p2[i] =3D UCHAR_MAX - j; > >>> + } > >>> + > >>> + do_one_test (p1, ref1, p2, ref2, len); > >>> + } > >>> +} > >>> + > >>> +static void > >>> +do_random_tests (void) > >>> +{ > >>> + for (size_t n =3D 0; n < ITERATIONS; n++) > >>> + { > >>> + size_t len, size, size1, size2, align1, align2; > >>> + > >>> + if (n =3D=3D 0) > >>> + { > >>> + len =3D getpagesize (); > >>> + size =3D len + 512; > >>> + size1 =3D size; > >>> + size2 =3D size; > >>> + align1 =3D 512; > >>> + align2 =3D 512; > >>> + } > >>> + else > >>> + { > >>> + if ((random () & 255) =3D=3D 0) > >>> + size =3D 65536; > >>> + else > >>> + size =3D 768; > >>> + if (size > page_size) > >>> + size =3D page_size; > >>> + size1 =3D size; > >>> + size2 =3D size; > >>> + size_t i =3D random (); > >>> + if (i & 3) > >>> + size -=3D 256; > >>> + if (i & 1) > >>> + size1 -=3D 256; > >>> + if (i & 2) > >>> + size2 -=3D 256; > >> Some tests with misaligned size seem in order. > > I am not sure I understood what is wrong here, by 'in order' do you mea= n > > exactly what? > > My interpretation was that this is the less commonly used meaning of "in > order" as meaning "appropriate in the current circumstances", i.e. that > tests that invoke memswap with unaligned operands seem like they would > be useful. ^ >