From patchwork Tue Jan 14 21:03:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Noah Goldstein X-Patchwork-Id: 104786 X-Patchwork-Delegate: fweimer@redhat.com Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39FC8385C41A for ; Tue, 14 Jan 2025 21:04:14 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oo1-xc36.google.com (mail-oo1-xc36.google.com [IPv6:2607:f8b0:4864:20::c36]) by sourceware.org (Postfix) with ESMTPS id 6123538560AB for ; Tue, 14 Jan 2025 21:03:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6123538560AB 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 6123538560AB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c36 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736888628; cv=none; b=oHj4xsk2lrQPoct4wukGvE6/gJ1KVrRr6pBah+E7y/0Fgp8bDTKZSjqsDzWBNeAMUj8gACdmUAqzjKNMYjo4x7cgJhLtEbZZMgycUu6j2oq7zAhVSZbA1w/lJVwVaIC10/CdBEGKz5tW6XwandDR41Z+euGOPY93fhQHTZbrfeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736888628; c=relaxed/simple; bh=yC3TCnMKqlKhAdkElPvpTblIJkCQKNrwigBy3Q5WPbk=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=mJkzzwGyUB+PkIhnH1LXdNlEHLtdR5hJxW67QY5UkGdhVeuXA2iONIanI5AhQRGfXCQMAmkxbm+/9meoaEk+OU+MoT79XWXZo+eJXcw9cr7M4ec5bZhmkIDFLojwifbluGUGHssQdAWd63XzuIc/riYwRVa25wflQ2B+V7VhNIQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6123538560AB Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=eR1TC3yi Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-5f4c111991bso112199eaf.0 for ; Tue, 14 Jan 2025 13:03:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736888627; x=1737493427; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=HjeLGkpxKeTiVVA141q3iv0r8nclOmLEreJPC//z0r4=; b=eR1TC3yiy++89RDd4gmN2sXdhqe7/VmHBi+rajRy3w2g558l35odINUgrT34jcp12i x0dMgM582Z+S4/4ZQTN3xeUTqKpki8LzZS+mVHFQBSf+vgLV654Z7aldNPCvflVjq/42 ZEHBOO5o+TMC5n/4KAOdcIxOMjioKyLSKL3FszCvo4SHNqBhLexu5w5esndUrhlgpj3i lmBiZk2xod5fRbB2AvcmdJRHeyPbP3aTQlBKKtIGnHk+r4IvYM46L/IIbugoLivMRjWK FN7z+W1o21ATWJfHT135luCd7Hvnf/8+VPGf8cz3c1bD4PBU86SLdu971zMo4vgaB7+S JH3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736888627; x=1737493427; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HjeLGkpxKeTiVVA141q3iv0r8nclOmLEreJPC//z0r4=; b=uiYqSxm8Aet4SY92UCMbWInwS2K6Z7ABqPThtWXIxr6wrzAeLbu7t23m04W3siVoNo wyormZ/Tt1VgwKUhh8yvyW6YiVPmNsWfovgWP+kooQKYyWc+O0Jtj4CGwYjZzOK04Re5 fjo0MEKBgdytpUYXaufpDPr9XspC/NshFPFf4UfOlAi5xzHHtI7hS2BLvmmk4U3g/B54 POUCvhALSW2+jRg9Ie5dT8867YCVI4EjVH6CAYc9qo1g+Bc5CC5C0ulQsWZt0qPevR/L f+G639+pIOJga7IoAhB46uQlEM9OlXodBXaP1++2AuXYXOTxdDTN8ayAVGo8/jowqR2J qCBA== X-Gm-Message-State: AOJu0YytkYSTJL9S0g2XY62Vrut50FM3c7Vx7zBAae3iIPgs/H0lWr0E ZJhd2An9qAHJsv9QiqS6h//6jqRK1PfyZMosn65yxG04kLF0bMA/wT6+5A== X-Gm-Gg: ASbGnctCLkm808ZA+O1Y18SDAfldHN4IXVmmDI9xdiFiJb3S1UfY6Hu7Qyvqq96wYlS tkJyOl3OJT6TasUQBsMpmcLZ2zoi9iCC8mchPEVHHTFfOaPJXXQW8im/2yDseeUE8oLY/5mudWl 5l2tHhei5yMMoTGmeoxmaiosv0TkXJDVOB78cDMevr5gKjS32nyj9jM2NMS3CKoHvaYg+qGKbfD B/LbBEySBXYMVn0ibQspMjIm9ivrA+v5pPW3pp+T8kRoVVkZ6DIiX8gw/CyjP04YVDqFyQQ7iil QDZUEyS+4bCwmAuoEKOMW6GS/iAQZ2w5rQ== X-Google-Smtp-Source: AGHT+IGkvXLXnllGvP8zofDbUNnR0mFYURV/RTH+VxQsyRaZBvZW5VUKA+Uy7mAOazrF1JUQYqOeHA== X-Received: by 2002:a4a:e84c:0:b0:5f3:4c09:55e7 with SMTP id 006d021491bc7-5f8fa867a9dmr324457eaf.3.1736888627231; Tue, 14 Jan 2025 13:03:47 -0800 (PST) Received: from noahgold-desk.lan (syn-024-243-147-173.res.spectrum.com. [24.243.147.173]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5f8826420d0sm4588259eaf.12.2025.01.14.13.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jan 2025 13:03:46 -0800 (PST) From: Noah Goldstein To: libc-alpha@sourceware.org Cc: goldstein.w.n@gmail.com, hjl.tools@gmail.com Subject: [PATCH v2 3/3] x86/string: Add version of memmove with page unrolled large impl Date: Tue, 14 Jan 2025 13:03:41 -0800 Message-Id: <20250114210341.599037-3-goldstein.w.n@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250114210341.599037-1-goldstein.w.n@gmail.com> References: <20250114210341.599037-1-goldstein.w.n@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org The page unrolled version has been shown to be the best performing on Intel SnB through ICX hardware. --- sysdeps/x86/cpu-features.c | 17 +++ sysdeps/x86/cpu-tunables.c | 6 + ...cpu-features-preferred_feature_index_1.def | 1 + sysdeps/x86/tst-hwcap-tunables.c | 4 +- sysdeps/x86_64/multiarch/Makefile | 3 + sysdeps/x86_64/multiarch/ifunc-impl-list.c | 120 ++++++++++++++++++ sysdeps/x86_64/multiarch/ifunc-memmove.h | 75 +++++++---- ...ove-avx-unaligned-erms-page-unrolled-rtm.S | 5 + ...memmove-avx-unaligned-erms-page-unrolled.S | 5 + .../memmove-avx-unaligned-erms-rtm.S | 2 + ...emmove-evex-unaligned-erms-page-unrolled.S | 5 + 11 files changed, 218 insertions(+), 25 deletions(-) create mode 100644 sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-page-unrolled-rtm.S create mode 100644 sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-page-unrolled.S create mode 100644 sysdeps/x86_64/multiarch/memmove-evex-unaligned-erms-page-unrolled.S diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index 27abaca8b7..c0ecbbb812 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -877,6 +877,12 @@ init_cpu_features (struct cpu_features *cpu_features) case INTEL_BIGCORE_HASWELL: case INTEL_BIGCORE_BROADWELL: cpu_features->cachesize_non_temporal_divisor = 8; + /* Benchmarks indicate page unrolled large implementation + performs better than standard copy loop on HSW (and + presumably SnB). */ + cpu_features + ->preferred[index_arch_Prefer_Page_Unrolled_Large_Copy] + |= bit_arch_Prefer_Page_Unrolled_Large_Copy; goto default_tuning; /* Newer Bigcore microarch (larger non-temporal store @@ -890,6 +896,11 @@ init_cpu_features (struct cpu_features *cpu_features) non-temporal on all Skylake servers. */ cpu_features->preferred[index_arch_Avoid_Non_Temporal_Memset] |= bit_arch_Avoid_Non_Temporal_Memset; + /* Benchmarks indicate page unrolled large implementation + performs better than standard copy loop on Skylake/SKX. */ + cpu_features + ->preferred[index_arch_Prefer_Page_Unrolled_Large_Copy] + |= bit_arch_Prefer_Page_Unrolled_Large_Copy; /* fallthrough */ case INTEL_BIGCORE_COMETLAKE: case INTEL_BIGCORE_SKYLAKE: @@ -897,6 +908,12 @@ init_cpu_features (struct cpu_features *cpu_features) case INTEL_BIGCORE_ICELAKE: case INTEL_BIGCORE_TIGERLAKE: case INTEL_BIGCORE_ROCKETLAKE: + /* Benchmarks indicate page unrolled large implementation + performs better than standard copy loop on SKX/ICX. */ + cpu_features + ->preferred[index_arch_Prefer_Page_Unrolled_Large_Copy] + |= bit_arch_Prefer_Page_Unrolled_Large_Copy; + /* fallthrough */ case INTEL_BIGCORE_RAPTORLAKE: case INTEL_BIGCORE_METEORLAKE: case INTEL_BIGCORE_LUNARLAKE: diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c index 3423176802..d85b618311 100644 --- a/sysdeps/x86/cpu-tunables.c +++ b/sysdeps/x86/cpu-tunables.c @@ -257,6 +257,12 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp) (n, cpu_features, Prefer_PMINUB_for_stringop, SSE2, 26); } break; + case 31: + { + CHECK_GLIBC_IFUNC_PREFERRED_BOTH ( + n, cpu_features, Prefer_Page_Unrolled_Large_Copy, 31); + } + break; } } } diff --git a/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def b/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def index 0f14aaf071..5943fc1423 100644 --- a/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def +++ b/sysdeps/x86/include/cpu-features-preferred_feature_index_1.def @@ -35,3 +35,4 @@ BIT (Prefer_FSRM) BIT (Avoid_Short_Distance_REP_MOVSB) BIT (Avoid_Non_Temporal_Memset) BIT (Avoid_STOSB) +BIT (Prefer_Page_Unrolled_Large_Copy) \ No newline at end of file diff --git a/sysdeps/x86/tst-hwcap-tunables.c b/sysdeps/x86/tst-hwcap-tunables.c index 3e06048dcc..985153fb38 100644 --- a/sysdeps/x86/tst-hwcap-tunables.c +++ b/sysdeps/x86/tst-hwcap-tunables.c @@ -61,7 +61,7 @@ static const struct test_t "-Prefer_ERMS,-Prefer_FSRM,-AVX,-AVX2,-AVX512F,-AVX512VL," "-SSE4_1,-SSE4_2,-SSSE3,-Fast_Unaligned_Load,-ERMS," "-AVX_Fast_Unaligned_Load,-Avoid_Non_Temporal_Memset," - "-Avoid_STOSB", + "-Avoid_STOSB,-Prefer_Page_Unrolled_Large_Copy", test_1, array_length (test_1) }, @@ -70,7 +70,7 @@ static const struct test_t ",-,-Prefer_ERMS,-Prefer_FSRM,-AVX,-AVX2,-AVX512F,-AVX512VL," "-SSE4_1,-SSE4_2,-SSSE3,-Fast_Unaligned_Load,,-," "-ERMS,-AVX_Fast_Unaligned_Load,-Avoid_Non_Temporal_Memset," - "-Avoid_STOSB,-,", + "-Avoid_STOSB,-Prefer_Page_Unrolled_Large_Copy,-,", test_1, array_length (test_1) } diff --git a/sysdeps/x86_64/multiarch/Makefile b/sysdeps/x86_64/multiarch/Makefile index 696cb66991..381eaef455 100644 --- a/sysdeps/x86_64/multiarch/Makefile +++ b/sysdeps/x86_64/multiarch/Makefile @@ -16,11 +16,14 @@ sysdep_routines += \ memcmpeq-evex \ memcmpeq-sse2 \ memmove-avx-unaligned-erms \ + memmove-avx-unaligned-erms-page-unrolled \ + memmove-avx-unaligned-erms-page-unrolled-rtm \ memmove-avx-unaligned-erms-rtm \ memmove-avx512-no-vzeroupper \ memmove-avx512-unaligned-erms \ memmove-erms \ memmove-evex-unaligned-erms \ + memmove-evex-unaligned-erms-page-unrolled \ memmove-sse2-unaligned-erms \ memmove-ssse3 \ memrchr-avx2 \ diff --git a/sysdeps/x86_64/multiarch/ifunc-impl-list.c b/sysdeps/x86_64/multiarch/ifunc-impl-list.c index a8349775df..424031f0e6 100644 --- a/sysdeps/x86_64/multiarch/ifunc-impl-list.c +++ b/sysdeps/x86_64/multiarch/ifunc-impl-list.c @@ -133,23 +133,43 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, X86_IFUNC_IMPL_ADD_V4 (array, i, __memmove_chk, CPU_FEATURE_USABLE (AVX512VL), __memmove_chk_evex_unaligned) + X86_IFUNC_IMPL_ADD_V4 (array, i, __memmove_chk, + CPU_FEATURE_USABLE (AVX512VL), + __memmove_chk_evex_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V4 (array, i, __memmove_chk, CPU_FEATURE_USABLE (AVX512VL), __memmove_chk_evex_unaligned_erms) + X86_IFUNC_IMPL_ADD_V4 (array, i, __memmove_chk, + CPU_FEATURE_USABLE (AVX512VL), + __memmove_chk_evex_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, __memmove_chk, CPU_FEATURE_USABLE (AVX), __memmove_chk_avx_unaligned) + X86_IFUNC_IMPL_ADD_V3 (array, i, __memmove_chk, + CPU_FEATURE_USABLE (AVX), + __memmove_chk_avx_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, __memmove_chk, CPU_FEATURE_USABLE (AVX), __memmove_chk_avx_unaligned_erms) + X86_IFUNC_IMPL_ADD_V3 (array, i, __memmove_chk, + CPU_FEATURE_USABLE (AVX), + __memmove_chk_avx_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, __memmove_chk, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __memmove_chk_avx_unaligned_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, __memmove_chk, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __memmove_chk_avx_unaligned_page_unrolled_rtm) X86_IFUNC_IMPL_ADD_V3 (array, i, __memmove_chk, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __memmove_chk_avx_unaligned_erms_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, __memmove_chk, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __memmove_chk_avx_unaligned_erms_page_unrolled_rtm) /* By V3 we assume fast aligned copy. */ X86_IFUNC_IMPL_ADD_V2 (array, i, __memmove_chk, CPU_FEATURE_USABLE (SSSE3), @@ -180,23 +200,43 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, X86_IFUNC_IMPL_ADD_V4 (array, i, memmove, CPU_FEATURE_USABLE (AVX512VL), __memmove_evex_unaligned) + X86_IFUNC_IMPL_ADD_V4 (array, i, memmove, + CPU_FEATURE_USABLE (AVX512VL), + __memmove_evex_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V4 (array, i, memmove, CPU_FEATURE_USABLE (AVX512VL), __memmove_evex_unaligned_erms) + X86_IFUNC_IMPL_ADD_V4 (array, i, memmove, + CPU_FEATURE_USABLE (AVX512VL), + __memmove_evex_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, memmove, CPU_FEATURE_USABLE (AVX), __memmove_avx_unaligned) + X86_IFUNC_IMPL_ADD_V3 (array, i, memmove, + CPU_FEATURE_USABLE (AVX), + __memmove_avx_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, memmove, CPU_FEATURE_USABLE (AVX), __memmove_avx_unaligned_erms) + X86_IFUNC_IMPL_ADD_V3 (array, i, memmove, + CPU_FEATURE_USABLE (AVX), + __memmove_avx_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, memmove, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __memmove_avx_unaligned_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, memmove, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __memmove_avx_unaligned_page_unrolled_rtm) X86_IFUNC_IMPL_ADD_V3 (array, i, memmove, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __memmove_avx_unaligned_erms_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, memmove, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __memmove_avx_unaligned_erms_page_unrolled_rtm) /* By V3 we assume fast aligned copy. */ X86_IFUNC_IMPL_ADD_V2 (array, i, memmove, CPU_FEATURE_USABLE (SSSE3), @@ -1140,23 +1180,43 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, X86_IFUNC_IMPL_ADD_V4 (array, i, __memcpy_chk, CPU_FEATURE_USABLE (AVX512VL), __memcpy_chk_evex_unaligned) + X86_IFUNC_IMPL_ADD_V4 (array, i, __memcpy_chk, + CPU_FEATURE_USABLE (AVX512VL), + __memcpy_chk_evex_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V4 (array, i, __memcpy_chk, CPU_FEATURE_USABLE (AVX512VL), __memcpy_chk_evex_unaligned_erms) + X86_IFUNC_IMPL_ADD_V4 (array, i, __memcpy_chk, + CPU_FEATURE_USABLE (AVX512VL), + __memcpy_chk_evex_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, __memcpy_chk, CPU_FEATURE_USABLE (AVX), __memcpy_chk_avx_unaligned) + X86_IFUNC_IMPL_ADD_V3 (array, i, __memcpy_chk, + CPU_FEATURE_USABLE (AVX), + __memcpy_chk_avx_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, __memcpy_chk, CPU_FEATURE_USABLE (AVX), __memcpy_chk_avx_unaligned_erms) + X86_IFUNC_IMPL_ADD_V3 (array, i, __memcpy_chk, + CPU_FEATURE_USABLE (AVX), + __memcpy_chk_avx_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, __memcpy_chk, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __memcpy_chk_avx_unaligned_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, __memcpy_chk, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __memcpy_chk_avx_unaligned_page_unrolled_rtm) X86_IFUNC_IMPL_ADD_V3 (array, i, __memcpy_chk, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __memcpy_chk_avx_unaligned_erms_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, __memcpy_chk, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __memcpy_chk_avx_unaligned_erms_page_unrolled_rtm) /* By V3 we assume fast aligned copy. */ X86_IFUNC_IMPL_ADD_V2 (array, i, __memcpy_chk, CPU_FEATURE_USABLE (SSSE3), @@ -1187,23 +1247,43 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, X86_IFUNC_IMPL_ADD_V4 (array, i, memcpy, CPU_FEATURE_USABLE (AVX512VL), __memcpy_evex_unaligned) + X86_IFUNC_IMPL_ADD_V4 (array, i, memcpy, + CPU_FEATURE_USABLE (AVX512VL), + __memcpy_evex_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V4 (array, i, memcpy, CPU_FEATURE_USABLE (AVX512VL), __memcpy_evex_unaligned_erms) + X86_IFUNC_IMPL_ADD_V4 (array, i, memcpy, + CPU_FEATURE_USABLE (AVX512VL), + __memcpy_evex_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, memcpy, CPU_FEATURE_USABLE (AVX), __memcpy_avx_unaligned) + X86_IFUNC_IMPL_ADD_V3 (array, i, memcpy, + CPU_FEATURE_USABLE (AVX), + __memcpy_avx_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, memcpy, CPU_FEATURE_USABLE (AVX), __memcpy_avx_unaligned_erms) + X86_IFUNC_IMPL_ADD_V3 (array, i, memcpy, + CPU_FEATURE_USABLE (AVX), + __memcpy_avx_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, memcpy, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __memcpy_avx_unaligned_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, memcpy, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __memcpy_avx_unaligned_page_unrolled_rtm) X86_IFUNC_IMPL_ADD_V3 (array, i, memcpy, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __memcpy_avx_unaligned_erms_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, memcpy, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __memcpy_avx_unaligned_erms_page_unrolled_rtm) /* By V3 we assume fast aligned copy. */ X86_IFUNC_IMPL_ADD_V2 (array, i, memcpy, CPU_FEATURE_USABLE (SSSE3), @@ -1234,23 +1314,43 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, X86_IFUNC_IMPL_ADD_V4 (array, i, __mempcpy_chk, CPU_FEATURE_USABLE (AVX512VL), __mempcpy_chk_evex_unaligned) + X86_IFUNC_IMPL_ADD_V4 (array, i, __mempcpy_chk, + CPU_FEATURE_USABLE (AVX512VL), + __mempcpy_chk_evex_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V4 (array, i, __mempcpy_chk, CPU_FEATURE_USABLE (AVX512VL), __mempcpy_chk_evex_unaligned_erms) + X86_IFUNC_IMPL_ADD_V4 (array, i, __mempcpy_chk, + CPU_FEATURE_USABLE (AVX512VL), + __mempcpy_chk_evex_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, __mempcpy_chk, CPU_FEATURE_USABLE (AVX), __mempcpy_chk_avx_unaligned) + X86_IFUNC_IMPL_ADD_V3 (array, i, __mempcpy_chk, + CPU_FEATURE_USABLE (AVX), + __mempcpy_chk_avx_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, __mempcpy_chk, CPU_FEATURE_USABLE (AVX), __mempcpy_chk_avx_unaligned_erms) + X86_IFUNC_IMPL_ADD_V3 (array, i, __mempcpy_chk, + CPU_FEATURE_USABLE (AVX), + __mempcpy_chk_avx_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, __mempcpy_chk, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __mempcpy_chk_avx_unaligned_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, __mempcpy_chk, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __mempcpy_chk_avx_unaligned_page_unrolled_rtm) X86_IFUNC_IMPL_ADD_V3 (array, i, __mempcpy_chk, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __mempcpy_chk_avx_unaligned_erms_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, __mempcpy_chk, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __mempcpy_chk_avx_unaligned_erms_page_unrolled_rtm) /* By V3 we assume fast aligned copy. */ X86_IFUNC_IMPL_ADD_V2 (array, i, __mempcpy_chk, CPU_FEATURE_USABLE (SSSE3), @@ -1281,23 +1381,43 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, X86_IFUNC_IMPL_ADD_V4 (array, i, mempcpy, CPU_FEATURE_USABLE (AVX512VL), __mempcpy_evex_unaligned) + X86_IFUNC_IMPL_ADD_V4 (array, i, mempcpy, + CPU_FEATURE_USABLE (AVX512VL), + __mempcpy_evex_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V4 (array, i, mempcpy, CPU_FEATURE_USABLE (AVX512VL), __mempcpy_evex_unaligned_erms) + X86_IFUNC_IMPL_ADD_V4 (array, i, mempcpy, + CPU_FEATURE_USABLE (AVX512VL), + __mempcpy_evex_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, mempcpy, CPU_FEATURE_USABLE (AVX), __mempcpy_avx_unaligned) + X86_IFUNC_IMPL_ADD_V3 (array, i, mempcpy, + CPU_FEATURE_USABLE (AVX), + __mempcpy_avx_unaligned_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, mempcpy, CPU_FEATURE_USABLE (AVX), __mempcpy_avx_unaligned_erms) + X86_IFUNC_IMPL_ADD_V3 (array, i, mempcpy, + CPU_FEATURE_USABLE (AVX), + __mempcpy_avx_unaligned_erms_page_unrolled) X86_IFUNC_IMPL_ADD_V3 (array, i, mempcpy, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __mempcpy_avx_unaligned_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, mempcpy, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __mempcpy_avx_unaligned_page_unrolled_rtm) X86_IFUNC_IMPL_ADD_V3 (array, i, mempcpy, (CPU_FEATURE_USABLE (AVX) && CPU_FEATURE_USABLE (RTM)), __mempcpy_avx_unaligned_erms_rtm) + X86_IFUNC_IMPL_ADD_V3 (array, i, mempcpy, + (CPU_FEATURE_USABLE (AVX) + && CPU_FEATURE_USABLE (RTM)), + __mempcpy_avx_unaligned_erms_page_unrolled_rtm) /* By V3 we assume fast aligned copy. */ X86_IFUNC_IMPL_ADD_V2 (array, i, mempcpy, CPU_FEATURE_USABLE (SSSE3), diff --git a/sysdeps/x86_64/multiarch/ifunc-memmove.h b/sysdeps/x86_64/multiarch/ifunc-memmove.h index de0ac73a2a..6d5df8a9eb 100644 --- a/sysdeps/x86_64/multiarch/ifunc-memmove.h +++ b/sysdeps/x86_64/multiarch/ifunc-memmove.h @@ -28,18 +28,27 @@ extern __typeof (REDIRECT_NAME) OPTIMIZE (avx512_unaligned_erms) extern __typeof (REDIRECT_NAME) OPTIMIZE (avx512_no_vzeroupper) attribute_hidden; -extern __typeof (REDIRECT_NAME) OPTIMIZE (evex_unaligned) - attribute_hidden; -extern __typeof (REDIRECT_NAME) OPTIMIZE (evex_unaligned_erms) - attribute_hidden; +extern __typeof (REDIRECT_NAME) OPTIMIZE (evex_unaligned) attribute_hidden; +extern __typeof (REDIRECT_NAME) + OPTIMIZE (evex_unaligned_page_unrolled) attribute_hidden; +extern __typeof (REDIRECT_NAME) + OPTIMIZE (evex_unaligned_erms) attribute_hidden; +extern __typeof (REDIRECT_NAME) + OPTIMIZE (evex_unaligned_erms_page_unrolled) attribute_hidden; extern __typeof (REDIRECT_NAME) OPTIMIZE (avx_unaligned) attribute_hidden; -extern __typeof (REDIRECT_NAME) OPTIMIZE (avx_unaligned_erms) - attribute_hidden; -extern __typeof (REDIRECT_NAME) OPTIMIZE (avx_unaligned_rtm) - attribute_hidden; -extern __typeof (REDIRECT_NAME) OPTIMIZE (avx_unaligned_erms_rtm) - attribute_hidden; +extern __typeof (REDIRECT_NAME) + OPTIMIZE (avx_unaligned_page_unrolled) attribute_hidden; +extern __typeof (REDIRECT_NAME) OPTIMIZE (avx_unaligned_erms) attribute_hidden; +extern __typeof (REDIRECT_NAME) + OPTIMIZE (avx_unaligned_erms_page_unrolled) attribute_hidden; +extern __typeof (REDIRECT_NAME) OPTIMIZE (avx_unaligned_rtm) attribute_hidden; +extern __typeof (REDIRECT_NAME) + OPTIMIZE (avx_unaligned_page_unrolled_rtm) attribute_hidden; +extern __typeof (REDIRECT_NAME) + OPTIMIZE (avx_unaligned_erms_rtm) attribute_hidden; +extern __typeof (REDIRECT_NAME) + OPTIMIZE (avx_unaligned_erms_page_unrolled_rtm) attribute_hidden; extern __typeof (REDIRECT_NAME) OPTIMIZE (ssse3) attribute_hidden; @@ -71,40 +80,60 @@ IFUNC_SELECTOR (void) return OPTIMIZE (avx512_no_vzeroupper); } - if (X86_ISA_CPU_FEATURES_ARCH_P (cpu_features, - AVX_Fast_Unaligned_Load, )) + if (X86_ISA_CPU_FEATURES_ARCH_P (cpu_features, AVX_Fast_Unaligned_Load, )) { if (X86_ISA_CPU_FEATURE_USABLE_P (cpu_features, AVX512VL)) { if (CPU_FEATURE_USABLE_P (cpu_features, ERMS)) - return OPTIMIZE (evex_unaligned_erms); - + { + if (CPU_FEATURES_ARCH_P (cpu_features, + Prefer_Page_Unrolled_Large_Copy)) + return OPTIMIZE (evex_unaligned_erms_page_unrolled); + return OPTIMIZE (evex_unaligned_erms); + } + + if (CPU_FEATURES_ARCH_P (cpu_features, + Prefer_Page_Unrolled_Large_Copy)) + return OPTIMIZE (evex_unaligned_page_unrolled); return OPTIMIZE (evex_unaligned); } if (CPU_FEATURE_USABLE_P (cpu_features, RTM)) { if (CPU_FEATURE_USABLE_P (cpu_features, ERMS)) - return OPTIMIZE (avx_unaligned_erms_rtm); - + { + if (CPU_FEATURES_ARCH_P (cpu_features, + Prefer_Page_Unrolled_Large_Copy)) + return OPTIMIZE (avx_unaligned_erms_page_unrolled_rtm); + return OPTIMIZE (avx_unaligned_erms_rtm); + } + if (CPU_FEATURES_ARCH_P (cpu_features, + Prefer_Page_Unrolled_Large_Copy)) + return OPTIMIZE (avx_unaligned_page_unrolled_rtm); return OPTIMIZE (avx_unaligned_rtm); } - if (X86_ISA_CPU_FEATURES_ARCH_P (cpu_features, - Prefer_No_VZEROUPPER, !)) + if (X86_ISA_CPU_FEATURES_ARCH_P (cpu_features, Prefer_No_VZEROUPPER, !)) { if (CPU_FEATURE_USABLE_P (cpu_features, ERMS)) - return OPTIMIZE (avx_unaligned_erms); - + { + if (CPU_FEATURES_ARCH_P (cpu_features, + Prefer_Page_Unrolled_Large_Copy)) + return OPTIMIZE (avx_unaligned_erms_page_unrolled); + return OPTIMIZE (avx_unaligned_erms); + } + if (CPU_FEATURES_ARCH_P (cpu_features, + Prefer_Page_Unrolled_Large_Copy)) + return OPTIMIZE (avx_unaligned_page_unrolled); return OPTIMIZE (avx_unaligned); } } if (X86_ISA_CPU_FEATURE_USABLE_P (cpu_features, SSSE3) /* Leave this as runtime check. The SSSE3 is optimized almost - exclusively for avoiding unaligned memory access during the - copy and by and large is not better than the sse2 - implementation as a general purpose memmove. */ + exclusively for avoiding unaligned memory access during the + copy and by and large is not better than the sse2 + implementation as a general purpose memmove. */ && !CPU_FEATURES_ARCH_P (cpu_features, Fast_Unaligned_Copy)) { return OPTIMIZE (ssse3); diff --git a/sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-page-unrolled-rtm.S b/sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-page-unrolled-rtm.S new file mode 100644 index 0000000000..683d903243 --- /dev/null +++ b/sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-page-unrolled-rtm.S @@ -0,0 +1,5 @@ +#ifndef MEMMOVE_SYMBOL +# define MEMMOVE_SYMBOL(p,s) p##_avx_##s##_page_unrolled_rtm +#endif +#define MEMMOVE_VEC_LARGE_IMPL "memmove-vec-large-page-unrolled.S" +#include "memmove-avx-unaligned-erms-rtm.S" diff --git a/sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-page-unrolled.S b/sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-page-unrolled.S new file mode 100644 index 0000000000..57b518e16f --- /dev/null +++ b/sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-page-unrolled.S @@ -0,0 +1,5 @@ +#ifndef MEMMOVE_SYMBOL +# define MEMMOVE_SYMBOL(p,s) p##_avx_##s##_page_unrolled +#endif +#define MEMMOVE_VEC_LARGE_IMPL "memmove-vec-large-page-unrolled.S" +#include "memmove-avx-unaligned-erms.S" diff --git a/sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-rtm.S b/sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-rtm.S index 20746e6713..36e864e935 100644 --- a/sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-rtm.S +++ b/sysdeps/x86_64/multiarch/memmove-avx-unaligned-erms-rtm.S @@ -2,7 +2,9 @@ # include "x86-avx-rtm-vecs.h" +#ifndef MEMMOVE_SYMBOL # define MEMMOVE_SYMBOL(p,s) p##_avx_##s##_rtm +#endif # include "memmove-vec-unaligned-erms.S" #endif diff --git a/sysdeps/x86_64/multiarch/memmove-evex-unaligned-erms-page-unrolled.S b/sysdeps/x86_64/multiarch/memmove-evex-unaligned-erms-page-unrolled.S new file mode 100644 index 0000000000..371b454819 --- /dev/null +++ b/sysdeps/x86_64/multiarch/memmove-evex-unaligned-erms-page-unrolled.S @@ -0,0 +1,5 @@ +#ifndef MEMMOVE_SYMBOL +# define MEMMOVE_SYMBOL(p,s) p##_evex_##s##_page_unrolled +#endif +#define MEMMOVE_VEC_LARGE_IMPL "memmove-vec-large-page-unrolled.S" +#include "memmove-evex-unaligned-erms.S"