From patchwork Sat Apr 15 11:23:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1769272 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=P9M2qP88; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz9v44bcmz1yXv for ; Sat, 15 Apr 2023 21:24:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0955C385734C for ; Sat, 15 Apr 2023 11:24:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0955C385734C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681557854; bh=OTE6W6OvOhPeNAXS7Qh2wSAB+huk7IMDdqqLPSA4+hU=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=P9M2qP88BpEcngkV5lYnYThe8LstazaNDRgWUkLmrK1l6WAVvRDT0VlLBQ03N1bzQ erNe9TN4vhu5OMeZJyVdjqSbaCUix87amN9kIbT9Ehc8ABGAP7vXuYzFuJcgrlsNzV YLQ958PKglsVdtOBGBjMkktMgofWs+rY8c7LrxwU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 35E423858C2B for ; Sat, 15 Apr 2023 11:23:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 35E423858C2B Received: from stargazer.. (unknown [113.140.11.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 0E9A4660BA; Sat, 15 Apr 2023 07:23:54 -0400 (EDT) To: libc-alpha@sourceware.org Cc: caiyinyu , Wang Xuerui , Adhemerval Zanella Netto , Xi Ruoyao Subject: [PATCH 1/5] LoongArch: Add bits/hwcap.h for Linux Date: Sat, 15 Apr 2023 19:23:36 +0800 Message-Id: <20230415112340.38431-2-xry111@xry111.site> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230415112340.38431-1-xry111@xry111.site> References: <20230415112340.38431-1-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, LIKELY_SPAM_FROM, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_PASS, 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: , X-Patchwork-Original-From: Xi Ruoyao via Libc-alpha From: Xi Ruoyao Reply-To: Xi Ruoyao Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Add this file and include it from sysdep.h so we can use HWCAP bits in Glibc and/or downstream apps. --- .../unix/sysv/linux/loongarch/bits/hwcap.h | 37 +++++++++++++++++++ sysdeps/unix/sysv/linux/loongarch/sysdep.h | 1 + 2 files changed, 38 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/loongarch/bits/hwcap.h diff --git a/sysdeps/unix/sysv/linux/loongarch/bits/hwcap.h b/sysdeps/unix/sysv/linux/loongarch/bits/hwcap.h new file mode 100644 index 0000000000..50100fba61 --- /dev/null +++ b/sysdeps/unix/sysv/linux/loongarch/bits/hwcap.h @@ -0,0 +1,37 @@ +/* Defines for bits in AT_HWCAP. LoongArch Linux version. + 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 + . */ + +#if !defined(_SYS_AUXV_H) && !defined(_LINUX_LOONGARCH_SYSDEP_H) +# error "Never include directly; use instead." +#endif + +/* The bit numbers must match those in the kernel's . */ + +#define HWCAP_LOONGARCH_CPUCFG (1 << 0) +#define HWCAP_LOONGARCH_LAM (1 << 1) +#define HWCAP_LOONGARCH_UAL (1 << 2) +#define HWCAP_LOONGARCH_FPU (1 << 3) +#define HWCAP_LOONGARCH_LSX (1 << 4) +#define HWCAP_LOONGARCH_LASX (1 << 5) +#define HWCAP_LOONGARCH_CRC32 (1 << 6) +#define HWCAP_LOONGARCH_COMPLEX (1 << 7) +#define HWCAP_LOONGARCH_CRYPTO (1 << 8) +#define HWCAP_LOONGARCH_LVZ (1 << 9) +#define HWCAP_LOONGARCH_LBT_X86 (1 << 10) +#define HWCAP_LOONGARCH_LBT_ARM (1 << 11) +#define HWCAP_LOONGARCH_LBT_MIPS (1 << 12) diff --git a/sysdeps/unix/sysv/linux/loongarch/sysdep.h b/sysdeps/unix/sysv/linux/loongarch/sysdep.h index 8a2d73ec8c..782ea1ccf9 100644 --- a/sysdeps/unix/sysv/linux/loongarch/sysdep.h +++ b/sysdeps/unix/sysv/linux/loongarch/sysdep.h @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef __ASSEMBLER__ From patchwork Sat Apr 15 11:23:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1769275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Ekqibsk1; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz9vv35Pdz1yXv for ; Sat, 15 Apr 2023 21:24:59 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 624533856DC6 for ; Sat, 15 Apr 2023 11:24:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 624533856DC6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681557897; bh=nXr//S1/CA0Uqs8tU++vnc+bTmIGXDoXQ0cEAL26BVk=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=Ekqibsk17hAMwd0Xj0AGaoHvxhlg7pOfxBzxj2DAaSjwTmF+3LmrlNAVg6uFPhMaA SAzaRZUNyl8p7uUv67GojvLYsL21DHP1HvbOzYM6lXubhu/ZL3m04iu5tuMaVKqRQ2 dEdpT+34yAoxTiVNLw/YKS19VS7+HOK8r1AE5dmk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id B2D953857733 for ; Sat, 15 Apr 2023 11:23:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B2D953857733 Received: from stargazer.. (unknown [113.140.11.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id C5E8C660BB; Sat, 15 Apr 2023 07:23:56 -0400 (EDT) To: libc-alpha@sourceware.org Cc: caiyinyu , Wang Xuerui , Adhemerval Zanella Netto , Xi Ruoyao Subject: [PATCH 2/5] LoongArch: Add LOONGARCH_HAVE_UAL macro Date: Sat, 15 Apr 2023 19:23:37 +0800 Message-Id: <20230415112340.38431-3-xry111@xry111.site> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230415112340.38431-1-xry111@xry111.site> References: <20230415112340.38431-1-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, LIKELY_SPAM_FROM, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_PASS, 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: , X-Patchwork-Original-From: Xi Ruoyao via Libc-alpha From: Xi Ruoyao Reply-To: Xi Ruoyao Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" On Linux, we can determine if the CPU supports unaligned access via HWCAP. Otherwise, we conservatively assume the CPU does not support unaligned access. Maybe we should add a built-in macro for GCC to tell if -m[no-]strict-align is used, but it won't happen for GCC 12 and 13. --- sysdeps/loongarch/loongarch-features.h | 26 ++++++++++++++++ .../sysv/linux/loongarch/loongarch-features.h | 30 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 sysdeps/loongarch/loongarch-features.h create mode 100644 sysdeps/unix/sysv/linux/loongarch/loongarch-features.h diff --git a/sysdeps/loongarch/loongarch-features.h b/sysdeps/loongarch/loongarch-features.h new file mode 100644 index 0000000000..722b4b61dc --- /dev/null +++ b/sysdeps/loongarch/loongarch-features.h @@ -0,0 +1,26 @@ +/* Macros to test for CPU features on LoongArch. + 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 + . */ + +#ifndef _LOONGARCH_LOONGARCH_FEATURES_H +#define _LOONGARCH_LOONGARCH_FEATURES_H 1 + +#ifndef LOONGARCH_HAVE_UAL +# define LOONGARCH_HAVE_UAL 0 +#endif + +#endif /* loongarch-features.h */ diff --git a/sysdeps/unix/sysv/linux/loongarch/loongarch-features.h b/sysdeps/unix/sysv/linux/loongarch/loongarch-features.h new file mode 100644 index 0000000000..d4c18d3cfe --- /dev/null +++ b/sysdeps/unix/sysv/linux/loongarch/loongarch-features.h @@ -0,0 +1,30 @@ +/* Macros to test for CPU features on LoongArch. Linux version. + 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 + . */ + +#ifndef _LINUX_LOONGARCH_FEATURES_H +#define _LINUX_LOONGARCH_FEATURES_H 1 + +#ifndef __ASSEMBLER__ +# include + +# define LOONGARCH_HAVE_UAL (GLRO (dl_hwcap) & HWCAP_LOONGARCH_UAL) +#endif + +#include_next + +#endif /* loongarch-features.h */ From patchwork Sat Apr 15 11:23:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1769274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=uUuy0Opo; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz9vJ2zHBz1yXv for ; Sat, 15 Apr 2023 21:24:28 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 639433856964 for ; Sat, 15 Apr 2023 11:24:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 639433856964 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681557866; bh=Uig2CG40Pcf1FgIimHmUMstEMdipDJpVTT+XgGG6BY0=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=uUuy0OpoUvzKgl6MZ/GVUX4y5cIWNtkQxmsoaibuoyKEF6MFOF1HLbspNnv9jpewM BT1J0Vfmr3niLIxoBAkjgr52BD3TjfHf3jzGWDc+biizf4gMRHXtLXZ85VGpUrET4V mL6N9f5FX+leesTGftaVePQN9yXBHbegBVquvbiQ= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id E58733857735 for ; Sat, 15 Apr 2023 11:23:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E58733857735 Received: from stargazer.. (unknown [113.140.11.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 33876660BC; Sat, 15 Apr 2023 07:23:58 -0400 (EDT) To: libc-alpha@sourceware.org Cc: caiyinyu , Wang Xuerui , Adhemerval Zanella Netto , Xi Ruoyao Subject: [PATCH 3/5] string: stpcpy.c: Only alias __stpcpy to stpcpy if STPCPY undefined Date: Sat, 15 Apr 2023 19:23:38 +0800 Message-Id: <20230415112340.38431-4-xry111@xry111.site> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230415112340.38431-1-xry111@xry111.site> References: <20230415112340.38431-1-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, LIKELY_SPAM_FROM, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_PASS, 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: , X-Patchwork-Original-From: Xi Ruoyao via Libc-alpha From: Xi Ruoyao Reply-To: Xi Ruoyao Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" If STPCPY is defined, it's likely __stpcpy is not provided by this file anyway. So it does not make too much sense to make the alias. --- string/stpcpy.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/string/stpcpy.c b/string/stpcpy.c index dd0fef12ef..80ddf81595 100644 --- a/string/stpcpy.c +++ b/string/stpcpy.c @@ -116,6 +116,9 @@ STPCPY (char *dest, const char *src) : stpcpy_unaligned_loop ((op_t*) dest, (const op_t *) (src - ofs) , ofs); } + +#ifndef STPCPY weak_alias (__stpcpy, stpcpy) libc_hidden_def (__stpcpy) libc_hidden_builtin_def (stpcpy) +#endif From patchwork Sat Apr 15 11:23:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1769276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=CHPSL7q3; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz9w61zb1z1yZt for ; Sat, 15 Apr 2023 21:25:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39EE038555B8 for ; Sat, 15 Apr 2023 11:25:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39EE038555B8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681557908; bh=yw7BZMhKhW7NZ+3bKPE0YKL64b9ymn6DQttBCzVojKs=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=CHPSL7q3igZJ4V3vAvpC6VPr/TMnw2Cy4hLjBXYnbiwJlDqe03IIWsggcdxCVfO3a mOTHfnkK9LfLZ4Ur6vqXeetJRmm8pdRMyTtvVa/12jq7AxkVGv/5iqFGM2JYC+S9Cr Vz5nXIFKm33QDIHBOkRUWC2WHEtMK1s9WCglo+K8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id EE8C23857024 for ; Sat, 15 Apr 2023 11:24:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EE8C23857024 Received: from stargazer.. (unknown [113.140.11.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id D4E9666120; Sat, 15 Apr 2023 07:23:59 -0400 (EDT) To: libc-alpha@sourceware.org Cc: caiyinyu , Wang Xuerui , Adhemerval Zanella Netto , Xi Ruoyao Subject: [PATCH 4/5] LoongArch: Multiarch stpcpy for unaligned access Date: Sat, 15 Apr 2023 19:23:39 +0800 Message-Id: <20230415112340.38431-5-xry111@xry111.site> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230415112340.38431-1-xry111@xry111.site> References: <20230415112340.38431-1-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, LIKELY_SPAM_FROM, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_PASS, 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: , X-Patchwork-Original-From: Xi Ruoyao via Libc-alpha From: Xi Ruoyao Reply-To: Xi Ruoyao Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" When the CPU supports unaligned access, we can align the src pointer first (to avoid a segmentation fault if a small source string is located at the end of a page), then just copy the string pretending both src and dest are aligned. --- sysdeps/loongarch/multiarch/Makefile | 5 +++ sysdeps/loongarch/multiarch/stpcpy-generic.c | 25 ++++++++++++ sysdeps/loongarch/multiarch/stpcpy-ual.c | 43 ++++++++++++++++++++ sysdeps/loongarch/multiarch/stpcpy.c | 37 +++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 sysdeps/loongarch/multiarch/Makefile create mode 100644 sysdeps/loongarch/multiarch/stpcpy-generic.c create mode 100644 sysdeps/loongarch/multiarch/stpcpy-ual.c create mode 100644 sysdeps/loongarch/multiarch/stpcpy.c diff --git a/sysdeps/loongarch/multiarch/Makefile b/sysdeps/loongarch/multiarch/Makefile new file mode 100644 index 0000000000..958752bcbd --- /dev/null +++ b/sysdeps/loongarch/multiarch/Makefile @@ -0,0 +1,5 @@ +ifeq ($(subdir),string) +sysdep_routines += stpcpy-generic stpcpy-ual + +CFLAGS-stpcpy-ual.c += -mno-strict-align +endif diff --git a/sysdeps/loongarch/multiarch/stpcpy-generic.c b/sysdeps/loongarch/multiarch/stpcpy-generic.c new file mode 100644 index 0000000000..487388372f --- /dev/null +++ b/sysdeps/loongarch/multiarch/stpcpy-generic.c @@ -0,0 +1,25 @@ +/* Multiarch stpcpy for LoongArch. Generic version. + 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 + +extern __typeof (stpcpy) __stpcpy_generic attribute_hidden; + +#define STPCPY __stpcpy_generic + +#include diff --git a/sysdeps/loongarch/multiarch/stpcpy-ual.c b/sysdeps/loongarch/multiarch/stpcpy-ual.c new file mode 100644 index 0000000000..9cd13e7fef --- /dev/null +++ b/sysdeps/loongarch/multiarch/stpcpy-ual.c @@ -0,0 +1,43 @@ +/* Multiarch stpcpy for LoongArch. Unaligned access version. + 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 + +static __typeof (stpcpy) __stpcpy_unused __attribute__ ((unused)); +extern __typeof (stpcpy) __stpcpy_ual attribute_hidden; + +#define STPCPY __stpcpy_unused + +#include + +char * +__stpcpy_ual (char *dest, const char *src) +{ + /* Copy just a few bytes to make SRC aligned. It's needed not to trigger + a segmentation fault when a short string is at the end of a segment. */ + size_t len = (-(uintptr_t) src) % OPSIZ; + for (; len != 0; len--, ++dest) + { + char c = *src++; + *dest = c; + if (c == '\0') + return dest; + } + + return stpcpy_aligned_loop ((op_t *) dest, (const op_t *) src); +} diff --git a/sysdeps/loongarch/multiarch/stpcpy.c b/sysdeps/loongarch/multiarch/stpcpy.c new file mode 100644 index 0000000000..58bfb1c89d --- /dev/null +++ b/sysdeps/loongarch/multiarch/stpcpy.c @@ -0,0 +1,37 @@ +/* Multiple versions of stpcpy. LoongArch version. + 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 + . */ + +#if defined SHARED && IS_IN (libc) +# define __NO_STRING_INLINES +# define NO_MEMPCPY_STPCPY_REDIRECT +# include + +extern __typeof (__stpcpy) __stpcpy_generic attribute_hidden; +extern __typeof (__stpcpy) __stpcpy_ual attribute_hidden; + +# include +# define INIT_ARCH() + +libc_ifunc_hidden (__stpcpy, __stpcpy, + LOONGARCH_HAVE_UAL ? __stpcpy_ual : __stpcpy_generic); +weak_alias (__stpcpy, stpcpy) +libc_hidden_def (__stpcpy) +libc_hidden_def (stpcpy) +#else +# include +#endif From patchwork Sat Apr 15 11:23:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1769277 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=hXMcSAYP; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pz9ww351Dz1yZt for ; Sat, 15 Apr 2023 21:25:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B2FDB3856DF6 for ; Sat, 15 Apr 2023 11:25:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B2FDB3856DF6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681557949; bh=m/MiL9i2v0psQrleICfmgLRAgR3Am2oSpeyHnLVPBw4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=hXMcSAYP2PARcYL6uf75DtC+B2/ESuGOPUiOyDNFo7sG3eOYYHc5Y9k33IQ5DDYCK VIba9zWr3y/QrHCm2e5x7htqJpHNILDxeIAPHO4RxMNZgkvmGJM2gi3mjPrYFI1rfH VZsFwM79MQTxURCoPrN6NvfLFnMR/xhu+bZDsV+I= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by sourceware.org (Postfix) with ESMTPS id 274C6385734E for ; Sat, 15 Apr 2023 11:24:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 274C6385734E Received: from stargazer.. (unknown [113.140.11.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id AEAA266128; Sat, 15 Apr 2023 07:24:01 -0400 (EDT) To: libc-alpha@sourceware.org Cc: caiyinyu , Wang Xuerui , Adhemerval Zanella Netto , Xi Ruoyao Subject: [PATCH 5/5] LoongArch: Multiarch memcpy for unaligned access Date: Sat, 15 Apr 2023 19:23:40 +0800 Message-Id: <20230415112340.38431-6-xry111@xry111.site> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230415112340.38431-1-xry111@xry111.site> References: <20230415112340.38431-1-xry111@xry111.site> MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, LIKELY_SPAM_FROM, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_PASS, 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: , X-Patchwork-Original-From: Xi Ruoyao via Libc-alpha From: Xi Ruoyao Reply-To: Xi Ruoyao Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" When the CPU supports unaligned access, we can align the dest pointer first (this will make a better performance than solely relying on the hardware unaligned access support), then just copy the memory area word by word pretending both src and dest are aligned. --- sysdeps/loongarch/multiarch/Makefile | 3 +- sysdeps/loongarch/multiarch/memcpy-generic.c | 27 ++++++++++ sysdeps/loongarch/multiarch/memcpy-ual.c | 50 +++++++++++++++++++ sysdeps/loongarch/multiarch/memcpy.c | 39 +++++++++++++++ .../loongarch/multiarch/wordcopy-ual-inline.c | 31 ++++++++++++ 5 files changed, 149 insertions(+), 1 deletion(-) create mode 100644 sysdeps/loongarch/multiarch/memcpy-generic.c create mode 100644 sysdeps/loongarch/multiarch/memcpy-ual.c create mode 100644 sysdeps/loongarch/multiarch/memcpy.c create mode 100644 sysdeps/loongarch/multiarch/wordcopy-ual-inline.c diff --git a/sysdeps/loongarch/multiarch/Makefile b/sysdeps/loongarch/multiarch/Makefile index 958752bcbd..34e2f2a334 100644 --- a/sysdeps/loongarch/multiarch/Makefile +++ b/sysdeps/loongarch/multiarch/Makefile @@ -1,5 +1,6 @@ ifeq ($(subdir),string) -sysdep_routines += stpcpy-generic stpcpy-ual +sysdep_routines += stpcpy-generic stpcpy-ual memcpy-generic memcpy-ual CFLAGS-stpcpy-ual.c += -mno-strict-align +CFLAGS-memcpy-ual.c += -mno-strict-align endif diff --git a/sysdeps/loongarch/multiarch/memcpy-generic.c b/sysdeps/loongarch/multiarch/memcpy-generic.c new file mode 100644 index 0000000000..9374ced033 --- /dev/null +++ b/sysdeps/loongarch/multiarch/memcpy-generic.c @@ -0,0 +1,27 @@ +/* Multiarch memcpy for LoongArch. Generic version. + 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 + +extern __typeof (memcpy) __memcpy_generic attribute_hidden; + +#define MEMCPY __memcpy_generic +#undef libc_hidden_def +#define libc_hidden_def(name) + +#include diff --git a/sysdeps/loongarch/multiarch/memcpy-ual.c b/sysdeps/loongarch/multiarch/memcpy-ual.c new file mode 100644 index 0000000000..e7cd8f253b --- /dev/null +++ b/sysdeps/loongarch/multiarch/memcpy-ual.c @@ -0,0 +1,50 @@ +/* Multiarch memcpy for LoongArch. Unaligned access version. + 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 + +extern __typeof (memcpy) __memcpy_ual attribute_hidden; + +#include "wordcopy-ual-inline.c" + +#define OPSIZ (sizeof (op_t)) + +void * +__memcpy_ual (void *dest, const void *src, size_t len) +{ + unsigned long int dstp = (long int) dest; + unsigned long int srcp = (long int) src; + + /* If there not too few bytes to copy, use word copy. */ + if (len >= OP_T_THRES) + { + /* Copy just a few bytes to make DSTP aligned. Not needed with + unaligned access support, but it improves the performance. */ + len -= (-dstp) % OPSIZ; + BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ); + + _wordcopy_fwd_ual (dstp, srcp, len / OPSIZ); + dstp += len & -OPSIZ; + srcp += len & -OPSIZ; + len %= OPSIZ; + } + + BYTE_COPY_FWD (dstp, srcp, len); + + return dest; +} diff --git a/sysdeps/loongarch/multiarch/memcpy.c b/sysdeps/loongarch/multiarch/memcpy.c new file mode 100644 index 0000000000..6a3089f88c --- /dev/null +++ b/sysdeps/loongarch/multiarch/memcpy.c @@ -0,0 +1,39 @@ +/* Multiple versions of memcpy. LoongArch version. + 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 + . */ + +#if defined SHARED && IS_IN (libc) +# undef memcpy +# define memcpy __redirect_memcpy +# include +# undef memcpy + +extern __typeof (__redirect_memcpy) __libc_memcpy; + +extern __typeof (__redirect_memcpy) __memcpy_generic attribute_hidden; +extern __typeof (__redirect_memcpy) __memcpy_ual attribute_hidden; + +# include +# define INIT_ARCH() + +libc_ifunc (__libc_memcpy, + LOONGARCH_HAVE_UAL ? __memcpy_ual : __memcpy_generic); +strong_alias (__libc_memcpy, memcpy); +libc_hidden_ver (__libc_memcpy, memcpy) +#else +# include +#endif diff --git a/sysdeps/loongarch/multiarch/wordcopy-ual-inline.c b/sysdeps/loongarch/multiarch/wordcopy-ual-inline.c new file mode 100644 index 0000000000..a552aa6946 --- /dev/null +++ b/sysdeps/loongarch/multiarch/wordcopy-ual-inline.c @@ -0,0 +1,31 @@ +/* Reuse subroutine from string/wordcopy.c for LoongArch unaligned access. + 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 + +static __always_inline void _wordcopy_fwd_ual (long int, long int, size_t); +static void _nouse_1 (long int, long int, size_t) __attribute__ ((unused)); +static void _nouse_2 (long int, long int, size_t) __attribute__ ((unused)); +static void _nouse_3 (long int, long int, size_t) __attribute__ ((unused)); + +#define WORDCOPY_FWD_ALIGNED _wordcopy_fwd_ual +#define WORDCOPY_BWD_ALIGNED _nouse_1 +#define WORDCOPY_FWD_DEST_ALIGNED _nouse_2 +#define WORDCOPY_BWD_DEST_ALIGNED _nouse_3 + +#include