Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp281259lqo; Wed, 15 May 2024 14:27:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUnHg0XjpC1jD7z/U5lGulJUjL3DElr3auj1tgm6O2LG+sjMxJEjCLdNUEO2wjvhSD07Pqvw1saVDZwdOR+Nq9TG/Glfo5ZGXBPKrnC3g== X-Google-Smtp-Source: AGHT+IEyCGKU7jNXxHhZA5f7W/fLAEvjDWFz8IcSPzlCL2zxBnLtetoJephhuj4pXN/UmYsCmfEo X-Received: by 2002:a17:902:ccd0:b0:1ef:442c:a023 with SMTP id d9443c01a7336-1ef442ca12bmr230055025ad.38.1715808435655; Wed, 15 May 2024 14:27:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715808435; cv=pass; d=google.com; s=arc-20160816; b=GFH/Dp6YfTtjB3KYruWoptgfx6DjG0fbtuh0HxEDXpQvHlp0K6gowwUM/JJBhuqLwX ix82UEGhhPRC3sQlZCNmhAlLJeOeGeVQT4iIxF54vBcUVxtplFTay5+ehqZyLga1/CxG cYoikNqBm4Sy0xoTrdzfbUSBSq0MSloyn58/5u0+/qyOfsnhrZDKIN0xdKO+UgQVCcMu LvLH57Q1g3DLzecBs9LSYv2wTfVMyOcOC+YDcaYuk+1tHJ9sEYHOz24pr53gBPza0Q6j BkbyV/dKDNkQQ5WsR6TEhtvBbUooul2O80EMlAdcIoI3MIdUCS45JU15BOJqiCwrXog7 jKpQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=NdYFoFjeOLfZ5ODsfLOrb3QUJFvf95EQYI0EaFj358o=; fh=Dsl8aKuIByz7oA8YBGcNcTYPPa1gC9zV9zM3bayRzdE=; b=Qb8w7WWvki1H+tFeQ9BqDNkyqRyOOQ/6ctIQOo+bjyRehjkvqMuUC3OrzR5xlkvZjD 6RFmJwU6CfDoC1NCmK1PYYHoLu1B96j9p3gkiyd40ZRrO7KXb2a50K8xjYEvCFTAdcgk ZacdeOrZ0add0rBvRSH/0/9Q6LTIM3M4keMyOleWuXE6QqFYLobIhkrBjz2ikFbVfAGC MeAq/VnqE1eLAj7Sx0urJSNPk+9bFuUBwvCXkjHXfvoD5z65oJpKlravsMOSRsd0e5iH y7r29S2cnItAZgLMVKu4/0GUkXWeff0cnAi0clYlLgTIXezcVH5mi8VBMnP70EgU3Yay TH4g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=nY3hLGFF; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-180387-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180387-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0c15ed9bsi127692355ad.535.2024.05.15.14.27.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 14:27:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180387-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=nY3hLGFF; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-180387-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180387-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 33451283589 for ; Wed, 15 May 2024 21:27:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D46B715B540; Wed, 15 May 2024 21:26:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="nY3hLGFF" Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FEAD15B579 for ; Wed, 15 May 2024 21:26:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715808396; cv=none; b=CPr2xGUt6G58ZGvillRt3wubNBnBUtlbEmcSUJIyGKp3hurfRPXjln5SzmJz8ZVbxpRWkW5dE2y6IM0q5ARzG+tjCob713imCouCmt/H8vFFqCtin5ZEuaDhrmMAXd3VwczWin6Iy0T6EVdh4D0GF7HVWMezGgfdaIDqynphQ0I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715808396; c=relaxed/simple; bh=p+999qomFpgC+1QPBVR4U3Loq/+tlgQihw1MdjTQtgg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a5E7NsexMVjDR+3wh0jdPQoov6OVxvY9arI33xgaWM+ze1LpxkjBvuexOUejIX11rIWaoJKGHfY9XdDbkpbbexvHPBSmsl1SQwMQexqnYZretu9CQ5dbAGbz8e6oLRJQnqwzuw+EFtxxZZzPgCxhNQYwrVzh4bki+KO75LRBgHk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=nY3hLGFF; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6f453d2c5a1so6033913b3a.2 for ; Wed, 15 May 2024 14:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1715808394; x=1716413194; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=NdYFoFjeOLfZ5ODsfLOrb3QUJFvf95EQYI0EaFj358o=; b=nY3hLGFFurbw+0bXBJBrQ5ALG4mirhacLK3hniScp07CjXbEtsHlTdojDBPuu8Du9W EqpJLdyKfJA/gzkIOwaFwBDwH+1CgsEYV/h3rIVCQrQbM5i8O3iC3TSOFlHfle3UXJWh LBcArIq8GK2GndxsU7r6a+ulWCmsNSBkqrHSeGUYTcQD5curfg+wR0JHa05W0w4uoCjb Fw4GAQcBxOg4JwOB63qvo/jGj7xxsz7BPWXb3ErdTV3N7+GDwwIEv9gdMeca4BnQH7j2 AJub2L0Cnjfg4MlJRzKYGhd5eZN0gcHR9HJzkOa2BQrBG0006MfwdaZdfgu1KzrfO+9j BW7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715808394; x=1716413194; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NdYFoFjeOLfZ5ODsfLOrb3QUJFvf95EQYI0EaFj358o=; b=eI1LgyuQKhEf5D4YspVKsUvebfMmifqZhXj4DmOV3ytxY084rzANvIKkwh3ovt55Zu 4F1ZPPRySfofwV4AjvhYO97zlcKTo0ww6X7u79zP5gb7XoGV6jny0KQu1b+EzlBHJEmR 323pnfXk9xAD4NYpWcMBzrKbdnm3P3gfDiAWRN/IA/YT7V30/T9w7/Wd6xZT2jbCibMA uX/KWd+fzCMJOJmwkSppnWq9g+nhZOGAzbFYHr+X8u6F2uYRNCd8PvPTePtd9RiIwQuK f1GxUIg5S6lC7u8xRBCG6DgLaJlnHyRxxujMNxgJQx2YsDDT+Of/E25ZivEjsYL7jP3n 6UHg== X-Forwarded-Encrypted: i=1; AJvYcCWznp0rv86GeewnLu8r5xax8Cm1J40mXrbNx/ifHybldYwmv+s4TTB8Zu8M79r7auOraOmgH+ZO2L0x5vFXSfgMLJOog/Qg2Qg2DQAr X-Gm-Message-State: AOJu0Yxg0XznFb+KRfo/GSYwclESnaRa9lFH8DluaqJdD6HJu9PcodPZ 5yvKnoRgj7WEqBRJ4h6h0T6kqYmnBLnttM3GSeUkBw9FC51pOS+pjBQCH67DdjM= X-Received: by 2002:a05:6a21:890b:b0:1b0:225:2b2c with SMTP id adf61e73a8af0-1b00225ba86mr10446547637.13.1715808394473; Wed, 15 May 2024 14:26:34 -0700 (PDT) Received: from charlie.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2af2b30sm11970243b3a.146.2024.05.15.14.26.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 14:26:33 -0700 (PDT) From: Charlie Jenkins Date: Wed, 15 May 2024 14:26:16 -0700 Subject: [PATCH 4/4] riscv: cpufeature: Extract common elements from extension checking Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240515-support_vendor_extensions-v1-4-b05dd5ea7d8d@rivosinc.com> References: <20240515-support_vendor_extensions-v1-0-b05dd5ea7d8d@rivosinc.com> In-Reply-To: <20240515-support_vendor_extensions-v1-0-b05dd5ea7d8d@rivosinc.com> To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Evan Green Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Charlie Jenkins X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1715808387; l=5623; i=charlie@rivosinc.com; s=20231120; h=from:subject:message-id; bh=p+999qomFpgC+1QPBVR4U3Loq/+tlgQihw1MdjTQtgg=; b=nvAv/0LgY6kSiMCHuWGhyPONt3JRLfURhijQYBNGtpiA/+Dzo7zJIn4kc3vJOP6L6e1AmnmTf Od31m1W2ikaCwSVkcCJneMyoWiEMl/8gLTK+287SGDd9fAVIyDcJXsi X-Developer-Key: i=charlie@rivosinc.com; a=ed25519; pk=t4RSWpMV1q5lf/NWIeR9z58bcje60/dbtxxmoSfBEcs= The __riscv_has_extension_likely() and __riscv_has_extension_unlikely() functions from the vendor_extensions.h can be used to simplify the standard extension checking code as well. Migrate those functions to cpufeature.h and reorganize the code in the file to use the functions. Signed-off-by: Charlie Jenkins Reviewed-by: Conor Dooley --- arch/riscv/include/asm/cpufeature.h | 78 +++++++++++++++++------------- arch/riscv/include/asm/vendor_extensions.h | 28 ----------- 2 files changed, 44 insertions(+), 62 deletions(-) diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h index 550d661dc78d..b029ca72cebc 100644 --- a/arch/riscv/include/asm/cpufeature.h +++ b/arch/riscv/include/asm/cpufeature.h @@ -96,59 +96,66 @@ extern bool riscv_isa_fallback; unsigned long riscv_isa_extension_base(const unsigned long *isa_bitmap); +#define STANDARD_EXT 0 + bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, unsigned int bit); #define riscv_isa_extension_available(isa_bitmap, ext) \ __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_##ext) -static __always_inline bool -riscv_has_extension_likely(const unsigned long ext) +static __always_inline bool __riscv_has_extension_likely(const unsigned long vendor, + const unsigned long ext) { - compiletime_assert(ext < RISCV_ISA_EXT_MAX, - "ext must be < RISCV_ISA_EXT_MAX"); - - if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { - asm goto( - ALTERNATIVE("j %l[l_no]", "nop", 0, %[ext], 1) - : - : [ext] "i" (ext) - : - : l_no); - } else { - if (!__riscv_isa_extension_available(NULL, ext)) - goto l_no; - } + asm goto(ALTERNATIVE("j %l[l_no]", "nop", %[vendor], %[ext], 1) + : + : [vendor] "i" (vendor), [ext] "i" (ext) + : + : l_no); return true; l_no: return false; } -static __always_inline bool -riscv_has_extension_unlikely(const unsigned long ext) +static __always_inline bool __riscv_has_extension_unlikely(const unsigned long vendor, + const unsigned long ext) { - compiletime_assert(ext < RISCV_ISA_EXT_MAX, - "ext must be < RISCV_ISA_EXT_MAX"); - - if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) { - asm goto( - ALTERNATIVE("nop", "j %l[l_yes]", 0, %[ext], 1) - : - : [ext] "i" (ext) - : - : l_yes); - } else { - if (__riscv_isa_extension_available(NULL, ext)) - goto l_yes; - } + asm goto(ALTERNATIVE("nop", "j %l[l_yes]", %[vendor], %[ext], 1) + : + : [vendor] "i" (vendor), [ext] "i" (ext) + : + : l_yes); return false; l_yes: return true; } +static __always_inline bool riscv_has_extension_unlikely(const unsigned long ext) +{ + compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX"); + + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) + return __riscv_has_extension_unlikely(STANDARD_EXT, ext); + + return __riscv_isa_extension_available(NULL, ext); +} + +static __always_inline bool riscv_has_extension_likely(const unsigned long ext) +{ + compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX"); + + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) + return __riscv_has_extension_likely(STANDARD_EXT, ext); + + return __riscv_isa_extension_available(NULL, ext); +} + static __always_inline bool riscv_cpu_has_extension_likely(int cpu, const unsigned long ext) { - if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && riscv_has_extension_likely(ext)) + compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX"); + + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && + __riscv_has_extension_likely(STANDARD_EXT, ext)) return true; return __riscv_isa_extension_available(hart_isa[cpu].isa, ext); @@ -156,7 +163,10 @@ static __always_inline bool riscv_cpu_has_extension_likely(int cpu, const unsign static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsigned long ext) { - if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && riscv_has_extension_unlikely(ext)) + compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX"); + + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) && + __riscv_has_extension_unlikely(STANDARD_EXT, ext)) return true; return __riscv_isa_extension_available(hart_isa[cpu].isa, ext); diff --git a/arch/riscv/include/asm/vendor_extensions.h b/arch/riscv/include/asm/vendor_extensions.h index a6959836f895..d21e411d7338 100644 --- a/arch/riscv/include/asm/vendor_extensions.h +++ b/arch/riscv/include/asm/vendor_extensions.h @@ -47,34 +47,6 @@ bool __riscv_isa_vendor_extension_available(int cpu, unsigned long vendor, unsig __riscv_isa_vendor_extension_available(VENDOR_EXT_ALL_CPUS, vendor, \ RISCV_ISA_VENDOR_EXT_##ext) -static __always_inline bool __riscv_has_extension_likely(const unsigned long vendor, - const unsigned long ext) -{ - asm goto(ALTERNATIVE("j %l[l_no]", "nop", %[vendor], %[ext], 1) - : - : [vendor] "i" (vendor), [ext] "i" (ext) - : - : l_no); - - return true; -l_no: - return false; -} - -static __always_inline bool __riscv_has_extension_unlikely(const unsigned long vendor, - const unsigned long ext) -{ - asm goto(ALTERNATIVE("nop", "j %l[l_yes]", %[vendor], %[ext], 1) - : - : [vendor] "i" (vendor), [ext] "i" (ext) - : - : l_yes); - - return false; -l_yes: - return true; -} - static __always_inline bool riscv_has_vendor_extension_likely(const unsigned long vendor, const unsigned long ext) { -- 2.44.0