From patchwork Mon May 27 11:18:46 2024 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: 1939863 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=Ven0DEL1; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntVY3ZnZz20PT for ; Mon, 27 May 2024 21:20:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A17F73858417 for ; Mon, 27 May 2024 11:20:35 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 634383858D34 for ; Mon, 27 May 2024 11:19:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 634383858D34 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 634383858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808756; cv=none; b=vehMAhVqQrEZtqq7fPkr0/TZe5JyXvg/ji7paMVFfYsaXSQV71+IT9euvYIrqvXLVxzyTaOWiwLMBPpnQyJJw2AmEEoNK5KyY8Cma+v44s1UDO1uniqHqC8cZ2btzQ8fGPgzoD6UaF4B8BwQxamn4uaGTe4ZQu0pKB1DdHm7hyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808756; c=relaxed/simple; bh=cp0/e6tjuPkpwzMPtEjgYHEdKWYV2SJn/zRjpdxFE7E=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QFTscXqJfV7AbvKpwUfCdwhoZApL8G97NRnbzWEgXBWTkvhuNI5Cu5TIsiE0ZCKxnUGrwFXtqDmGznE9TFKjyWH2HBA4Lz+JOThFnVjA4GEGBtS9KZmLPTcyS+z2o2/KbaMBhMNmjyx2RWEXEb9iVt0qE/H/VsJXfL1WU7eL/XQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-52742fdd363so4583860e87.1 for ; Mon, 27 May 2024 04:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808751; x=1717413551; 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=GP34uPH5EEjBCGq1IdwqaDHpXE6DdMJq8pG7aGC61/Q=; b=Ven0DEL1kkE39EiwHa1ENB6RQC4K/9D4iaGfo9uSUUFl4oCjuX8JBler2brv0nEeXr e7RaYpoaCoM9e0+q6XUrKE2uhB4JLDEaVe3R9msdaR/yoF7F7JUzkNjqz1qIGzqqfXPw qA6td7lE195R9ONLr7S/4MDaaqAgsxk5xjn+kw9L+/VhAgk+ufCBRklmWSx6ICSym046 DK03e16lQSFXvH2ACLP/ZJ6D5vFA3AjzC1VZyXM4mRknhdAOpZVmm9NuvlL6HqRxoC9G J+F2ukjXpi8WKnlbFbP7BG05nsTvSV1ae4uZOeNCTrtuDRelhZ1lYtIJhTfC5QPNWNMT T5iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808751; x=1717413551; 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=GP34uPH5EEjBCGq1IdwqaDHpXE6DdMJq8pG7aGC61/Q=; b=exOAWlsLO613oI6MgBrvim7zxfzz6OlE74Rb3/x80+/FVWSx+buThZ+/3Dezg6OSoj esOsBoKHSTRwdyZB95O9Zd46H+9On5EvzkkEnhGM8+alNcmEkMrqVz6kg0AffVM0NyZn j1R/nozbglGNQjqhTaXtD2yyk3RTqJ66vOlC5A8IA2OXQ5OmHzKwYhVvP1eZQuMCGYnS CyW07pVoQOZ+JD51uphklmIa087ab/XPGyn601p/36PlWg4aNMPRQ9+mpch061jb3x/x OZTaXwtlbz9ve4qE5l0fijWltLagoj74sD66mpSzFIopskRvT9SiSzjeCHv2Ivglkssw otjw== X-Gm-Message-State: AOJu0Yzq4yfXSrp0iNQqf7UP/Gl4vBOP4F1Yc6r2082UhKnIeNugTdUR 6yCPaPccEkC1cMx1i4StuyBvpSvDSmjPAKLtbKDOdK5Nhl2qApQ5Tgkqpfa9V0PVF7QvsF0Y4Dt 9rrg= X-Google-Smtp-Source: AGHT+IG3CINv6tG8+4xu4gucse5MU8P4527lOjuXLxJNzcQ+O0pMZiUzffxaL42rn7oaYWyWrNMpyA== X-Received: by 2002:ac2:4899:0:b0:528:33c7:4097 with SMTP id 2adb3069b0e04-529665cf483mr5353710e87.49.1716808751409; Mon, 27 May 2024 04:19:11 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:10 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 01/15] cdefs: Add mechanism to add attributes to __always_inline functions Date: Mon, 27 May 2024 13:18:46 +0200 Message-ID: <20240527111900.1060546-2-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org Contrary to LLVM, GCC does not propagate function attributes accross inlined functions ("target specific option mismatch"). To overcome this limiation, this patch introduces a __CODEGEN_ATTRIBUTE macro, which can be used to add function attributes to __always_inline functions. Signed-off-by: Christoph Müllner --- misc/sys/cdefs.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index ab9620bd0d..91dceab1f2 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -587,15 +587,19 @@ #endif /* Forces a function to be always inlined. */ +# ifndef __CODEGEN_ATTRIBUTES +# define __CODEGEN_ATTRIBUTES +# endif #if __GNUC_PREREQ (3,2) || __glibc_has_attribute (__always_inline__) /* The Linux kernel defines __always_inline in stddef.h (283d7573), and it conflicts with this definition. Therefore undefine it first to allow either header to be included first. */ # undef __always_inline -# define __always_inline __inline __attribute__ ((__always_inline__)) +# define __always_inline __inline __attribute__ ((__always_inline__)) \ + __CODEGEN_ATTRIBUTES #else # undef __always_inline -# define __always_inline __inline +# define __always_inline __inline __CODEGEN_ATTRIBUTES #endif /* Associate error messages with the source location of the call site rather From patchwork Mon May 27 11:18:47 2024 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: 1939860 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=kTtYC7dh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntV25mHCz20Pb for ; Mon, 27 May 2024 21:20:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 138FF3858C31 for ; Mon, 27 May 2024 11:20:08 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 756B03858D35 for ; Mon, 27 May 2024 11:19:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 756B03858D35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 756B03858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808766; cv=none; b=EEBh0m/dAlQyYZkSP7aOGBUkCwbgelT4qr4txC1p2eDxcKR5E1eWN7X8eCvBKs9awPt6JXpLWe4ykRWOfDgoWa+/xxi4p5k9poBpGyvyirHWjeZSW2RheoWBK+f7TzDfG0bBKfUf+MpSz4UF5zpWGJmHAnTl9S1UWPfH25QlTSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808766; c=relaxed/simple; bh=aVlOIHxMr1jkDM8dvn9KawXWe4YzlWQnzNvwFzDAJcI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=OKAOq1M9uGLSej0lwKtySlHHQc2OPkTfiSXawcG/d17fxvQ9isLG21szqJyNlM6QG6wXGPhCRfOxDFsPXL1GwMkypTFyI15ymS8I/QJL51ji5ROZ6nm5fUMJnI7Y2Do5qhu1L2JWnjSQXzey/zvDxnlyONAPRtnVBEROmCLBxmw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-529b22aabc1so644093e87.2 for ; Mon, 27 May 2024 04:19:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808753; x=1717413553; 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=ZAPcY9aUptcItGUKytlnrIEEiovnYZvNLeZqEWSxHrU=; b=kTtYC7dh3jvx2nLG942ZNQHCHwjs4hHy5aa1DKm6Ilnq8WEKOo8Nv7FlA+ooWsUb5d XAQ3U7SahkrX/6DW9iNgIPZgrK0x+7Q2xajcc/bEdTHQUerEraWoqZO75QiZgavt5qNX Pi906nVLUjcK3WEd4J4bMDtQG1HW58RZZfdrLEvWtOoX3wCubeQQpaDkWKYtSy+QptCA NEm1xmsy7EvuZr28S9Sx0xZNrxr4N97k8CT5D9wLnaYGTSqQlkmzzW8fxqrsS8eMFOMw IW6GFzOFJjxdZuQCllxEsl1T/wRpAUlXub//pO6rCOUnBnx7hv9RjBkyGbjVSAgtUJrH OJug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808753; x=1717413553; 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=ZAPcY9aUptcItGUKytlnrIEEiovnYZvNLeZqEWSxHrU=; b=HAz9W0320a2JxoydUIHYB9gwBPHu5vHqxnuH6Ptq+dkWPqYnya+AbyIAljFKSzo5GE dwJdIL7D3PNePg/1Ef/3Hpg614kyye3zCX++jMrA2vJwMYLI/iZUBVkd5csgTA09922x f0cnBON+3eilqkleDQC6T3H3mJvzen8F+KPt/EE9wOdkXPPsEWt0jPkQAMO9RDfBS5+A fW4gW2c7C0BMszS0sFJgxwl63v7AMmkmOFs9QGkyDD2yv9jsEOxVBSXSLsZEQ8ynBU63 z+1HUHtot3tnnF0SLcvHkcoetOIm8vdlSR5meed9/N5/cDeubsicdL1pgDoZrl14awtW ESBg== X-Gm-Message-State: AOJu0YzzOCSpHhW9MIZHp/KI1H4EhVu1F2P6Xe2RVZ40RODy676gs4GT Kx/pEzFT+cKBKJC5mBg8VOp3Cz/YUkXtPWpWz4ESMQKyIdnM7FXtVCSXBdAoIuM7jmwy8wzp46j 2/eI= X-Google-Smtp-Source: AGHT+IGbZy36uDVGrXPBcl1eW5hD2s6+xf2b8LhfJoFlJngywWPCRlWBp1MFaA01BOPuIMVh7wFK4w== X-Received: by 2002:a19:9148:0:b0:523:bbf5:4b36 with SMTP id 2adb3069b0e04-529646df136mr4291323e87.20.1716808753206; Mon, 27 May 2024 04:19:13 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:12 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 02/15] string/memchr: Add mechanism to set function attributes Date: Mon, 27 May 2024 13:18:47 +0200 Message-ID: <20240527111900.1060546-3-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-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, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org This patch introduces the __CODEGEN_ATTRIBUTES macro which can be used to set function attributes when building the code. Signed-off-by: Christoph Müllner --- string/memchr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/string/memchr.c b/string/memchr.c index 08b5c41667..a2bcd0419e 100644 --- a/string/memchr.c +++ b/string/memchr.c @@ -29,6 +29,10 @@ # define __memchr MEMCHR #endif +#ifndef __CODEGEN_ATTRIBUTES +# define __CODEGEN_ATTRIBUTES +#endif + static __always_inline const char * sadd (uintptr_t x, uintptr_t y) { @@ -36,6 +40,7 @@ sadd (uintptr_t x, uintptr_t y) } /* Search no more than N bytes of S for C. */ +__CODEGEN_ATTRIBUTES void * __memchr (void const *s, int c_in, size_t n) { From patchwork Mon May 27 11:18:48 2024 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: 1939869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=hOiwOcr/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntWR2WJfz20PT for ; Mon, 27 May 2024 21:21:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9FCF53858289 for ; Mon, 27 May 2024 11:21:21 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id AA1253858D39 for ; Mon, 27 May 2024 11:19:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AA1253858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AA1253858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808762; cv=none; b=ryyZRJsYIa88BHEJKSAlWP9Se9KQOsjYV4NC9gSefiBESh3P6YTeb0CvVoqmysp9iiEi6aE5YMiHDN95SniQtBstKWJSbZGKgrS74voJedEVO/BFN7sEXBKIVr7bPKkYg42iVtvf8xMN/SxsDEfcbv2l77riHDoa0gJsl6Le1rM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808762; c=relaxed/simple; bh=AuVKpT03lKTweqZOYNEQiaNOB0EPZ/A9CxB6XGk6WW4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tZEr7Ql/2UbTung1JBlR2DzduSqc4syTMZ5YfczGzlWI0SOg+xSSl/7Wlg4k2rZosYdDeQTGBdwy9pvyOZF9Ua0D4F+BJ2bY2PWWCRLW/fLLZlxW8Z9nsh8OKg7fr9spPXLXxQvTrjvu+szdg+T3Pc+HOnLVhK3pB3qtbejAeRE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-529aa4e988aso1783766e87.0 for ; Mon, 27 May 2024 04:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808755; x=1717413555; 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=wgzRCgTJUSfB9wSON9FiDdkEMqqbK5ZqvchzlimgWNk=; b=hOiwOcr/mDqUD3RWjB9ZsYzuOn757zC78kkFpC4eO7wLHBIZP0v8xV7GCQ/IkWA5uc c7rRQ/zqglIKTG7RqEPMLeL39aRv8ufP+BuJkZ6/hlbMZ8GCROUCcMvRsq/dsZki8PRg jNcdmr+ZLaE1xfZm/jZ77I8ntTmNKlzSXuUO4GBHZLnZ8hPWj29adVN5xQ7s623LosYC wIstBk8bIAmBp9r8dhMGglKSVGlT8GpISrghGP6tzVzw24Yhsqao0g1q31xkzafsQ5Dj 2ljeX3gURovTsmJmDrR3N6zecj3kB/J+Go7hHiWlW2LpcJr4N966xYlQ/shAYxlov/y/ nmNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808755; x=1717413555; 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=wgzRCgTJUSfB9wSON9FiDdkEMqqbK5ZqvchzlimgWNk=; b=B8qJd7eezH5PAE8tbekLK0Z9ciARYqAqgAhnFfPUjTJndNdrPrzHg2rqho9h6gaTlN 1qKsToS6ZmJHK3slkTTb8rsG0087VMWMW0k1hlGKzsn4szL+dljvU7Es2JVpzEES2j2R U9v60OZaIswPSVnyQq1SRufJzPhXc8tl+U/w+7roiAY3ioAl3GIV6a3FASYEARLen2wA YBFr72kJBxOrhblMXeDBsbhZkvhA6Ts5QQR2+nePPiJngI3j1KmkQeiFnYNKQhsWDVr+ ou1k5jFPzZm3VE3j+dAVwDl8peZ4oRH+pPXvnJmiLrnvsCcPZXM6l0LJXgN2UfnnIu88 URSg== X-Gm-Message-State: AOJu0YyvCKDvOOkG0Y/7Boa2X1bg4Rlu2bMrydJBU1Ph0Lfhr8JIf07m W8InBpiWJhVXU4vuon+7XkXEiOj+5bebMyJrb57BarA3KQUm5NQ5my74UDR/NpCcHc0bJh8LRWA ajBs= X-Google-Smtp-Source: AGHT+IH+0FlukPPdNWlpUlAOmMCNfomQlC8mlvG0Tv1qE8oK2kGlsE4uXbU2VseS2A81+GvDBGWlUQ== X-Received: by 2002:a05:6512:3994:b0:522:2a2c:759e with SMTP id 2adb3069b0e04-5296420479emr6639665e87.6.1716808754922; Mon, 27 May 2024 04:19:14 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:14 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 03/15] string/memrchr: Add mechanism to set function attributes Date: Mon, 27 May 2024 13:18:48 +0200 Message-ID: <20240527111900.1060546-4-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org This patch introduces the __CODEGEN_ATTRIBUTES macro which can be used to set function attributes when building the code. Signed-off-by: Christoph Müllner --- string/memrchr.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/string/memrchr.c b/string/memrchr.c index 6511dac591..129fa9a681 100644 --- a/string/memrchr.c +++ b/string/memrchr.c @@ -30,6 +30,11 @@ # define __memrchr MEMRCHR #endif +#ifndef __CODEGEN_ATTRIBUTES +# define __CODEGEN_ATTRIBUTES +#endif + +__CODEGEN_ATTRIBUTES void * __memrchr (const void *s, int c_in, size_t n) { From patchwork Mon May 27 11:18:49 2024 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: 1939859 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=IusowYiF; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntTl2dhwz20KL for ; Mon, 27 May 2024 21:19:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 593E53858C39 for ; Mon, 27 May 2024 11:19:53 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id AAA6F385840D for ; Mon, 27 May 2024 11:19:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AAA6F385840D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AAA6F385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::22d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808762; cv=none; b=nbimSmbq6dbkw6hLjvBvipJPxs92CCWpKJYKsHGumHN5vnC+YE55ykRfAnVQg8tEscDX3e2jLVtE0IeXk9HBzvlEwnD49AtAEBc76hLgN9VGywAKwKkwCHZBvUJ5Wf5gGpSJRlzMv0l6HSv2eqhDzoAqeytszq6pe7q9HepwDIY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808762; c=relaxed/simple; bh=HUo6dLA7i2gLVgv5j2/HyYQlRKpUm0QX5pASbgK12bI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Xk/6HeVj5zF6+EImKw37PomUPTsG9M0GocKLZlRkY1n0QG6tL5VyhB3VYTWBg49ONQeJJEZGezxK5k2zTXq7cQgh3wKkUThmRvP/DY72SP4IO3ETTy8h2O3Mt5532jOMDGNBZfq6dRSh0cBnRxWs4W4Yk0HqQKXa/307G9Q8bdM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x22d.google.com with SMTP id 38308e7fff4ca-2e96f29884dso14137361fa.0 for ; Mon, 27 May 2024 04:19:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808757; x=1717413557; 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=3YklGTP7CP07LSTwp4r033wxnlt1eTepOlLSvQ/z2qQ=; b=IusowYiFiRVInpDIo7hN1tFdiKTI9/S6iIZSjIlkCtpP6SxFwv7jM77pELpuCFoTZe stbyFkQAm5lHEi5CdE0MbNG6uPnnoQph00OgtVs6xWZm+0I+ZyKtNzy+d+LgMxR2M1UB cZ+Qu7nZe0NUGP46YKwZp09z/0UST9nqy1tDsxsZ/HSW/rm6C/+mA8yAztjz0sX+CRUc 6hFyATOLQnnG26yyW8sWYr/hIe/DnqcQQrkZZ4xb5WnS/qoti4cOBTkdxNGouQkR5MQO LDvJmFnqqlN2+lgyYyHQoSYrZo5EugDPtIau/Ie1HRbEgJIcP+sftirXCHDZPKvVuhVT T4Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808757; x=1717413557; 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=3YklGTP7CP07LSTwp4r033wxnlt1eTepOlLSvQ/z2qQ=; b=NgV8dgqeXahN1ypLTGCgcOdWznDmXfG9nn4Kng6VrU6kxk+VH2l/EdOVldo5rgPPqJ rthiEUDCLMa16IgMTNHR+6YHG9205qw4KGVW709a+/CeDITbGS1EQWvvHSVeVchpdZdz Y8Qn6jtvuvrxyK01BpRuDObXIWFzCLUAH13sDFjVkyQVlXpUZ+aQVURVKweDuqkTQasE SmfFLxePUMcyulObta2kQ31k7nDVQmcyURrVZPVfTI2c+p0t6knSoMJzpzyHYbwLkDWZ FfH0dXZxPX6ENTT0OwyZ1SK2F7fAAva/npRN83QJjhC9F+Sf66VyUOIp0yZ6zU1HwduA 26vA== X-Gm-Message-State: AOJu0YwFvVUq7oGzPm3KN8p6Favjfr1TYmoq2KRWWyFYuO7EjnAShML7 PT3PtUqhh1+lJAMMdnYq9JVXXXRII2uP4O0yUZZ9qrSLCh3QlDZ8DOkiuGPNXG/Aels0F0zV7jJ oI9CK9w== X-Google-Smtp-Source: AGHT+IGNY5Ufpfr45r2I5iqNZb0eqbQUqPHdCmSCzCv6m01YG4blBB2EMgPm9BcICLI+cWXuSvIAzw== X-Received: by 2002:a05:6512:3498:b0:523:8702:7855 with SMTP id 2adb3069b0e04-52964aba87amr5266025e87.21.1716808756679; Mon, 27 May 2024 04:19:16 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:16 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 04/15] string/strchrnul: Add mechanism to set function attributes Date: Mon, 27 May 2024 13:18:49 +0200 Message-ID: <20240527111900.1060546-5-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org This patch introduces the __CODEGEN_ATTRIBUTES macro which can be used to set function attributes when building the code. Signed-off-by: Christoph Müllner --- string/strchrnul.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/string/strchrnul.c b/string/strchrnul.c index f64d52ea67..feff66dddf 100644 --- a/string/strchrnul.c +++ b/string/strchrnul.c @@ -29,7 +29,12 @@ # define __strchrnul STRCHRNUL #endif +#ifndef __CODEGEN_ATTRIBUTES +# define __CODEGEN_ATTRIBUTES +#endif + /* Find the first occurrence of C in S or the final NUL byte. */ +__CODEGEN_ATTRIBUTES char * __strchrnul (const char *str, int c_in) { From patchwork Mon May 27 11:18:50 2024 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: 1939872 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=cGr+c0Qv; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntXD5ZBgz20Pb for ; Mon, 27 May 2024 21:22:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1986438708F3 for ; Mon, 27 May 2024 11:22:03 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id 5B7603858C31 for ; Mon, 27 May 2024 11:19:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B7603858C31 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5B7603858C31 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808762; cv=none; b=UHQJlrjGqr+dRNR51I+h740rKML9mcwq8Jr2TCG3cj2Mv7jKjdzIv9PCfTGy3JSsPjWAvK90s1yUjViZxgcJoXd9Lc87FZ8cRid3hVw0vmWufO+enhT6qM5EP0yWjsmjiH7WhmQ2UaXM7u9eqxh9IFjh8mIBgpR1y4+G3LuDEzs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808762; c=relaxed/simple; bh=S1t6qqpPLTjN6wom1DriYPntWh6jicbH6flsV77jsF8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dNz+Qiis9S0NDEbuEEy6CrhUxZZfPSuQ9XnlxT0QDwpe1wCvJsScVuOewjYmgts3eE/xOAaLVZ4Ld4ZMveQiiHJPVkBhubZ4YNfPfSH73PCbdvPyzUgAS9GdRGGa6XmZJexLVpjOX3Sa6svY/3ZgZBMAtI7ux+Sblp3n2RNgJjg= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-52449b7aa2bso8475708e87.3 for ; Mon, 27 May 2024 04:19:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808758; x=1717413558; 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=LVEFekLBL2gbkV7F9/f8RGDMXRefy1uwUmkhCG1YCNU=; b=cGr+c0QvqE60QGm3Zvpl0UW6YM5D7FF0GcWX1byKZD+h0GalEEP7uz4sH509Qm1opw Iypo+nmzY8yX4+eexZLRVNKifVB0kO9dEv6gCZIP0m02GkgyM+vaGuZdefgZqFWmVB2H 7AdZa858vfdljOfERLXUDKYlCafAoVyGVg8gW/+QxZb7xle1ChZ86pye4dBe56RBiJZi ma42clxfcayR24MvPd2Yb4rTeqhJ9rsvh0JxGjv8dN6KhyoDVrfqjdCv31dbLsng2cmL 7oUaxIL5N+66ENmg0SA+oeTxSVZvu1xm1Cs23gTKLRNUashMRez5GoJI321ngJGTjv9T Bi5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808758; x=1717413558; 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=LVEFekLBL2gbkV7F9/f8RGDMXRefy1uwUmkhCG1YCNU=; b=V+Xl+q+WUxYtvPKNY5nAflREW1IzvaHlsu5q+PyO4g6wXe4fKS7WoaUWFZWj0Wwzba q385ajF+PWNuf3BhdjsGZghFKR0oAvsMCJ4dyY/dfQJ2uVpi3vMDtpHlxwjRxsT3f6pF jgB6DO0BGpoFrXQTiVy0a7V8cuMxyvEqQuBlIXhwWYCJ9TmY2RThWhFHbu2whFZPXRh1 13CmcGvXqvdwewwC3rT2Qb26ws1h+KSZjYGQA2vfgme/mu4B4f7UEFje+ZHGN68XYBKr TrgMtNwC+q6fg/UKdL1f4IsXDdI97R8yCMK42A0rkxb58dfdsfybbviech5OQB/2V2Dx pTlg== X-Gm-Message-State: AOJu0YzHe7e1amrqXg9Zs8zgWL6QDFqCmzrTZskKsXKdurRaOsRluhnY mKsev7S+D3ROQNN4dmI63aQtN/JHBlDFn/mqoTkSvAeVhYA59pAXx20OuLYbjvBw1lmvebAgIhj eL39BZA== X-Google-Smtp-Source: AGHT+IFaw8/EaBAnvwa1SJY6LN9rPjR4xwnpdAzbgaojsB9Y+yb+DE/Na4w9/vkEcyF+bIcUuNXPVw== X-Received: by 2002:a05:6512:3d1d:b0:529:a0fd:a257 with SMTP id 2adb3069b0e04-529a0fdb25emr7304755e87.54.1716808758476; Mon, 27 May 2024 04:19:18 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:17 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 05/15] string/strcmp: Add mechanism to set function attributes Date: Mon, 27 May 2024 13:18:50 +0200 Message-ID: <20240527111900.1060546-6-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org This patch introduces the __CODEGEN_ATTRIBUTES macro which can be used to set function attributes when building the code. Signed-off-by: Christoph Müllner --- string/strcmp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/string/strcmp.c b/string/strcmp.c index 2bca399f52..59d7d98e5e 100644 --- a/string/strcmp.c +++ b/string/strcmp.c @@ -26,6 +26,11 @@ # define strcmp STRCMP #endif +#ifndef __CODEGEN_ATTRIBUTES +# define __CODEGEN_ATTRIBUTES +#endif + +__CODEGEN_ATTRIBUTES static inline int final_cmp (const op_t w1, const op_t w2) { @@ -35,6 +40,7 @@ final_cmp (const op_t w1, const op_t w2) /* Aligned loop: if a difference is found, exit to compare the bytes. Else if a zero is found we have equal strings. */ +__CODEGEN_ATTRIBUTES static inline int strcmp_aligned_loop (const op_t *x1, const op_t *x2, op_t w1) { @@ -55,6 +61,7 @@ strcmp_aligned_loop (const op_t *x1, const op_t *x2, op_t w1) the bytes so that we can also apply the has_zero test to see if we have already reached EOS. If we have, then we can simply fall through to the final comparison. */ +__CODEGEN_ATTRIBUTES static inline int strcmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs) { @@ -98,6 +105,7 @@ strcmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs) /* Compare S1 and S2, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. */ +__CODEGEN_ATTRIBUTES int strcmp (const char *p1, const char *p2) { From patchwork Mon May 27 11:18:51 2024 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: 1939874 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=aa+qhfcn; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntY20hBBz20PT for ; Mon, 27 May 2024 21:22:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E18E382FAED for ; Mon, 27 May 2024 11:22:44 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by sourceware.org (Postfix) with ESMTPS id EE9473858C32 for ; Mon, 27 May 2024 11:19:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EE9473858C32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EE9473858C32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808763; cv=none; b=HJC+Yfr/FoQTvJJRE4AIpty6ASWB1zS4pbkULCWyZ1+yLPPHYbIG0zLWMuVgM6Pf/nO7XHnZZr8J+0YYTB8mLV5RXK00eeq+T8cfRoOvDzO1+twUa2R7C10sDnXwLyu2NmEzdCnWfgdfIwZalh7oZe4LH6kGHakvW/eIA99CnVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808763; c=relaxed/simple; bh=GxRntzmTR7R6nfgnllNQhQQVK1c+iSnqv89VC102NEY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Xi7mo2aNxh6xdNVkCiQ0GMQF4vjSozbWnoByVWEBfhWOn9aL3Gvu8ZusBZIw9kOhZSh6/ePO12Y2wRmIsNSsUT/hO1cEWLxXz7D/CdHk8234PR/EiSgOcds7ttSPgskpTqjNruwTLtFBZ5IADCQqZrNS4YHTk/OgzGG6UPyo4Nk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-52962423ed8so3377161e87.2 for ; Mon, 27 May 2024 04:19:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808760; x=1717413560; 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=TUcuLypJGMJM3r1W1M/FOVVV0C5CSoTeO1s+T3ZHUUM=; b=aa+qhfcn91gLi+oqMymhPsKnpHsgdZUMWydMJ2VA6FYnmhxufajyD+SYaRrc55iUkl SE5LdTEaIbl0GhSK05S9xrlY7iuoTAftepdFnFJQkS1NYNRt5B++6pTkt2SvXT09iybk 1fGW+vHJZIbdHnPvTeT5Fu7f4uQs15q9pIpPbMbXurejlcB+u7MW/XgWNkxcjYtzd+wT yLSvp95cwgD41PBQpeoJxNCrky1VE47gcpmS74plolDfBRoNnn1YsmkR/kMkiT+4rrk7 GfeRkVr1g8gNC38NDmfmzwyBrGBDViTtA0iVCNyvaGKvhGLIcDgtQVLbTACCwU+ppfIX fVQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808760; x=1717413560; 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=TUcuLypJGMJM3r1W1M/FOVVV0C5CSoTeO1s+T3ZHUUM=; b=RXvEggrKmR7af+S01+trLwOYqIjkywcYCcW/snrAtnWLKb+iZHheRhsrfiz4cDWdbo CpVFUlxkuOapyBk9+DL8DCa3BtSInfdn5t+m3eCuBWcV1fMpIhY26tP4PU46gc3vZrAb Rr0zqsFZZd8TwnngtopYZPMbAg8aMdc+Xmq/w4x6ibvSAqcebUejOtQ88G7FwXZdOvWD qNEcB9Kn/U/GdEES2AO7xZtKEYqEaaCiUqqDXf0Wq0kR5Xoyzq9Ntm62OnNAL+SUc/c6 NG8pws2/GlFxLN2GJl4ubg5vkQX3CDDmeSrc+BN7ypM0OvyMQ9H08rD4GAGdKIlysctc Wetg== X-Gm-Message-State: AOJu0Yx5/uCzYnMaDwdMpWomRV4Ar3GOm6PasefA725Vy9rtBRyvjajI PWg9mejK7O35IPNo4PebRTi8UOJ6/4QD94q7Ovi/r7aWITn8EdybMBqxqGgIGtBn2dFQETjReaQ 2BLYU1Q== X-Google-Smtp-Source: AGHT+IEheE2zycE+s07XkdWaafV9Mqv5UsQdyT2QESJZfS8jGKsj9hznCJSIWg6JxWHtYuSfcFVtuw== X-Received: by 2002:a05:6512:224c:b0:51f:d989:18f6 with SMTP id 2adb3069b0e04-529645e230emr8644929e87.13.1716808760255; Mon, 27 May 2024 04:19:20 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:19 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 06/15] string/strlen: Add mechanism to set function attributes Date: Mon, 27 May 2024 13:18:51 +0200 Message-ID: <20240527111900.1060546-7-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org This patch introduces the __CODEGEN_ATTRIBUTES macro which can be used to set function attributes when building the code. Signed-off-by: Christoph Müllner --- string/strlen.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/string/strlen.c b/string/strlen.c index a0378c500e..dcf03769d7 100644 --- a/string/strlen.c +++ b/string/strlen.c @@ -26,8 +26,13 @@ # define __strlen STRLEN #endif +#ifndef __CODEGEN_ATTRIBUTES +# define __CODEGEN_ATTRIBUTES +#endif + /* Return the length of the null-terminated string STR. Scan for the null terminator quickly by testing four bytes at a time. */ +__CODEGEN_ATTRIBUTES size_t __strlen (const char *str) { From patchwork Mon May 27 11:18:52 2024 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: 1939875 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=aVboslur; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntYk2b54z20PT for ; Mon, 27 May 2024 21:23:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9F0893882AEC for ; Mon, 27 May 2024 11:23:20 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id 2C4B53858C33 for ; Mon, 27 May 2024 11:19:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C4B53858C33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2C4B53858C33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808766; cv=none; b=t2OxiKoXWANK6oSx1O+eOjyciE+FhHExzVc901q1kLT/fKGTQbe0JEUOeE2P/sAFED7kOPuq1I/yuvHsATidezOinq9VaQdQiA6d/petLypwo+35yGTl0YQhyrXZy/FStwtIm0VhR7c9cPh61S+e3/ej6DVQnFveKjqgAbpMAHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808766; c=relaxed/simple; bh=TZ0iKjR1+7J+uXkN92wievmaSNxW9Qhx0GUcK7olV88=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Q1JmKrHqqBcDIdTlm6IyTlVktiTXBl+CeTJ6AfAWNhT4LsAkw/mq78hVrPjz9EGSzknFEJGtyBZ9l7AKB5G2BZyc5HLWh/Td7o75j5KTaH82YC5AGjn7M1OZiBgl92D0tlJ9NduKz70LKzr/mDy7TsmpZ4CCg+Mw5bAazaX/hrQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5238b5c07efso10646451e87.3 for ; Mon, 27 May 2024 04:19:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808762; x=1717413562; 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=CQOAgolGAU+5nf6pEbcDaqXBaYckR/gEOsP4SkgrlBQ=; b=aVboslurnn6TfHJ5WILTFtgBQ0QZUSSPJHfiqA9SDaa0OObheoPyqBl37F65mDtQJy p0/KIYKdnGukbJBJXRm0NjcablI/6d+AORbIEYmCY/6i9nl0uYTR2cEwGACiGcpAKB2C Nf99jcgbuqiEKUIp/fDC/NwTZCnMeahWdzXrknyePqGELdQQayGLhjVI18p6C7mT4iEx TNQWz5Bjlt4zc3FR8ip2UBUaTExXftLGEsBFZzc7Ez0O3n3WwXhn/1GAkZ4MNCvKig9O YhFKqjvuZSWeZ+M/dWTLfbkWYstg0cle3w2f8qrbNvGnMBlF/it63Rijzpf2duMPuH/r j/2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808762; x=1717413562; 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=CQOAgolGAU+5nf6pEbcDaqXBaYckR/gEOsP4SkgrlBQ=; b=D6+jAbegkg+tD4kmmVjjc6X4Sij1/hbrTAvSdnTMCA6FWkTQimZHffWnOMMxNMsTix vll4MwAZOMnENM3xChNhGVvlg6zL0Dp9LgyjP0ND3vK/4Fe9w+AMe+6WaiedEW7Kr2XB r27ysbqhdCihlMXqv26miFub5B64rs0gqTBQp66Ekqh8B08btCrqpLLZeouL4pcZc6ay m2UgzoSS9o4vwXGuEBpXq1v5HrPfA2TLKOeyDmy9xu2kMy6hbW19T9xfaehKwtf5b6VE nbM1L+HziokuzsTRVb5d+yiAdE8+UE2In/YN5dM5BJrMnjw7+uy8X5wF4ENSwjlf786n 8lSQ== X-Gm-Message-State: AOJu0YxoKT89wEz4n1e9RuREM0r+t/9GNt18b2fP1sFjxE9CASkO41SF VodlO/og49hUxlXxZXuUmkh9S5aBGnfDruAMfm6rqdkRpGzeDKkoBrx6YVGFTa6s+ODsux17ZGb pcZr44w== X-Google-Smtp-Source: AGHT+IHQTA3XHWEYfD0ij4xSrO3iwBsHB0U7ETbYiRgAwDYo5yOwk9tBqyfacVuW1OfSMo/Jk58QsQ== X-Received: by 2002:ac2:5edb:0:b0:51b:58c7:d04d with SMTP id 2adb3069b0e04-529613c3539mr6097617e87.0.1716808762223; Mon, 27 May 2024 04:19:22 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:21 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 07/15] string/strncmp: Add mechanism to set function attributes Date: Mon, 27 May 2024 13:18:52 +0200 Message-ID: <20240527111900.1060546-8-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org This patch introduces the __CODEGEN_ATTRIBUTES macro which can be used to set function attributes when building the code. Signed-off-by: Christoph Müllner --- string/strncmp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/string/strncmp.c b/string/strncmp.c index 67cc97542a..13c656dc2e 100644 --- a/string/strncmp.c +++ b/string/strncmp.c @@ -29,6 +29,11 @@ #define STRNCMP strncmp #endif +#ifndef __CODEGEN_ATTRIBUTES +# define __CODEGEN_ATTRIBUTES +#endif + +__CODEGEN_ATTRIBUTES static inline int final_cmp (const op_t w1, const op_t w2, size_t n) { @@ -40,6 +45,7 @@ final_cmp (const op_t w1, const op_t w2, size_t n) /* Aligned loop: if a difference is found, exit to compare the bytes. Else if a zero is found we have equal strings. */ +__CODEGEN_ATTRIBUTES static inline int strncmp_aligned_loop (const op_t *x1, const op_t *x2, op_t w1, size_t n) { @@ -64,6 +70,7 @@ strncmp_aligned_loop (const op_t *x1, const op_t *x2, op_t w1, size_t n) the bytes so that we can also apply the has_zero test to see if we have already reached EOS. If we have, then we can simply fall through to the final comparison. */ +__CODEGEN_ATTRIBUTES static inline int strncmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs, size_t n) @@ -110,6 +117,7 @@ strncmp_unaligned_loop (const op_t *x1, const op_t *x2, op_t w1, uintptr_t ofs, returning less than, equal to or greater than zero if S1 is lexicographically less than, equal to or greater than S2. */ +__CODEGEN_ATTRIBUTES int STRNCMP (const char *p1, const char *p2, size_t n) { From patchwork Mon May 27 11:18:53 2024 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: 1939861 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=VCoU1QE0; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntV40LYCz20PT for ; Mon, 27 May 2024 21:20:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 502453864849 for ; Mon, 27 May 2024 11:20:10 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by sourceware.org (Postfix) with ESMTPS id 08D7C385840E for ; Mon, 27 May 2024 11:19:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08D7C385840E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 08D7C385840E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808768; cv=none; b=Xg2hjiW9u/R9zrkF47SNJ39l2s5+3RV6yl4F1Q9pPGshdDP3OLN2zjcIF9zrZTp9m/cmgVY8k6/1UJe1D/9BnBULAHA2czZ4WNin0UiIenoDhfARSF5p5pnoz3WrH3Nt0JjjA83ZaPW7lGFh+KrprMw8eNmKkDW6AHIhZd3JJWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808768; c=relaxed/simple; bh=SmMkXGp9ESf0MGGItmNdmpmnfs9+n5RYcQOEuDyZtmw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=htU9oMpzz2JUU3C3hU3Hl73qnFmuDAGZFpvT/C8OdCkYnjLpR4oAJjt7laNbx/WpCaDfkNwQI1OTQZ3SzMx+jJpftPxi6sg0yJ/nZUvolJ4ZFkyYCRYuCjpVmgjERSu4p56elHPBBj5+Nx3pKrNPKM1jaiVbdLW+pTxmwC5qdJo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-5238b7d0494so11882448e87.3 for ; Mon, 27 May 2024 04:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808764; x=1717413564; 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=FceaouteRfw2bKdZ9nOLgDS+MaAyvcOnJMW/O+IAtrM=; b=VCoU1QE0aH5WL/1azlbCbiYcwQd7TmQlvTgf29kH2mMdeoec8zWjhwK6J5LX9m0z98 2EKzI5q7JXyL/bFQiWsWmzgVf5I0ygpxZdYs70rhuWsjRw5F9iuwQC/AoHKpW0HThVek rdkozr8iBq7VUZkUXhLMDQR08QB7G5vsY2HNqBoJXQpkPWMJikvm4SE4UqzC3S7sdswy ZTY2UtJLgQuzEpZp4o3MG3JkGe3x9g9oCud6Esd+lhm3bjhyZy2Id5FPFDI96nF6l8xF +2BkQz5eTu/4Y4BQNpnmdUrnCMVv3k9gFvDoISNhbPTEPOdTgSWASVCQMgqAFOakMv70 QEwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808764; x=1717413564; 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=FceaouteRfw2bKdZ9nOLgDS+MaAyvcOnJMW/O+IAtrM=; b=ADpABBgAtU+zTvVkWzvDYkMVMdlQ0ruE5xRibDBpUD7I3tz21hlh7GVx21gVwT2dy7 QSkQYA6ERLSOHFyM0p2mUIzR5tocanGjA7xzvX6xRP4RVEeroyRuHKyAYwUqv8iSndkM Isr82K2f2Kt0ODGTBd7dc0QLOQVNPZnJ4EUTdYc45eiXW+aD5lKOIFgY595+rag9DIGC s74OAJIzw9PBWv7TkwCCmZ2KeTLja6c3JPKBfuhrXm03aYeqssLvQ4t7Ft4W91f4RPv6 cNhGKaRLBf24Ncw3PssWuWgU/PBKZ2g481ZnYdNGv3sRpdwzcxCjP/a29kJ1H1RdijGI /KGQ== X-Gm-Message-State: AOJu0YzC2FgemIIwi286aynvdwc05RJO/J2T8RISkhQXSvIlO1LU4PS+ G6JS9jm5g9Rw3DXxfJoGhoPmwyZakGrMuyP9+ikF+avem8j05yS0BvvYJ3ZGC8CJRBK9ojbOxtR 0syyFdg== X-Google-Smtp-Source: AGHT+IGkUf+i4IarW342hzrp2P1o7dtbCF0eHV1YtYKeLA3zQ0HcVhfm1SAz20MrKYsq7v98tMqGZg== X-Received: by 2002:a05:6512:10d6:b0:51b:539f:d1c2 with SMTP id 2adb3069b0e04-52965b3a0camr10035768e87.33.1716808764039; Mon, 27 May 2024 04:19:24 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:23 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 08/15] RISC-V: string-fz[a, i].h: Make orc.b optimization explicit Date: Mon, 27 May 2024 13:18:53 +0200 Message-ID: <20240527111900.1060546-9-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-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, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org RISC-V Zbb has the orc.b instruction, which can be used in find_zero_all. T-Head has a similar instruction (th.tstnbz) in their XTheadBb extension. Currently, we pick the optimized code, whenever the corresponding extension test macros are enabled (e.g. __riscv_zbb for Zbb). However, these test macros are not set in case the extensions are enabled via function attributes. This patch adds a mechanism to enable the optimization explicitly to overcome this limitation. The old behavior (enabled optimization via __riscv_zbb) remains the same. By evaluating the value (instead of just checking if these macros are defined) we could also explicitly disable the optimization by defining the macros as 0 (e.g. #define USE_ZBB_ORCB 0). Signed-off-by: Christoph Müllner --- sysdeps/riscv/string-fza.h | 22 ++++++++++++++++++++-- sysdeps/riscv/string-fzi.h | 20 +++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/sysdeps/riscv/string-fza.h b/sysdeps/riscv/string-fza.h index ee5c31317f..34d6972aea 100644 --- a/sysdeps/riscv/string-fza.h +++ b/sysdeps/riscv/string-fza.h @@ -19,7 +19,25 @@ #ifndef _RISCV_STRING_FZA_H #define _RISCV_STRING_FZA_H 1 -#if defined __riscv_zbb || defined __riscv_xtheadbb +/* Enable use of orc.b if Zbb is available. */ +#ifndef USE_ZBB_ORCB +# ifdef __riscv_zbb +# define USE_ZBB_ORCB 1 +# else +# define USE_ZBB_ORCB 0 +# endif +#endif + +/* Enable use of th.tstnbz if XTheadBb is available. */ +#ifndef USE_XTHEADBB_TSTNBZ +# ifdef __riscv_xtheadbb +# define USE_XTHEADBB_TSTNBZ 1 +# else +# define USE_XTHEADBB_TSTNBZ 0 +# endif +#endif + +#if USE_ZBB_ORCB || USE_XTHEADBB_TSTNBZ /* With bitmap extension we can use orc.b to find all zero bytes. */ # include # include @@ -32,7 +50,7 @@ static __always_inline find_t find_zero_all (op_t x) { find_t r; -#ifdef __riscv_xtheadbb +#if USE_XTHEADBB_TSTNBZ asm ("th.tstnbz %0, %1" : "=r" (r) : "r" (x)); return r; #else diff --git a/sysdeps/riscv/string-fzi.h b/sysdeps/riscv/string-fzi.h index 66237c2f03..e3c3a96d62 100644 --- a/sysdeps/riscv/string-fzi.h +++ b/sysdeps/riscv/string-fzi.h @@ -19,7 +19,25 @@ #ifndef _STRING_RISCV_FZI_H #define _STRING_RISCV_FZI_H 1 -#if defined __riscv_zbb || defined __riscv_xtheadbb +/* Enable use of orc.b if Zbb is available. */ +#ifndef USE_ZBB_ORCB +# ifdef __riscv_zbb +# define USE_ZBB_ORCB 1 +# else +# define USE_ZBB_ORCB 0 +# endif +#endif + +/* Enable use of th.tstnbz if XTheadBb is available. */ +#ifndef USE_XTHEADBB_TSTNBZ +# ifdef __riscv_xtheadbb +# define USE_XTHEADBB_TSTNBZ 1 +# else +# define USE_XTHEADBB_TSTNBZ 0 +# endif +#endif + +#if USE_ZBB_ORCB || USE_XTHEADBB_TSTNBZ # include #else /* Without bitmap clz/ctz extensions, it is faster to direct test the bits From patchwork Mon May 27 11:18:54 2024 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: 1939864 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=Y1vreqgK; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntW071q5z20PT for ; Mon, 27 May 2024 21:21:00 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 42AFE3858417 for ; Mon, 27 May 2024 11:20:59 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id A8A4A3858C35 for ; Mon, 27 May 2024 11:19:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A8A4A3858C35 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A8A4A3858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808773; cv=none; b=oqf9YtUafasegcNkSfgjKes6qy+tzPQ4ZFkCsmtVojJcJpDdALS6jn4Ea5i7pzIezwV/BvG/iTVajrEi4yE2laVlo7lA+MImBS4wLWjA07k43fz9dCMsBM5vFHCeSnrXf3bDM1eT3ZQ2i4Gy1s1YZ5I2NxHvy/fjRLAWV1/C2NE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808773; c=relaxed/simple; bh=sp8BAn6PW1iPdgULjL8a8KZFO65B1LUGdDTOwx0L8jw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=pdhCUPLg6cQjZGiGGAoDnRjfJhIt8InBtBXBlhX+c8gsFQtlW7Flo1MxIAG3MvNbxzTjRb9ST+gu22h886g+S8ihYizIU+N8We7AtWNNCp7rxPpIvsM1iTnL7CGAFh6EG2Zalj+Lvw/SubZnWaLy4aATzqhcKdD1b+g1iJFxaG4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-5295f201979so3314203e87.2 for ; Mon, 27 May 2024 04:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808766; x=1717413566; 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=+apeuom6RsFcela7h9RztLgGg80Twa+f2x4XT0EMiN8=; b=Y1vreqgKYtMTtY82NWeYkPrB8WCCO3rKS8FYV9lyj25qeqPUGHPnzVxU4dSHogbUFT SgCHdZP4HRgosJM4FMnzZvBgnpIz9g3rfI6g+PYyFzh6HS1wFIt+15w2pOMxUDgxRixE dWg1H8L5XUUdgW06mWPsGlcL9FnOUluuEPqf5yUUz6bL6wTcP1QkZuQyXhTT268pfCUM 4LvcKqE+nMRMWsWZ/H4lBdG96rG8tnxRYM+5P/DyG71DWW8DV0spSDuQ1MZjShh6rtcF JcBQu31wsmjXabjT2XL4p8+8M1I4OWg2KvceRfBT/MyIx/p/yRLBLlPImAr3j4NH+UZC 9g4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808766; x=1717413566; 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=+apeuom6RsFcela7h9RztLgGg80Twa+f2x4XT0EMiN8=; b=P52t+sMnx7YzcafDXjuA05syu86FHa769/pYEh621o+N03z3pEhsWI2JAm6I6wsVIb 6TDIMDU6ggfUiTwkaP7dru/c2a72M8R9anQvKX+BxeDqjGRiQ0O5eHeSQHe8TAiXWQft 2C02nR/XQsgfU0DY4zbKaEePCom4PWq2GgWtE5bgRhUwoSWDqC2H2MDbAKFolS1JLHhD fpYw+8awCrfgfJCSJgouFl2f0fPQ1l1KjnQTbUgHb0Hd6G8ra465xvkIi4dEz09qtrUW jVaBwtyHofHn5KOCB+zCL+e6DN7/4K2yEdzEQrhNxFYKBMnVzgcdL//+lsuFNOO4MENL dl0w== X-Gm-Message-State: AOJu0YzfGk/5nxBKXkNhcodzx0YQ9IBH97WUX/NHP4gNLzPYfJ4BtNZh 585irrrQzLEsAXJlvjjpDzTDSiwqFW/GV+Hx5tEHM061OKv5uD/PkyyMg/tHrIJlsgUpUwxIqqz mPdr3mA== X-Google-Smtp-Source: AGHT+IGnmyu9mUcJxjpfMEGJ0Dyukb6olGvqYtW+hrFPN8qWGUiLDHI1iiLFjDGU9FCukOstD2Xyew== X-Received: by 2002:a05:6512:5c9:b0:523:3be3:cbfe with SMTP id 2adb3069b0e04-52966ca8800mr5033466e87.65.1716808765846; Mon, 27 May 2024 04:19:25 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:25 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 09/15] RISC-V: Add compiler test for Zbb function attribute support Date: Mon, 27 May 2024 13:18:54 +0200 Message-ID: <20240527111900.1060546-10-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-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, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org Target function attributes that allow enabling RISC-V extensions have been added to GCC and LLVM a few months ago. This patch adds a configure test to see if the compiler supports enabling Zbb via this mechanism. Note, that unknown target attributes just issue a warning, so this test needs to build with -Werror. Tested with GCC 13 (fails) and GCC 14 (succeeds). Signed-off-by: Christoph Müllner --- config.h.in | 3 +++ sysdeps/riscv/configure | 27 +++++++++++++++++++++++++++ sysdeps/riscv/configure.ac | 18 ++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/config.h.in b/config.h.in index 9a83b774fa..10a670441c 100644 --- a/config.h.in +++ b/config.h.in @@ -273,6 +273,9 @@ /* PowerPC32 uses fctidz for floating point to long long conversions. */ #define HAVE_PPC_FCTIDZ 0 +/* RISC-V function attributes for Zbb. */ +#define HAVE_RISCV_FATTRIBUTE_ZBB 0 + /* Define if PIE is unsupported. */ #undef PIE_UNSUPPORTED diff --git a/sysdeps/riscv/configure b/sysdeps/riscv/configure index c8f01709f8..e0f57fcf9b 100644 --- a/sysdeps/riscv/configure +++ b/sysdeps/riscv/configure @@ -80,3 +80,30 @@ if test "$libc_cv_static_pie_on_riscv" = yes; then printf "%s\n" "#define SUPPORT_STATIC_PIE 1" >>confdefs.h fi + +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for RISC-V Zbb target attribute support" >&5 +printf %s "checking for RISC-V Zbb target attribute support... " >&6; } +if test ${libc_cv_compiler_fattribute_zbb+y} +then : + printf %s "(cached) " >&6 +else $as_nop + cat > conftest.c <&5 \ + 2>&5 ; then + libc_cv_compiler_fattribute_zbb=yes +fi +rm -f conftest* +fi +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $libc_cv_compiler_fattribute_zbb" >&5 +printf "%s\n" "$libc_cv_compiler_fattribute_zbb" >&6; } +if test "$libc_cv_compiler_fattribute_zbb" = yes; then + printf "%s\n" "#define HAVE_RISCV_FATTRIBUTE_ZBB 1" >>confdefs.h + +fi +config_vars="$config_vars +have-fattribute-zbb-support = $libc_cv_compiler_fattribute_zbb" + diff --git a/sysdeps/riscv/configure.ac b/sysdeps/riscv/configure.ac index ee3d1ed014..a7e16dcf83 100644 --- a/sysdeps/riscv/configure.ac +++ b/sysdeps/riscv/configure.ac @@ -43,3 +43,21 @@ EOF if test "$libc_cv_static_pie_on_riscv" = yes; then AC_DEFINE(SUPPORT_STATIC_PIE) fi + +dnl Test if we have Zbb via function attributes +AC_CACHE_CHECK([for RISC-V Zbb target attribute support], + libc_cv_compiler_fattribute_zbb, [dnl +cat > conftest.c <&AS_MESSAGE_LOG_FD \ + 2>&AS_MESSAGE_LOG_FD ; then + libc_cv_compiler_fattribute_zbb=yes +fi +rm -f conftest*]) +if test "$libc_cv_compiler_fattribute_zbb" = yes; then + AC_DEFINE(HAVE_RISCV_FATTRIBUTE_ZBB) +fi +LIBC_CONFIG_VAR([have-fattribute-zbb-support], [$libc_cv_compiler_fattribute_zbb]) From patchwork Mon May 27 11:18:55 2024 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: 1939866 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=e3eAZwHS; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntW45rhMz20Pb for ; Mon, 27 May 2024 21:21:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C6363858432 for ; Mon, 27 May 2024 11:21:03 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 9229D3858424 for ; Mon, 27 May 2024 11:19:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9229D3858424 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9229D3858424 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808773; cv=none; b=OoiK5/XAUiO9FKg+MTB3oEUprCleDOce92HJqwSTAwXPB5yLPHI3sQywTIBSEI3N4O7NkgtomTIX92xv0rtYaVZVSq0bK7Bz6YJZvcihMLCdNxmEybIcwxsKUPAfxu2WxNSp+u9Issak/6zNbwELDGdFu/hpv3ZeAllEO25m59I= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808773; c=relaxed/simple; bh=5u3heF8Q0Cm/bYlRuWINxbOxUJ6OoprCTOvSwMMsTaw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TdSe3WMTXzBQVFsjXWF0ycu2l6vWe82/MMXUD4OUF4wYmaC9uYv4jXNB5eC1DBe/jC4/tmgnsGUaokTRsNo1BTmw1SQq2ErZj9sfaGBFGfYGTCeeDXVjc/KfvTtlfvoe6TP2i2Xu9djTvtERrxcIixYeJ6R2a9r7OjCfBSdqBhU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-529614b8c29so4698292e87.2 for ; Mon, 27 May 2024 04:19:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808768; x=1717413568; 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=eo96U3q/XuUrZDJZMtU9qUbOHa+4ce/iJbW1sF/Wl6M=; b=e3eAZwHSRoEj7dtWMgw4KPO43o7HMh++me9xTGlIAl5X61M+oHf2k6Q7ZexHbzLUkJ XD9BjDC0CUoJJ2EmY/er1mUrkjll5X8L645DCfDu5nigdqJTe1L1vOxzwbnq6n/eJB1Y pLe5YMOF2ynfq3LtBv4pvpHsKyZ8BCTvAkTkm6n/IW+fiTK/yuIKItALz2krVeQmzics BEQr5gfJJMw54+FNunvToPhhJrXh4APY7VBpfiLOrqSquaxHcW5LRpr4EFPZRHiqsNRF hJPvk99rYjVoDzGusOiTFoI+6ShrZV2xAtxCutTLaLJXFI1YuJbI56GolL9IgrDzf0Xh gnvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808768; x=1717413568; 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=eo96U3q/XuUrZDJZMtU9qUbOHa+4ce/iJbW1sF/Wl6M=; b=bgls3gUUcM83j/yDCXzpMBEM5xbgR480WKqSCoxcnnIPCUHnfWeOmkDyWHU5kZWvIS jmSbUbnUjRUJoJvgMH6hcfyyXD8UqvmcaNXom56YlDxzB/Ni+3oyaU2W0p/DhUDus5q7 YNj0el6mVggqn+vjVdLb4SzLuf6B6VT7chZDDBI3YKQxErYRHurwJPrMIrVfC1kj5ZZG SYJV7k6LhmR0K3BSdheMxm/q6b1fVfgjMKYKpa3MTUJjUYw7Ib8UGPC6LDEMj0ak81cA G/d8Mz5PEFNOh+BrX7yNdgMtZmv8duGU3V/vZvtJuJwk2oHd5EvT/o9lMcnzbLq1FgbZ cFkw== X-Gm-Message-State: AOJu0YznufTk3YBHOYxU3KmPzqwwrZ8CLshil9lDuLlBZq6P07jSRuHo tOebxRcBUvFtUb0kD3A+/OtztS/uS1dBVuqhKv/W++Dg+TvbJ/I1T7mxtLwCK4vmhAnsGMkxUNa vXXNVTw== X-Google-Smtp-Source: AGHT+IHQjGDS9RlrVHuxvVDdnPHLUiVlWHOXuQKSFkqobKryvu/TSd3/RwBlDJkFZ8qlxDXi4E5Zhg== X-Received: by 2002:ac2:5181:0:b0:527:95a4:c40a with SMTP id 2adb3069b0e04-5296736bb65mr7158523e87.49.1716808767735; Mon, 27 May 2024 04:19:27 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:27 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 10/15] RISC-V: Add Zbb optimized memchr as ifunc Date: Mon, 27 May 2024 13:18:55 +0200 Message-ID: <20240527111900.1060546-11-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-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, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org When building with Zbb enabled, memchr benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/memchr-generic.c | 24 ++++++++ sysdeps/riscv/multiarch/memchr-zbb.c | 23 +++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 8 +++ .../linux/riscv/multiarch/ifunc-impl-list.c | 37 ++++++++++-- .../unix/sysv/linux/riscv/multiarch/memchr.c | 60 +++++++++++++++++++ 5 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 sysdeps/riscv/multiarch/memchr-generic.c create mode 100644 sysdeps/riscv/multiarch/memchr-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c diff --git a/sysdeps/riscv/multiarch/memchr-generic.c b/sysdeps/riscv/multiarch/memchr-generic.c new file mode 100644 index 0000000000..c44616c95c --- /dev/null +++ b/sysdeps/riscv/multiarch/memchr-generic.c @@ -0,0 +1,24 @@ +/* Re-include the default memchr implementation. + Copyright (C) 2024 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 + +#if IS_IN(libc) +# define MEMCHR __memchr_generic +#endif +#include diff --git a/sysdeps/riscv/multiarch/memchr-zbb.c b/sysdeps/riscv/multiarch/memchr-zbb.c new file mode 100644 index 0000000000..e5de76ec18 --- /dev/null +++ b/sysdeps/riscv/multiarch/memchr-zbb.c @@ -0,0 +1,23 @@ +/* Re-include the default memchr implementation for Zbb. + Copyright (C) 2024 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 + . */ + +/* Build with Zbb enabled. */ +#define __CODEGEN_ATTRIBUTES __attribute__((target("arch=+zbb"))) +#define USE_ZBB_ORCB 1 +#define MEMCHR __memchr_zbb +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index fcef5659d4..12ebe0a960 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -1,9 +1,17 @@ ifeq ($(subdir),string) sysdep_routines += \ + memchr \ + memchr-generic \ memcpy \ memcpy-generic \ memcpy_noalignment \ # sysdep_routines +ifeq ($(have-fattribute-zbb-support),yes) +sysdep_routines += \ + memchr-zbb \ + # Zbb sysdep_routines +endif + CFLAGS-memcpy_noalignment.c += -mno-strict-align endif diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index 9f806d7a9e..e7bb604c5a 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -20,19 +20,46 @@ #include #include +#define ARRAY_SIZE(A) (sizeof (A) / sizeof ((A)[0])) + size_t __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, size_t max) { size_t i = max; + struct riscv_hwprobe pairs[] = { + { .key = RISCV_HWPROBE_KEY_IMA_EXT_0 }, + { .key = RISCV_HWPROBE_KEY_CPUPERF_0 }, + }; bool fast_unaligned = false; +#if HAVE_RISCV_FATTRIBUTE_ZBB + bool has_zbb = false; +#endif + + if (__riscv_hwprobe (pairs, ARRAY_SIZE (pairs), 0, NULL, 0) == 0) + { + struct riscv_hwprobe *pair; + + /* RISCV_HWPROBE_KEY_IMA_EXT_0 */ + pair = &pairs[0]; +#if HAVE_RISCV_FATTRIBUTE_ZBB + if (pair->value & RISCV_HWPROBE_EXT_ZBB) + has_zbb = true; +#endif + + /* RISCV_HWPROBE_KEY_CPUPERF_0 */ + pair = &pairs[1]; + if ((pair->value & RISCV_HWPROBE_MISALIGNED_MASK) + == RISCV_HWPROBE_MISALIGNED_FAST) + fast_unaligned = true; + } - struct riscv_hwprobe pair = { .key = RISCV_HWPROBE_KEY_CPUPERF_0 }; - if (__riscv_hwprobe (&pair, 1, 0, NULL, 0) == 0 - && (pair.value & RISCV_HWPROBE_MISALIGNED_MASK) - == RISCV_HWPROBE_MISALIGNED_FAST) - fast_unaligned = true; + IFUNC_IMPL (i, name, memchr, +#if HAVE_RISCV_FATTRIBUTE_ZBB + IFUNC_IMPL_ADD (array, i, memchr, has_zbb, __memchr_zbb) +#endif + IFUNC_IMPL_ADD (array, i, memchr, 1, __memchr_generic)) IFUNC_IMPL (i, name, memcpy, IFUNC_IMPL_ADD (array, i, memcpy, fast_unaligned, diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c new file mode 100644 index 0000000000..71a0c039bd --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c @@ -0,0 +1,60 @@ +/* Multiple versions of memchr. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 IS_IN (libc) + +/* Redefine memchr so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef memchr +# define memchr __redirect_memchr +# include +# include +# include +# include +# include + +extern __typeof (__redirect_memchr) __libc_memchr; + +extern __typeof (__redirect_memchr) __memchr_generic attribute_hidden; +extern __typeof (__redirect_memchr) __memchr_zbb attribute_hidden; + +static inline __typeof (__redirect_memchr) * +select_memchr_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ +#if HAVE_RISCV_FATTRIBUTE_ZBB + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __memchr_zbb; +#endif + + return __memchr_generic; +} + +riscv_libc_ifunc (__libc_memchr, select_memchr_ifunc); + +# undef memchr +strong_alias (__libc_memchr, memchr); +# ifdef SHARED +__hidden_ver1 (memchr, __GI_memchr, __redirect_memchr) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (memchr); +# endif +#else +# include +#endif From patchwork Mon May 27 11:18:56 2024 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: 1939873 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=Pgjm5cGj; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntXd0qqZz20PT for ; Mon, 27 May 2024 21:22:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5E5A43875462 for ; Mon, 27 May 2024 11:22:23 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id EDAF23858D28 for ; Mon, 27 May 2024 11:19:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EDAF23858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EDAF23858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808781; cv=none; b=liT0TpDglNCqG61dwGvy4bwaMNMTHQXmea/6E+v0to0ZkuCGPeDYEyqAc2SNNtIDndlPUntTcarIjUJTfe+RczS1eUOd6k5cfJZrueghWPcVcr3U9sizwDMesEpU+zodm5w4n7LUpDt4u8IHCtopo4pSULv/C9irqjtJ/17BuqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808781; c=relaxed/simple; bh=zsuvNS2iZY6f9akggHXpV2KEOT8WxBpWIYEacg8gvNw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=JWh77xrQn5O3ZAFf1AmlUPpoAAUo8l6hDZt3FjB6tUFhjaoxFVQVVOY0B4g1kQfDTAcqe0O/pwS+BsctiVF0bm/C+T+Qo9kJZcsBc+61/vLcDdZ317U2C80owtsZywfoN7/W2bBeLMoFrwHNomBfKCoGeus54Mk8KOO6jybgypc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-5295dada905so2515822e87.1 for ; Mon, 27 May 2024 04:19:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808770; x=1717413570; 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=gehWyHBFqXqO1jhP6wKYdbMiwj6cFpbZX2UI0OgMUkc=; b=Pgjm5cGjadBlvs1/vUiKzNyh5LBs5fwJCL0yEHFG+MG+IP8wiZsro6H+Qqej/TUB6m zvUQZLNfjPvEfEaIxxg5CGLdwo9ifKbC0OIOa9AL0ALFjCZXxCgS15HAHSkqefzzl/QJ tRk6auLfb8M4Q65iT8SM/KdQIlBWz7DOUSpFJ5DEowEotvlJHIj1nlOVMFn77twRrCA2 7Yj2+3wXKNhhvxOEBzypRVptbHb6c65pSl/haI0nvu2aNi1f+z0WW+zc1uedJdQkGUf/ qQp98udakFeFHnGFXoz6ERnOkBsnCUMeD14p9TIKnXmINiDNNJZoVscFnomr0XwQsKL0 Q+qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808770; x=1717413570; 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=gehWyHBFqXqO1jhP6wKYdbMiwj6cFpbZX2UI0OgMUkc=; b=qlQsXQ61C/A/HeVg9gStav53hZ49s0jfzPW1yO2zpCuFNibBJltZP6YgFid6QPtl5b AIvQIJtJdUoNsR4lR49oZ83WD3zADEUSn3CjGqvmOTcBX0taCwQUQhTCdezIdSLe3aDO 6qYwL+XZnRtfqvzvMdriRwj8cx+7d9izYyDXh29SvD0iuGQ1u4aTaXsVWKyH3wuUvria ZAux1xfmOR7e/wCUMLrcS9pKuzIFS9KnsXlMondaNk65a+xFLY6mCyZQNeqs7NxKZNCX IY8IA69Dd2t1VSdcW9YeY1x4aq60cSwgIK2FWzKw76mV090CCd1fC2II22JKiepu0cHy ELdA== X-Gm-Message-State: AOJu0YzK94w0iB4FAQSvimQkh5Ka7f/i2OWEd3QwYP4q3K5llfcr+oZR I8siZXKNiPWaZjBhr2rxRnDTVsmTcgPZBw/QxMO0n6fcNsPMEyvq61ZSfUiuChaCryQeJjr4WLJ C0yitLA== X-Google-Smtp-Source: AGHT+IFFTjP772OyihC125wa8LK+pgTBgV/R2AJgj/TY1Vh1eoWPsMBtnDEWEqrHrbF21WSnqB7zrg== X-Received: by 2002:a05:6512:3b98:b0:529:3b3c:134c with SMTP id 2adb3069b0e04-5293b3c147emr3634657e87.2.1716808769607; Mon, 27 May 2024 04:19:29 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:29 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 11/15] RISC-V: Add Zbb optimized memrchr as ifunc Date: Mon, 27 May 2024 13:18:56 +0200 Message-ID: <20240527111900.1060546-12-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-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, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org When building with Zbb enabled, memrchr benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/memrchr-generic.c | 24 +++++++ sysdeps/riscv/multiarch/memrchr-zbb.c | 23 +++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 6 ++ .../unix/sysv/linux/riscv/multiarch/memrchr.c | 63 +++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 sysdeps/riscv/multiarch/memrchr-generic.c create mode 100644 sysdeps/riscv/multiarch/memrchr-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c diff --git a/sysdeps/riscv/multiarch/memrchr-generic.c b/sysdeps/riscv/multiarch/memrchr-generic.c new file mode 100644 index 0000000000..787e9ce5ca --- /dev/null +++ b/sysdeps/riscv/multiarch/memrchr-generic.c @@ -0,0 +1,24 @@ +/* Re-include the default memrchr implementation. + Copyright (C) 2024 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 + +#if IS_IN(libc) +# define MEMRCHR __memrchr_generic +#endif +#include diff --git a/sysdeps/riscv/multiarch/memrchr-zbb.c b/sysdeps/riscv/multiarch/memrchr-zbb.c new file mode 100644 index 0000000000..10565d95a9 --- /dev/null +++ b/sysdeps/riscv/multiarch/memrchr-zbb.c @@ -0,0 +1,23 @@ +/* Re-include the default memrchr implementation for Zbb. + Copyright (C) 2024 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 + . */ + +/* Build with Zbb enabled. */ +#define __CODEGEN_ATTRIBUTES __attribute__((target("arch=+zbb"))) +#define USE_ZBB_ORCB 1 +#define MEMRCHR __memrchr_zbb +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index 12ebe0a960..ca7b924007 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -5,11 +5,14 @@ sysdep_routines += \ memcpy \ memcpy-generic \ memcpy_noalignment \ + memrchr \ + memrchr-generic \ # sysdep_routines ifeq ($(have-fattribute-zbb-support),yes) sysdep_routines += \ memchr-zbb \ + memrchr-zbb \ # Zbb sysdep_routines endif diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index e7bb604c5a..fbd08162ca 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -66,5 +66,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, __memcpy_noalignment) IFUNC_IMPL_ADD (array, i, memcpy, 1, __memcpy_generic)) + IFUNC_IMPL (i, name, memrchr, +#if HAVE_RISCV_FATTRIBUTE_ZBB + IFUNC_IMPL_ADD (array, i, memrchr, has_zbb, __memrchr_zbb) +#endif + IFUNC_IMPL_ADD (array, i, memrchr, 1, __memrchr_generic)) + return 0; } diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c new file mode 100644 index 0000000000..065557ed7b --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c @@ -0,0 +1,63 @@ +/* Multiple versions of memrchr. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 IS_IN (libc) +/* Redefine memrchr so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef memrchr +# undef __memrchr +# define memrchr __redirect_memrchr +# define __memrchr __redirect___memrchr +# include +# include +# include +# include +# include + +extern __typeof (__redirect_memrchr) __libc_memrchr; + +extern __typeof (__redirect_memrchr) __memrchr_generic attribute_hidden; +extern __typeof (__redirect_memrchr) __memrchr_zbb attribute_hidden; + +static inline __typeof (__redirect_memrchr) * +select_memrchr_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ +#if HAVE_RISCV_FATTRIBUTE_ZBB + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __memrchr_zbb; +#endif + + return __memrchr_generic; +} + +riscv_libc_ifunc (__libc_memrchr, select_memrchr_ifunc); + +# undef memrchr +# undef __memrchr +strong_alias (__libc_memrchr, __memrchr); +weak_alias (__memrchr, memrchr) +# ifdef SHARED +__hidden_ver1 (memrchr, __GI___memrchr, __redirect_memrchr) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (memrchr); +# endif +#else +# include +#endif From patchwork Mon May 27 11:18:57 2024 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: 1939862 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=IrgyQECm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntVK48smz20PT for ; Mon, 27 May 2024 21:20:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 990D63858429 for ; Mon, 27 May 2024 11:20:23 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id BF7203858C5F for ; Mon, 27 May 2024 11:19:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF7203858C5F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BF7203858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::135 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808777; cv=none; b=ngg6btSLylIxg7dfuPPPGzmZoKO7k+yr3r8qmagMh8OeJD2PgTl3Y1MNZWCwntAAxzD0wWDDFo1SwPChbwwB/05o7x8SMC/5Ghhhuf0ANhpkp3Ybrttral9AAQlGxb5D/RAuxf5b96MHGrG9cdE1l4h5Su9161iCTtp8hYCFM6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808777; c=relaxed/simple; bh=bqfDToaELlxNDt4eQQFFbUv78tkKfrZ9uWL5oJfBRHg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Xs5ooUx619DNzaP//yHq796pivaGTHX2amisTb3bZPL820zkrwHnWofwYlqBQ3WwyzpyoKMthtx5twU3+d8u10wGf/R8rnCielVcKx6ubqHBlMsNRQxeuWT418cOLRAFe7AUQIn9vzgNGtATOc1FlDMOxKZ2ROz7zj/bLOWQd+8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5295a576702so3388598e87.0 for ; Mon, 27 May 2024 04:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808771; x=1717413571; 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=q1nDUVu2N2Hg/n3Py1NjmttTaGkPAoZaVR7fzveopng=; b=IrgyQECmxVoVpXd3wuXPh+GiR5Lj4ZVBZqlpKXPxuLpO2pWrJRe6fvVheanaSzIG1U hd67yly8lgOXq+qFVxP/ZXjh0ds/1ST9KbU2v++hjD2/y7ne/Yi1AmothpZ4DYImiA0D AQj1f/wIe1TqseDVJkfLseA028JQwDxzC+x8bWCQQ4WRb1dHriR8Z0YeTLTUflH3Jpvg CjYCp/Kp3X+pVpXUwYch9yqF7MTSIOaQ51hQDxm+f3OlaKMPpJDWlKu3jXvQKmdkytLx Qm4D+dwWnvjQYsdGrFhd/rSpJ8pplKsc7W6cQvYPsqZ+bfCBEApPWBpbxAnDcOqNqPRM bMUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808771; x=1717413571; 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=q1nDUVu2N2Hg/n3Py1NjmttTaGkPAoZaVR7fzveopng=; b=dr4R329w1AGybyc2goqOlr1x0vUUI2OosOUozqFbY9oRRXyW7ODfbac81e5RiF9sFc gBHlbGCjmVjg82ahOshXzTKkoJYICJ6am6yeyKXRDKrZ+FGherbT63SV+9unPum5sHN4 gdQvU7EY8wrFyOpsk1Njkpu/nGvCbYSqEkAyyXzlZcsfkpVox9JmN7wtuhqAKu1nd2Vp BzHRXBCASdt/+CK1gFC7VH0hgDJCP7Vi8KDxPxai3vwA4jZ4E4MOh4wjliXUuk0qQXBi f+q+NPDztuRT8HREgc227aM8bHbAA3s64cTYju/m0R3O88VbyqFfqf5YODVZMIYBcXSi ikUg== X-Gm-Message-State: AOJu0YyBzQDdheXKZHoqhJpSNSMqaTsbUO/xGMfAL1MqW6T3pq2CW+r/ /JjL76TB/ySpU/pxjMZ+nuUVfKk8fPaAk61MhCK5QID0Yd7sTFsJ4zylqXvrg5ShSRVAPx2J9K7 B1DHoBg== X-Google-Smtp-Source: AGHT+IGmvZzvEbYpoENWciWIz+FtC1fElLrFX5TisburZzQnLUM/Y43h3GTp1BpH7fQC7OV0xpXKJQ== X-Received: by 2002:ac2:4843:0:b0:528:f1c0:1d3 with SMTP id 2adb3069b0e04-529645e2ba2mr5206615e87.22.1716808771464; Mon, 27 May 2024 04:19:31 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:30 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 12/15] RISC-V: Add Zbb optimized strchrnul as ifunc Date: Mon, 27 May 2024 13:18:57 +0200 Message-ID: <20240527111900.1060546-13-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-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, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org When building with Zbb enabled, strchrnul benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/strchrnul-generic.c | 24 +++++++ sysdeps/riscv/multiarch/strchrnul-zbb.c | 23 +++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 6 ++ .../sysv/linux/riscv/multiarch/strchrnul.c | 63 +++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 sysdeps/riscv/multiarch/strchrnul-generic.c create mode 100644 sysdeps/riscv/multiarch/strchrnul-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strchrnul.c diff --git a/sysdeps/riscv/multiarch/strchrnul-generic.c b/sysdeps/riscv/multiarch/strchrnul-generic.c new file mode 100644 index 0000000000..c59500798d --- /dev/null +++ b/sysdeps/riscv/multiarch/strchrnul-generic.c @@ -0,0 +1,24 @@ +/* Re-include the default strchrnul implementation. + Copyright (C) 2024 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 + +#if IS_IN(libc) +# define STRCHRNUL __strchrnul_generic +#endif +#include diff --git a/sysdeps/riscv/multiarch/strchrnul-zbb.c b/sysdeps/riscv/multiarch/strchrnul-zbb.c new file mode 100644 index 0000000000..f5f290621e --- /dev/null +++ b/sysdeps/riscv/multiarch/strchrnul-zbb.c @@ -0,0 +1,23 @@ +/* Re-include the default strchrnul implementation for Zbb. + Copyright (C) 2024 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 + . */ + +/* Build with Zbb enabled. */ +#define __CODEGEN_ATTRIBUTES __attribute__((target("arch=+zbb"))) +#define USE_ZBB_ORCB 1 +#define STRCHRNUL __strchrnul_zbb +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index ca7b924007..5a442905b5 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -7,12 +7,15 @@ sysdep_routines += \ memcpy_noalignment \ memrchr \ memrchr-generic \ + strchrnul \ + strchrnul-generic \ # sysdep_routines ifeq ($(have-fattribute-zbb-support),yes) sysdep_routines += \ memchr-zbb \ memrchr-zbb \ + strchrnul-zbb \ # Zbb sysdep_routines endif diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index fbd08162ca..7a769122ec 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -72,5 +72,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, #endif IFUNC_IMPL_ADD (array, i, memrchr, 1, __memrchr_generic)) + IFUNC_IMPL (i, name, strchrnul, +#if HAVE_RISCV_FATTRIBUTE_ZBB + IFUNC_IMPL_ADD (array, i, strchrnul, has_zbb, __strchrnul_zbb) +#endif + IFUNC_IMPL_ADD (array, i, strchrnul, 1, __strchrnul_generic)) + return 0; } diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strchrnul.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strchrnul.c new file mode 100644 index 0000000000..b2c6665e90 --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strchrnul.c @@ -0,0 +1,63 @@ +/* Multiple versions of strchrnul. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 IS_IN (libc) +/* Redefine strchrnul so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef strchrnul +# undef __strchrnul +# define strchrnul __redirect_strchrnul +# define __strchrnul __redirect_strchrnul +# include +# include +# include +# include +# include + +extern __typeof (__redirect_strchrnul) __libc_strchrnul; + +extern __typeof (__redirect_strchrnul) __strchrnul_generic attribute_hidden; +extern __typeof (__redirect_strchrnul) __strchrnul_zbb attribute_hidden; + +static inline __typeof (__redirect_strchrnul) * +select_strchrnul_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ +#if HAVE_RISCV_FATTRIBUTE_ZBB + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __strchrnul_zbb; +#endif + + return __strchrnul_generic; +} + +riscv_libc_ifunc (__libc_strchrnul, select_strchrnul_ifunc); + +# undef strchrnul +# undef __strchrnul +strong_alias (__libc_strchrnul, __strchrnul); +weak_alias (__strchrnul, strchrnul) +# ifdef SHARED +__hidden_ver1 (strchrnul, __GI___strchrnul, __redirect_strchrnul) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strchrnul); +# endif +#else +# include +#endif From patchwork Mon May 27 11:18:58 2024 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: 1939867 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=dGvp1Jgo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntW71mCFz20PT for ; Mon, 27 May 2024 21:21:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8C092385E458 for ; Mon, 27 May 2024 11:21:05 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by sourceware.org (Postfix) with ESMTPS id 5EE1E3857C4F for ; Mon, 27 May 2024 11:19:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5EE1E3857C4F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5EE1E3857C4F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::135 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808778; cv=none; b=C5KTbircPjW2ZgbCB+h/AH/5rkg4AMud0SCGNruhgmRxDwyvwZUj3+med9Znk8WLJBu0fmjL9ZPFHjHRzdv4SGXd/Su9aAR0BSj+esGuAUJlY9/pt9jEo6JxjapKcJAOEuXvGojgDWRYGW/aQrqlr5Vnu2G2NUaDEaJJbY+Sr/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808778; c=relaxed/simple; bh=6c/Gmjogk6Bhd87EgXhQ+3POvhiCmHZGzvGjRKxAvPI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uYsVdqCwzopH6gyVPIUsnXPlhnygvCzR+Y5TvrAe2BwdiQOMltyVet+WHnL+87wyqvGEJLSMRnI4EHvECAge2JcstkvVBsbFcQAa4i4efcZ36BQoEjrCaCTQk2ZVUgPK9wQXsyUbs30XIiG5S3IRQ0dG8DZy2wCG2E4pIDFKF4w= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-5238b5c07efso10646552e87.3 for ; Mon, 27 May 2024 04:19:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808773; x=1717413573; 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=W6avFlMGw4Ck7J5FOD7fovMTlEiPPfd304/ZUOT4PMs=; b=dGvp1JgowzbEtsk6yGZv0ZZOiQ7AK1NkXipWLFwTpEs4QNMsV0QuE1WkJABmJMH0Xm sIHlAB1LQROZ7wh9TaAOv5lIqi+oWB0dMjhyRYRYuDBqam4pDFvphShcVlN/wyJD/SOs iMEHquKAHhW3zunibyWzRm3MQk40RwdHz4i+MTzf+bh6J49QZM7SUSLyccC60l9mVJDN xTo9AcutIYnz54BAtBGg4NQbsvTHnJgA/8V7fWMIsI1ZSJOqIRfCTw6Q56EOnFnOd8gh nfD4TMVgpjt87NPkblrVbh/qWho8bkSAoticEZiqaA8yW4XOVGCkDBqV2FWHF347ZSeH WbBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808773; x=1717413573; 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=W6avFlMGw4Ck7J5FOD7fovMTlEiPPfd304/ZUOT4PMs=; b=GoFKQqBw/oVysh1bVze2BrmlJd6J/ZRGUCLHiwzvcGDHyWk1Gqsee1IUX5yGrUSAbE wbOx6oPwyVtogRzbwfQlMqDOmsy+0VjeMJutadbeB4wzA4KwbNYmdLQvYByv0HJzrXUv dEEkyfZkZY7fzVlpMVH2B1B3YJ6pQ+tiLxReE69LT4pqq9g8/9rMLuQUA/qEVG4sQclZ c9aIjJtRbaJBspylnF1TX833QtFC3KhDOJwkAWBPNgPXpEqjmSBGB4VwK7u+2qMAR4pV p/FByxUGWQkhbqooA05gJPrN5Odhvr/NcnZOLpP+iXO4uijDnoWc7XpLG1gXipt7sdTo oK8w== X-Gm-Message-State: AOJu0Yytk4rrpSoryZ3tEba2sr9vgrL3eBNBmoBCyiwI7nPx0NcJJM1C 2GjRYkgCSRNWNoPjZAMJGWsZ32tFot5V9y+nanutZG2XQDAqGnsZR/R1zRV73jhbkPBZVTZnZJX jA6l64w== X-Google-Smtp-Source: AGHT+IGtP8DwXoDA8S7jgcSgaCH3grM0ueMaIgtDsRDtrNW/fnLOHrm74pCApW+Z4MxMivyqaI/wmg== X-Received: by 2002:ac2:53a5:0:b0:51f:463c:c577 with SMTP id 2adb3069b0e04-5296410a5b4mr5131617e87.4.1716808773362; Mon, 27 May 2024 04:19:33 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:32 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 13/15] RISC-V: Add Zbb optimized strcmp as ifunc Date: Mon, 27 May 2024 13:18:58 +0200 Message-ID: <20240527111900.1060546-14-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-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, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org When building with Zbb enabled, strcmp benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/strcmp-generic.c | 24 ++++++++ sysdeps/riscv/multiarch/strcmp-zbb.c | 23 ++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 6 ++ .../unix/sysv/linux/riscv/multiarch/strcmp.c | 59 +++++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 sysdeps/riscv/multiarch/strcmp-generic.c create mode 100644 sysdeps/riscv/multiarch/strcmp-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c diff --git a/sysdeps/riscv/multiarch/strcmp-generic.c b/sysdeps/riscv/multiarch/strcmp-generic.c new file mode 100644 index 0000000000..ef9fb9eb46 --- /dev/null +++ b/sysdeps/riscv/multiarch/strcmp-generic.c @@ -0,0 +1,24 @@ +/* Re-include the default strcmp implementation. + Copyright (C) 2024 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 + +#if IS_IN(libc) +# define STRCMP __strcmp_generic +#endif +#include diff --git a/sysdeps/riscv/multiarch/strcmp-zbb.c b/sysdeps/riscv/multiarch/strcmp-zbb.c new file mode 100644 index 0000000000..86a2996358 --- /dev/null +++ b/sysdeps/riscv/multiarch/strcmp-zbb.c @@ -0,0 +1,23 @@ +/* Re-include the default strcmp implementation for Zbb. + Copyright (C) 2024 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 + . */ + +/* Build with Zbb enabled. */ +#define __CODEGEN_ATTRIBUTES __attribute__((target("arch=+zbb"))) +#define USE_ZBB_ORCB 1 +#define STRCMP __strcmp_zbb +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index 5a442905b5..69c4dd2d07 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -9,6 +9,8 @@ sysdep_routines += \ memrchr-generic \ strchrnul \ strchrnul-generic \ + strcmp \ + strcmp-generic \ # sysdep_routines ifeq ($(have-fattribute-zbb-support),yes) @@ -16,6 +18,7 @@ sysdep_routines += \ memchr-zbb \ memrchr-zbb \ strchrnul-zbb \ + strcmp-zbb \ # Zbb sysdep_routines endif diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index 7a769122ec..c761807a7a 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -78,5 +78,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, #endif IFUNC_IMPL_ADD (array, i, strchrnul, 1, __strchrnul_generic)) + IFUNC_IMPL (i, name, strcmp, +#if HAVE_RISCV_FATTRIBUTE_ZBB + IFUNC_IMPL_ADD (array, i, strcmp, has_zbb, __strcmp_zbb) +#endif + IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_generic)) + return 0; } diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c new file mode 100644 index 0000000000..f32f87a8e9 --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c @@ -0,0 +1,59 @@ +/* Multiple versions of strcmp. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 IS_IN (libc) +/* Redefine strcmp so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef strcmp +# define strcmp __redirect_strcmp +# include +# include +# include +# include +# include + +extern __typeof (__redirect_strcmp) __libc_strcmp; + +extern __typeof (__redirect_strcmp) __strcmp_generic attribute_hidden; +extern __typeof (__redirect_strcmp) __strcmp_zbb attribute_hidden; + +static inline __typeof (__redirect_strcmp) * +select_strcmp_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ +#if HAVE_RISCV_FATTRIBUTE_ZBB + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __strcmp_zbb; +#endif + + return __strcmp_generic; +} + +riscv_libc_ifunc (__libc_strcmp, select_strcmp_ifunc); + +# undef strcmp +strong_alias (__libc_strcmp, strcmp); +# ifdef SHARED +__hidden_ver1 (strcmp, __GI_strcmp, __redirect_strcmp) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strcmp); +# endif +#else +# include +#endif From patchwork Mon May 27 11:18:59 2024 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: 1939870 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=p8zAvOKf; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntWr2Frjz20PT for ; Mon, 27 May 2024 21:21:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 94F31386D606 for ; Mon, 27 May 2024 11:21:42 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by sourceware.org (Postfix) with ESMTPS id 055C83858CDB for ; Mon, 27 May 2024 11:19:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 055C83858CDB Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 055C83858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::231 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808780; cv=none; b=QMlU3oFMopaT2dq5ZroZo3dG4zEIJNkV92wIYtHBBEw44tH88doKALXF9rZyaRiZv5IK+efc/N8afyYo7nD/Cu4KKvMShXRrkeMMT2f7ZhFkELBnHrGSH7Q2yxhEpT4a8VDKYbMBg5Fq3rC4Uvj0Rh2bh0h3P9FL1VqYXTPD9vQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808780; c=relaxed/simple; bh=TW0/51b2VyhFcIZMaKDWmmwCD48akQKcdunlQ5dovRw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vZ7YfpY5M/F4yLozF4I18m/X4wriYs7wlk7RjuZtbec2c8cgz8Ln+FRTksxNKykVhNs7qsZBwcRsMmIppTtjSz0Jw0KOrSFRw0BCs1bOVGgMCu9G9RNR3STcpXm199VSfqaBhNVYVI489moLfYLoYZx5IFfzKEZqEL3P5zq4NiU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2e95a1eff78so40475651fa.0 for ; Mon, 27 May 2024 04:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808775; x=1717413575; 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=6dubrFx0Pywo6re2s1o/23KWXa6P1IlggaUtN7zGpHA=; b=p8zAvOKfM99R+5w/NuXu+KuGOhnmsMWUzhX9FEE8UZfm4tjl2z7nhS1GdgXNf6WKuE WrIkRx6vUdAoTOHXHSri96f2YIk48VokOGK97GuNUNIZUEzHWogXDOubaV4lGHou/WoK WF5V0f354+pyvjhqr2h+Yzo7V/UEfg8VP00JZk9DRmuCf0a49MIdC7gV0x0B9e1GXAfw RpgI0/5wcEba9FH/gHif1+iqRNDXy8qcvWuMUXb/prRrWvHNqF6vUxqGFGxEtfQTRMrc jCulXh0FxZB6Pe4AF0hKTlqKpJhs3IZjb9Oxtuu7hYKaXZPKQFJBrK3pubTP9K0g3s+W 3Bzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808775; x=1717413575; 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=6dubrFx0Pywo6re2s1o/23KWXa6P1IlggaUtN7zGpHA=; b=DX+fvBLbZn9fo/y7mGpp9Cbu52eOkKDoFOrET2HxiorukusnBc2Ak6xJsY4ywQi2tO pHRQU3sDId9vMHQ4m8rNUfnH4RD8zWQA1EGEXF+m0KKmiqKJLqZzmhLG1Vhp5z9sGCKP 6Dd46thEuSz4BC9Scw3t5dSmHsJvgauioea1wDOgN7B3RftK97Mql+Xvt4iqxuW/aUYk PMIlxInLcO5rVIZSr9Xo9VR4opH1wrtdt54VZH0ugUJg8Pzo52g3Gq+SX00xA6eYYpwN pln5qGrq+PWlWCEpITkqrj2ga/gAGvpk5uzM4gEQZLaraqlo/Vm9di6uf4r3p06MThvP iZsg== X-Gm-Message-State: AOJu0YzUoKGNoqHPyXSIXWAHaNe7dAnJrsyU3TRyyxwsHb6MuxNfUtIc a5VeTDSPJfjgznOvcHztYd3/5xnsxcvNjxESgq/rLZgHhzmPqf2ah1AYf7/mufrFaqb8i2OwoSV d7FsNng== X-Google-Smtp-Source: AGHT+IFH/Vhg8gC+IBR/LK26QeeoyuSyTcoZ8o4bh0Zthi7lVpULu9sW6r8I5IKdrqa2sfgHsl+kdg== X-Received: by 2002:a19:5e12:0:b0:51d:9ef1:7c62 with SMTP id 2adb3069b0e04-52964ea97f8mr6926575e87.6.1716808775096; Mon, 27 May 2024 04:19:35 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:34 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 14/15] RISC-V: Add Zbb optimized strlen as ifunc Date: Mon, 27 May 2024 13:18:59 +0200 Message-ID: <20240527111900.1060546-15-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-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, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org When building with Zbb enabled, strlen benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/strlen-generic.c | 24 ++++++++ sysdeps/riscv/multiarch/strlen-zbb.c | 23 ++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 6 ++ .../unix/sysv/linux/riscv/multiarch/strlen.c | 59 +++++++++++++++++++ 5 files changed, 115 insertions(+) create mode 100644 sysdeps/riscv/multiarch/strlen-generic.c create mode 100644 sysdeps/riscv/multiarch/strlen-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c diff --git a/sysdeps/riscv/multiarch/strlen-generic.c b/sysdeps/riscv/multiarch/strlen-generic.c new file mode 100644 index 0000000000..e2d59bd4ef --- /dev/null +++ b/sysdeps/riscv/multiarch/strlen-generic.c @@ -0,0 +1,24 @@ +/* Re-include the default strlen implementation. + Copyright (C) 2024 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 + +#if IS_IN(libc) +# define STRLEN __strlen_generic +#endif +#include diff --git a/sysdeps/riscv/multiarch/strlen-zbb.c b/sysdeps/riscv/multiarch/strlen-zbb.c new file mode 100644 index 0000000000..3be9e78556 --- /dev/null +++ b/sysdeps/riscv/multiarch/strlen-zbb.c @@ -0,0 +1,23 @@ +/* Re-include the default strlen implementation for Zbb. + Copyright (C) 2024 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 + . */ + +/* Build with Zbb enabled. */ +#define __CODEGEN_ATTRIBUTES __attribute__((target("arch=+zbb"))) +#define USE_ZBB_ORCB 1 +#define STRLEN __strlen_zbb +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index 69c4dd2d07..e48ca11149 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -11,6 +11,8 @@ sysdep_routines += \ strchrnul-generic \ strcmp \ strcmp-generic \ + strlen \ + strlen-generic \ # sysdep_routines ifeq ($(have-fattribute-zbb-support),yes) @@ -19,6 +21,7 @@ sysdep_routines += \ memrchr-zbb \ strchrnul-zbb \ strcmp-zbb \ + strlen-zbb \ # Zbb sysdep_routines endif diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index c761807a7a..9b4ae40941 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -84,5 +84,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, #endif IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_generic)) + IFUNC_IMPL (i, name, strlen, +#if HAVE_RISCV_FATTRIBUTE_ZBB + IFUNC_IMPL_ADD (array, i, strlen, has_zbb, __strlen_zbb) +#endif + IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_generic)) + return 0; } diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c new file mode 100644 index 0000000000..dec274af18 --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c @@ -0,0 +1,59 @@ +/* Multiple versions of strlen. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 IS_IN (libc) +/* Redefine strlen so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef strlen +# define strlen __redirect_strlen +# include +# include +# include +# include +# include + +extern __typeof (__redirect_strlen) __libc_strlen; + +extern __typeof (__redirect_strlen) __strlen_generic attribute_hidden; +extern __typeof (__redirect_strlen) __strlen_zbb attribute_hidden; + +static inline __typeof (__redirect_strlen) * +select_strlen_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ +#if HAVE_RISCV_FATTRIBUTE_ZBB + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __strlen_zbb; +#endif + + return __strlen_generic; +} + +riscv_libc_ifunc (__libc_strlen, select_strlen_ifunc); + +# undef strlen +strong_alias (__libc_strlen, strlen); +# ifdef SHARED +__hidden_ver1 (strlen, __GI_strlen, __redirect_strlen) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strlen); +# endif +#else +# include +#endif From patchwork Mon May 27 11:19:00 2024 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: 1939871 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=OwynvhHw; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VntWt3bm2z20PT for ; Mon, 27 May 2024 21:21:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C3AC638432F1 for ; Mon, 27 May 2024 11:21:44 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id BEB49385B50B for ; Mon, 27 May 2024 11:19:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BEB49385B50B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BEB49385B50B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808781; cv=none; b=HkhhE9oU8EAUpm1BLDxYQwQQF8B82stHoYepe64T9JdsZ4rkG3bkvHdxhF8XENXfkt9myuuyi1/sGFAuoo4Glm4EYptweJSUU0DRwbU1d/WbAV/hrWO98CzWuDMMnGmGJWyHgRDB3L5DwzuiyhPXPtAKu9xg48cxdfxPmRkGbmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716808781; c=relaxed/simple; bh=Zru5tRfky7uUI5nlmSnY9wXgMOaIF6JeZRZLN1THwLI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WVTA8091Qr7vxXAAceWgV0nDgxlSt4dHTozVvszzWsGSc9zGxWLM+YB4CmhqmUmiklkEgqN/Lo6V4+jgan1JvB5jMoJViOLCC5qxgAsFiAXs86v1fWwxRAZ5a1zDQ1gVq8htL0Df69Q3b13/C+ySsst0jxNheM4OB7JN49T/Oto= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-529597d77b4so3065776e87.0 for ; Mon, 27 May 2024 04:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1716808777; x=1717413577; 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=1YnX/TTTXRmXP6brc268dqfpbYWjVPFASzcNmzenlFo=; b=OwynvhHw2rGaJd8HE+ydop7UajEwxVPgbhrbn20twpe0wQDOwbQzqXkRPBai3LveM7 1rcUEwZA0kNEn2X3YGaNbV10281PFNjGRcOzcdUlatNnVugkN3U0dqB78yKUQv+rk9dd Oa/qkYqULYduJMolAB8OQpw8RG7SLWqjpRKHZCH3Qezzt1W76TZP/sBWBNjOWtPdqx09 VpdnfFl0I2PjnkTsx1cLUp4k6IEmw02oZnYpXGjMG9BLUZBEljnIvm/WPURNz8N0xT0S m0yxVXaXXZoKk41nbrbMbSrKssLSWzprjGOlmFkLZl3LZopYJOjxxMglHddpv/OgfUwj Lcng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716808777; x=1717413577; 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=1YnX/TTTXRmXP6brc268dqfpbYWjVPFASzcNmzenlFo=; b=R8IVobmo5ca1aDtVLX5X7UQin2/BPF2cf8DlByg6Ivpkdyxp8s8w3JGqGm2Cj7Cs5c 1Ho31RcfnojTYgqI+GV3T3kA395FyRdEDIDEjBk8QF6DrHsuHtmaVjztbUEDLtX0lzJj Ke84nADmHbf2U0ylcYs+uB0TQjmkNvDhJsI8NULbG9+S14YLSUfVG3et0u83H54s0eNB lqRFHPnJr2NTJjW8ySsyzb8lHyl45GA+NrrWjuKdi9hxN4yqzP4osLhflmcoPbs3NQPm lvkrkmXVEVWWm66+JtlPrCd4n9cn5HJTeOLdanf4gzZR35jPWQxufE0xW2VpDSdhXJ/q nQZA== X-Gm-Message-State: AOJu0YyXE7oEMv80iZhmo839VMYPEzMcQObjjO+yxDrO4+iv57eF3NbR hvCqlHBpbhJO81MShdha/BEGgBlaXgMAN84Brk7XvHe/cDN55xEQ+IrdxYfoDXjkWMjMDxefrNV j/wLf+g== X-Google-Smtp-Source: AGHT+IHu3Mgv7S6qY8A+j+1p6C+4cYHTUNUaI9hsot9RZZYwyoPSe4ya/qYbD2TP2+bTSXlPueEtRA== X-Received: by 2002:a19:a401:0:b0:523:b7ec:a222 with SMTP id 2adb3069b0e04-529667cfceemr5180307e87.51.1716808776922; Mon, 27 May 2024 04:19:36 -0700 (PDT) Received: from beast.fritz.box (static.239.130.217.95.clients.your-server.de. [95.217.130.239]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5296e887b1asm519861e87.32.2024.05.27.04.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 04:19:36 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: libc-alpha@sourceware.org, Adhemerval Zanella , Palmer Dabbelt , Darius Rad , Andrew Waterman , Philipp Tomsich , Evan Green , DJ Delorie , Vineet Gupta , Kito Cheng , Jeff Law Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH v2 15/15] RISC-V: Add Zbb optimized strncmp as ifunc Date: Mon, 27 May 2024 13:19:00 +0200 Message-ID: <20240527111900.1060546-16-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu> References: <20240527111900.1060546-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, KAM_MANYTO, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+incoming=patchwork.ozlabs.org@sourceware.org When building with Zbb enabled, strncmp benefits from using orc.b in find_zero_all(). This patch changes the build system such, that a non-Zbb version as well as a Zbb version of this routine is built. Further, a ifunc resolver is provided that selects the right routine based on the outcome of extension probing via hwprobe(). Signed-off-by: Christoph Müllner --- sysdeps/riscv/multiarch/strncmp-generic.c | 26 ++++++++ sysdeps/riscv/multiarch/strncmp-zbb.c | 25 ++++++++ .../unix/sysv/linux/riscv/multiarch/Makefile | 3 + .../linux/riscv/multiarch/ifunc-impl-list.c | 6 ++ .../unix/sysv/linux/riscv/multiarch/strncmp.c | 59 +++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 sysdeps/riscv/multiarch/strncmp-generic.c create mode 100644 sysdeps/riscv/multiarch/strncmp-zbb.c create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c diff --git a/sysdeps/riscv/multiarch/strncmp-generic.c b/sysdeps/riscv/multiarch/strncmp-generic.c new file mode 100644 index 0000000000..67eb89e62e --- /dev/null +++ b/sysdeps/riscv/multiarch/strncmp-generic.c @@ -0,0 +1,26 @@ +/* Re-include the default strncmp implementation. + Copyright (C) 2024 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 + +#if IS_IN(libc) +# define STRNCMP __strncmp_generic +# undef libc_hidden_builtin_def +# define libc_hidden_builtin_def(x) +#endif +#include diff --git a/sysdeps/riscv/multiarch/strncmp-zbb.c b/sysdeps/riscv/multiarch/strncmp-zbb.c new file mode 100644 index 0000000000..8485bdecb1 --- /dev/null +++ b/sysdeps/riscv/multiarch/strncmp-zbb.c @@ -0,0 +1,25 @@ +/* Re-include the default strncmp implementation for Zbb. + Copyright (C) 2024 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 + . */ + +/* Build with Zbb enabled. */ +#define __CODEGEN_ATTRIBUTES __attribute__((target("arch=+zbb"))) +#define USE_ZBB_ORCB 1 +#define STRNCMP __strncmp_zbb +#undef libc_hidden_builtin_def +#define libc_hidden_builtin_def(x) +#include diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile index e48ca11149..a4320d6419 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile @@ -13,6 +13,8 @@ sysdep_routines += \ strcmp-generic \ strlen \ strlen-generic \ + strncmp \ + strncmp-generic \ # sysdep_routines ifeq ($(have-fattribute-zbb-support),yes) @@ -22,6 +24,7 @@ sysdep_routines += \ strchrnul-zbb \ strcmp-zbb \ strlen-zbb \ + strncmp-zbb \ # Zbb sysdep_routines endif diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c index 9b4ae40941..a19d88fcf8 100644 --- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c @@ -90,5 +90,11 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array, #endif IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_generic)) + IFUNC_IMPL (i, name, strncmp, +#if HAVE_RISCV_FATTRIBUTE_ZBB + IFUNC_IMPL_ADD (array, i, strncmp, has_zbb, __strncmp_zbb) +#endif + IFUNC_IMPL_ADD (array, i, strncmp, 1, __strncmp_generic)) + return 0; } diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c new file mode 100644 index 0000000000..31a91adcac --- /dev/null +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c @@ -0,0 +1,59 @@ +/* Multiple versions of strncmp. + All versions must be listed in ifunc-impl-list.c. + Copyright (C) 2017-2024 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 IS_IN (libc) +/* Redefine strncmp so that the compiler won't complain about the type + mismatch with the IFUNC selector in strong_alias, below. */ +# undef strncmp +# define strncmp __redirect_strncmp +# include +# include +# include +# include +# include + +extern __typeof (__redirect_strncmp) __libc_strncmp; + +extern __typeof (__redirect_strncmp) __strncmp_generic attribute_hidden; +extern __typeof (__redirect_strncmp) __strncmp_zbb attribute_hidden; + +static inline __typeof (__redirect_strncmp) * +select_strncmp_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func) +{ +#if HAVE_RISCV_FATTRIBUTE_ZBB + unsigned long long int v; + if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0 + && (v & RISCV_HWPROBE_EXT_ZBB)) + return __strncmp_zbb; +#endif + + return __strncmp_generic; +} + +riscv_libc_ifunc (__libc_strncmp, select_strncmp_ifunc); + +# undef strncmp +strong_alias (__libc_strncmp, strncmp); +# ifdef SHARED +__hidden_ver1 (strncmp, __GI_strncmp, __redirect_strncmp) + __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strncmp); +# endif +#else +# include +#endif