From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by sourceware.org (Postfix) with ESMTPS id CB676385351D for ; Fri, 27 Oct 2023 20:25:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB676385351D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CB676385351D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698438305; cv=none; b=ESjrbHmY8f6ID9GBaLUE2faDHulP/NTQRyIr6+1mQ1IfMtthetlV/yJ7QBWczKIOTYLsT04hkzo/UsbunbN7bYTNSHWfqBQ9K7H+7t6jkpUID4/aISSl14wlXV+C7RDZL4pLf+rHGT+xHcMf7rvQt6YXdB7i4/1wAlTslQ5Z7/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698438305; c=relaxed/simple; bh=7OjI0HcrbRSrHUwGcJ+LYzW8i354oGQgKEIbc/iaIYs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=mhpaPSNWnU9x6EZ8iDJeP3JORSRsFe6kPIvIM0EpBmwOYw0Nd8Bcl8C6su04dLswOsbW3pMr2HxaUnGa+rXvBJLKgmutj9k1bxbjJGePlDlJeTJ5p9lFg40hQevA9tp+HkcCLGNyWaBUCaEMiySGcFlZhx6lF6xyDp8hN2yd4zk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-yb1-xb29.google.com with SMTP id 3f1490d57ef6-d9ca471cf3aso1821524276.2 for ; Fri, 27 Oct 2023 13:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698438303; x=1699043103; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=vpZIP1RSjrisrPq8h45BfV6kWdxE5FNctSeg6OwjfPM=; b=HiIBAyPU03X7/7BmG+96FQ0xtEamsYwYDVULlNET/Wk5jMDygXrU9lapQ6Rih+TTqp JlTJvX3nV0kHuUofyf6XqadC7PAnwi8b+ZCZXr6fhJqpu0fmS7wwkJt471rV0+fAP0xH v0nu6kzr1+nQ65xVbBlclt/KRi1A12VkZSOWvHwEv5RGt0L+QeUE0RHhBwhMUrpPHmys OYgqz6zWvKL4BjjwzDkNKiybQMjuMVRyfQr/J+Aq6Rl2kAYnVPOKh1S3qmbd5DnHKnGq 5HJxRpQfm/PcgcEkd7HBI3x3cMYYO/wg6MDX62LLthFjVuSwGf6E/u73tfzE3M65rfjs XMOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698438303; x=1699043103; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=vpZIP1RSjrisrPq8h45BfV6kWdxE5FNctSeg6OwjfPM=; b=oiU5F/pbSABImgwY+5CyjyRLEr1zcnzwCmiUEIBGK/KnFZvY6r1a6hMgZ/vlPi40Oe ZNWrMMOtP9wah4qiur0wW4q+4mWINb80iaM+M5MsDitSsho/4oq3Uc7uPTv+riAsZFtW i5VvrcXMSrC5gfJHcT5zqiETCz/63VBooluwXczT0L8+k9r1Xd7R1pOQz4D1OKE0T7dn RItTfnjlZqCKCeTftka3uHpq/wzUhU6Qh9KAxHzIijQfPfqjSibRNOEEChL9LMODcCeD Hj/rDCs5GMg1POQo8Ajd5OpNMiLb9Gfl78DWiesKgxQIPzCb6LYgZMJD3y6rcM6iGvbE LMBQ== X-Gm-Message-State: AOJu0YyTKR9Prx6RlODENxdjTrOrjcsUjsFbd0aoPT6adP0Ky9QTpVxr TiZzppC4G8nh7gK5n5SV5OYGpA== X-Google-Smtp-Source: AGHT+IHNmn5VJGzf0APRTLhpJLNjBLvKUIkTDbHbaJTO2hPfUcUHDfRHcMFfRSnJYBR+MF0iMQNqyw== X-Received: by 2002:a25:2684:0:b0:da0:3924:3c9b with SMTP id m126-20020a252684000000b00da039243c9bmr3879753ybm.23.1698438302838; Fri, 27 Oct 2023 13:25:02 -0700 (PDT) Received: from [192.168.15.31] (189-46-2-229.dsl.telesp.net.br. [189.46.2.229]) by smtp.gmail.com with ESMTPSA id n201-20020a25d6d2000000b00da06575fbc8sm960586ybg.2.2023.10.27.13.25.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 27 Oct 2023 13:25:02 -0700 (PDT) Message-ID: <9fa121e7-434a-4f63-897b-b0cc09d38c35@linaro.org> Date: Fri, 27 Oct 2023 17:23:44 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v8 1/7] string: Add internal memswap implementation To: 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> Content-Language: en-US From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_BARRACUDACENTRAL,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 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?