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: 90946 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 60F0F385B52B for ; Mon, 27 May 2024 11:20:19 +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+patchwork=sourceware.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