From patchwork Tue Feb 7 00:16:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 64392 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 C03D73858C30 for ; Tue, 7 Feb 2023 00:19:33 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 0A0B03858C30 for ; Tue, 7 Feb 2023 00:16:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0A0B03858C30 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu Received: by mail-wm1-x32c.google.com with SMTP id u10so6852981wmj.3 for ; Mon, 06 Feb 2023 16:16:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; 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=eV8w4DflMjsQTeC9E4djYSCYGafIxUSYc+n8bY0TA7E=; b=X2/ud9M4il3ziufQ4XrAAsoClgQ9zkoAF/yQPDGWpGa1vlBxkjcwv/rCo0rHjDDI0L dcNEfoIaGZW1J1CRScd+QWuW6Wmb0QxcI2kRJw/8UjPe4ClpZ7uGJMDgySGNZtNdosY9 wRyCVyfxCl7/ucamBS3zDcKAKLC6LprpZ6MiLBwG8GUFGz7nAxnG4HQhTTryC33A3mJu 7lv+bXX4msdtztmXD9WqFJdlqTVHcuV2qHOOPQA8o3+xUqvjZxzL2WCaRnhibm+6p4h4 6fpbOfsj5rJeabMpqxPN8dMs9/5EEWeDEmo5UxsGOsZpkPrkLm4dM+DoBimg/MNO8USB z1hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=eV8w4DflMjsQTeC9E4djYSCYGafIxUSYc+n8bY0TA7E=; b=VvpwJWJJpa/U3XX7SJzWpXpCcayIy6sWaM1PnSE3t0ctKLwrXfH0dUxoCF/3aEnAQx BPtxi3baD9fnFg39TaQPM/FCTq8hMxjkw/oxOr7y6E2jZ6/PNjYXmM4IDKzhRgC3NcwI MoFpt5CSOzjdR2DFMgazLgDh+9Ljkkly77uGvANSsNR6YMAycGkJ9qhyMEPtql/7m6yL kTLUXgQWRJ/gp8AGwuSqb4TPgNZY4u/YWbOJbwCfbdI6bzD2LiZKG7lm6GdIKvum9HpO cnGpOgR8YIIUL1YqGe+2fAHj0OiEnZH3PCRmKqLZfKLc07xxDjQ8zHl6LsquyCFNRvXx yDxQ== X-Gm-Message-State: AO0yUKVK2fn4XHc7yuotcIkyrqZfVqVowaJObe7JCD6MpZ7oQSYtWfLz 2XLmg5pSjs+qBDzRPKE23DRZmLfTJGw/fTs7 X-Google-Smtp-Source: AK7set+5mN9m+VgpZHeS6tq76FujDZCB2IRPPYCMrAF8ggEM1ATjgSXttSJnnwyJoq1BjFIStyltLA== X-Received: by 2002:a05:600c:2ac8:b0:3c6:e61e:ae71 with SMTP id t8-20020a05600c2ac800b003c6e61eae71mr1380621wme.1.1675729006298; Mon, 06 Feb 2023 16:16:46 -0800 (PST) Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id f1-20020a1cc901000000b003df14531724sm16862050wmb.21.2023.02.06.16.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 16:16:45 -0800 (PST) From: Christoph Muellner To: libc-alpha@sourceware.org, Palmer Dabbelt , Darius Rad , Andrew Waterman , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law , Philipp Tomsich , Heiko Stuebner Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [RFC PATCH 11/19] riscv: Add ifunc support for memcpy/memmove Date: Tue, 7 Feb 2023 01:16:10 +0100 Message-Id: <20230207001618.458947-12-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230207001618.458947-1-christoph.muellner@vrull.eu> References: <20230207001618.458947-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_MANYTO, 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 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 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 Sender: "Libc-alpha" From: Christoph Müllner This patch adds ifunc support for calls to memcpy() and memmove() to the RISC-V code. No optimized code is added as part of this patch. Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/Makefile | 2 ++ sysdeps/riscv/multiarch/ifunc-impl-list.c | 6 ++++ sysdeps/riscv/multiarch/memcpy.c | 40 +++++++++++++++++++++++ sysdeps/riscv/multiarch/memcpy_generic.c | 32 ++++++++++++++++++ sysdeps/riscv/multiarch/memmove.c | 40 +++++++++++++++++++++++ sysdeps/riscv/multiarch/memmove_generic.c | 32 ++++++++++++++++++ 6 files changed, 152 insertions(+) create mode 100644 sysdeps/riscv/multiarch/memcpy.c create mode 100644 sysdeps/riscv/multiarch/memcpy_generic.c create mode 100644 sysdeps/riscv/multiarch/memmove.c create mode 100644 sysdeps/riscv/multiarch/memmove_generic.c diff --git a/sysdeps/riscv/multiarch/Makefile b/sysdeps/riscv/multiarch/Makefile index 6e8ebb42d8..6bc20c4fe0 100644 --- a/sysdeps/riscv/multiarch/Makefile +++ b/sysdeps/riscv/multiarch/Makefile @@ -1,5 +1,7 @@ ifeq ($(subdir),string) sysdep_routines += \ + memcpy_generic \ + memmove_generic \ memset_generic \ memset_rv64_unaligned \ memset_rv64_unaligned_cboz64 diff --git a/sysdeps/riscv/multiarch/ifunc-impl-list.c b/sysdeps/riscv/multiarch/ifunc-impl-list.c index e878977b73..16e4d7137f 100644 --- a/sysdeps/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/riscv/multiarch/ifunc-impl-list.c @@ -35,6 +35,12 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, size_t i = 0; + IFUNC_IMPL (i, name, memcpy, + IFUNC_IMPL_ADD (array, i, memcpy, 1, __memcpy_generic)) + + IFUNC_IMPL (i, name, memmove, + IFUNC_IMPL_ADD (array, i, memmove, 1, __memmove_generic)) + IFUNC_IMPL (i, name, memset, #if __riscv_xlen == 64 IFUNC_IMPL_ADD (array, i, memset, 1, __memset_rv64_unaligned_cboz64) diff --git a/sysdeps/riscv/multiarch/memcpy.c b/sysdeps/riscv/multiarch/memcpy.c new file mode 100644 index 0000000000..cc9185912a --- /dev/null +++ b/sysdeps/riscv/multiarch/memcpy.c @@ -0,0 +1,40 @@ +/* Multiple versions of memcpy. RISC-V version. + Copyright (C) 2022 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 + . */ + +/* Define multiple versions only for the definition in libc. */ + +#if IS_IN (libc) +/* Redefine memcpy so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef memcpy +# define memcpy __redirect_memcpy +# include +# include +# include +# include + +extern __typeof (__redirect_memcpy) __libc_memcpy; +extern __typeof (__redirect_memcpy) __memcpy_generic attribute_hidden; + +libc_ifunc (__libc_memcpy, __memcpy_generic); + +# undef memcpy +strong_alias (__libc_memcpy, memcpy); +#else +# include +#endif diff --git a/sysdeps/riscv/multiarch/memcpy_generic.c b/sysdeps/riscv/multiarch/memcpy_generic.c new file mode 100644 index 0000000000..fb46fe7622 --- /dev/null +++ b/sysdeps/riscv/multiarch/memcpy_generic.c @@ -0,0 +1,32 @@ +/* Memcpy for RISC-V, default version for internal use. + Copyright (C) 2022 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 + +#define MEMCPY __memcpy_generic + +#ifdef SHARED +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(name) \ + __hidden_ver1(__memcpy_generic, __GI_memcpy, __memcpy_generic); +#endif + +extern void *__memcpy_generic(void *dest, const void *src, size_t n); + +#include diff --git a/sysdeps/riscv/multiarch/memmove.c b/sysdeps/riscv/multiarch/memmove.c new file mode 100644 index 0000000000..581a8327d6 --- /dev/null +++ b/sysdeps/riscv/multiarch/memmove.c @@ -0,0 +1,40 @@ +/* Multiple versions of memmove. RISC-V version. + Copyright (C) 2022 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 + . */ + +/* Define multiple versions only for the definition in libc. */ + +#if IS_IN (libc) +/* Redefine memmove so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef memmove +# define memmove __redirect_memmove +# include +# include +# include +# include + +extern __typeof (__redirect_memmove) __libc_memmove; +extern __typeof (__redirect_memmove) __memmove_generic attribute_hidden; + +libc_ifunc (__libc_memmove, __memmove_generic); + +# undef memmove +strong_alias (__libc_memmove, memmove); +#else +# include +#endif diff --git a/sysdeps/riscv/multiarch/memmove_generic.c b/sysdeps/riscv/multiarch/memmove_generic.c new file mode 100644 index 0000000000..4a9e83c13c --- /dev/null +++ b/sysdeps/riscv/multiarch/memmove_generic.c @@ -0,0 +1,32 @@ +/* Memmove for RISC-V, default version for internal use. + Copyright (C) 2022 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 + +#define MEMMOVE __memmove_generic + +#ifdef SHARED +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(name) \ + __hidden_ver1(__memmove_generic, __GI_memmove, __memmove_generic); +#endif + +extern void *__memmove_generic(void *dest, const void *src, size_t n); + +#include