From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id D556E385B52D for ; Fri, 27 Oct 2023 22:47:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D556E385B52D 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 D556E385B52D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::332 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698446826; cv=none; b=vFw79Z6lPoggOF71rUfYL8zxFCCwO9Jgh+lYdZx1x6jdYtrj+P0QUx0PUL81faCgqffV/nts7++fUF1LdMHSXVT9PNDKsSR8nYIFe1fn8H0hejKFDNAnwum1/zUFKQZBdYd9ViDypSPyoGo4VxxLT9y2Suy6qaMKr6Zm63qODoI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698446826; c=relaxed/simple; bh=DXuSqvlHk/15hSDgGrVTNHq69TL5xpKfZ24LgvThLkE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=ALYhUu/ORBUfMspzh8DTfSOiZYmIOtDL7jYW9jmuasi+8Hu2eShRvn2hKFlpcealp7XJP7XnWLSXFadjyAB3ss5BvZdssiSM9tvdcCVCPduME9gyfEdQw6WXAHnb9k8AVERY1RXQDzcOilM5Qt+3O6vodi9U5d3aqQA0BwhfONI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4083ac51d8aso19714725e9.2 for ; Fri, 27 Oct 2023 15:47:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698446823; x=1699051623; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=r1CSs2J3CGj1102OYLnnKwp0tseo4EMombYDpr1folo=; b=INU27e3XOlBnIkxYQ2E4RPH93n6zMrd7eVGnq6sAhUE+AVu4I1+9FfYpjp6aFrKkY9 3SbRYdsgLfpxhoBLfTlx11EzU4k3eycxYu2QD/m3jJhCHueinTEd9bhzUMZUWHi/785v V4oQMGLWfm1QdiBdjB0CpNUlRZw7AsFP+2rmG4cChUE0bnheSeO6BJLcl3gKql9eM3o4 2kUIyxrj2X+tvJp+CiDX4XMSlfQXOZgb/HC4nw0i1tHqEbuKjBL0zEp4lNtHEW+fo9Cl KPuqimjnKBmELdnHxak9QMo2n6Dj1lwi3hbEPfYnBRPxfabzkOcTKfi458YQW27b8Xw4 Yxbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698446823; x=1699051623; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=r1CSs2J3CGj1102OYLnnKwp0tseo4EMombYDpr1folo=; b=O9wgSWKmdNFEE0LdODKBNzyy4TQxBMWcvoLEzU6UYwiaUhxVtDCT7Y5GzjBVuKy7zb T/sJMVr6EDGoQrt3g++Af510YIYXqsJK0xXSOXH6ihr/NNrGATyzzR1yIihfzLutGxHg Y24JSLmTq7+T1fajQOp7L1HGXXTyoyPX53TYj5RiHqxY3cWe3JPMx/VlLj5p7IeleWYt tNFJbfirj+jHzWJ8UhJWallGmp+mGOoi1EeWutPyuKrCxFuv+YcjiH1PoB2cHGwIkOHD lU1f9C3bZ0vWIbCWnPg4SUhmLE8IKda5zD8o1a133TVU4IL+YiFuFZ7VttFM+jTMcoSq tjhw== X-Gm-Message-State: AOJu0YxVXiagW+02JHj8IrA2IAUI1xM/UDCKHCc1BcMPY5ntelQ9Pg0d x0eo/wfKMrVhTRFJLqBaOCY= X-Google-Smtp-Source: AGHT+IEbbC+bGO6wJti4h4sJZ0UzTxuPuya+j4S2WY1lVKRKG0cMIBQOjnWXQdrdv0n+6C1KBvihqw== X-Received: by 2002:a05:600c:5252:b0:402:98cd:a3e9 with SMTP id fc18-20020a05600c525200b0040298cda3e9mr3282777wmb.32.1698446822455; Fri, 27 Oct 2023 15:47:02 -0700 (PDT) Received: from [10.96.0.57] ([146.70.48.3]) by smtp.gmail.com with ESMTPSA id y9-20020a7bcd89000000b00407efbc4361sm6060340wmj.9.2023.10.27.15.47.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Oct 2023 15:47:01 -0700 (PDT) Message-ID: <1b4a07e3-cf6d-4f71-9c07-a9079274e9fb@gmail.com> Date: Fri, 27 Oct 2023 23:47:00 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8 1/7] string: Add internal memswap implementation Content-Language: en-US To: Adhemerval Zanella Netto , Noah Goldstein Cc: libc-alpha@sourceware.org, Paul Eggert , Florian Weimer References: <20231003122251.3325435-1-adhemerval.zanella@linaro.org> <20231003122251.3325435-2-adhemerval.zanella@linaro.org> <9fa121e7-434a-4f63-897b-b0cc09d38c35@linaro.org> From: Gabriel Ravier In-Reply-To: <9fa121e7-434a-4f63-897b-b0cc09d38c35@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.9 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 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 AM 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 := \ >>> tst-xbzero-opt \ >>> # tests >>> >>> +tests-static-internal := \ >>> + test-memswap \ >>> +# tests-static-internal >>> + >>> +tests-internal := \ >>> + $(tests-static-internal) \ >>> + # tests-internal >>> + >>> +tests-static := \ >>> + $(tests-static-internal) \ >>> + # tests-static >>> + >>> # Both tests require the .mo translation files generated by msgfmt. >>> tests-translation := \ >>> 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/or >>> + 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 useful, >>> + 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 &= page_size; >>> + if (align1 + len >= page_size) >>> + return; >>> + >>> + align2 &= page_size; >>> + if (align2 + len >= page_size) >>> + return; >>> + >>> + unsigned char *p1 = buf1 + align1; >>> + unsigned char *p2 = buf2 + align2; >>> + for (size_t repeats = 0; repeats < 2; ++repeats) >>> + { >>> + size_t i, j; >>> + for (i = 0, j = 1; i < len; i++, j += 23) >>> + { >>> + ref1[i] = p1[i] = j; >>> + ref2[i] = p2[i] = UCHAR_MAX - j; >>> + } >>> + >>> + do_one_test (p1, ref1, p2, ref2, len); >>> + } >>> +} >>> + >>> +static void >>> +do_random_tests (void) >>> +{ >>> + for (size_t n = 0; n < ITERATIONS; n++) >>> + { >>> + size_t len, size, size1, size2, align1, align2; >>> + >>> + if (n == 0) >>> + { >>> + len = getpagesize (); >>> + size = len + 512; >>> + size1 = size; >>> + size2 = size; >>> + align1 = 512; >>> + align2 = 512; >>> + } >>> + else >>> + { >>> + if ((random () & 255) == 0) >>> + size = 65536; >>> + else >>> + size = 768; >>> + if (size > page_size) >>> + size = page_size; >>> + size1 = size; >>> + size2 = size; >>> + size_t i = random (); >>> + if (i & 3) >>> + size -= 256; >>> + if (i & 1) >>> + size1 -= 256; >>> + if (i & 2) >>> + size2 -= 256; >> Some tests with misaligned size seem in order. > I am not sure I understood what is wrong here, by 'in order' do you mean > 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.