From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19874CA0EE4 for ; Wed, 20 Aug 2025 18:26:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Jk43W/TR60vNU8rZqH4zyRhxz/9SPtuckf8iQLednsI=; b=gIXIsqUwNSQeHv RHcGdUA24wV5uOnn8Kw5yrotjH4VdvBz8k1fXKsaJAT4fnpTXbaF64mFku9AB3kJ97Z5wr+f22Tgr AWpdmVASucyW9Bz8Acu9KVc8Lrdrqgm3E7N1Wd59nWdE58olZlteHp6yDuzhjCxk0Fn3BInjis+cf e2Y5qzV4uNz3J1MTqQbt0s+uHssEcNhn6DNE1UAnaXdhG6VJq3FqmzmeWeqkji5RNlXJUJcMqkjT8 /b2u22Vxg+fPgiVebzC+gN6GLvYqhIPJY4gIp2mYVheWwSdVBuNlHRURsiG9OJhsZn6346K2wUZB/ cHVxBl8huMUh9vWGCzcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uonVZ-0000000Eg1e-0FFY; Wed, 20 Aug 2025 18:26:01 +0000 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uokMd-0000000EBUy-0c2Z for linux-riscv@lists.infradead.org; Wed, 20 Aug 2025 15:04:36 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-2445811e19dso53114715ad.1 for ; Wed, 20 Aug 2025 08:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755702274; x=1756307074; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=++r0iAI2yCp7ByMWBTkoq4eZJInhcfQbLd7c4fa729Y=; b=bZpdH90xxan6OqaSKkRp8WH9hK+rnzYEJN4f/XuFvnJcLtzgh1aMqWLLfnmn5ENv5g yjmk9wkpj7aftuutLvmcdTR7N0Wtfh03hHY17aAqzOBOkrrj3hXOPDfRsyXRkOjrmThL TGbo5SXkOj1fQlNuxOd5ixcDdWM0yPtc6msqIBtXh+I/IRpuHDTrrZuv0h4hX31pkSE5 dLhuG8bdVZ0fU4vaJhXvOWqsLweyjg8RX4omPHVEvokFPaGae5LWLLrZcVJPHe+jDRNO DVbX7kXri3NE1rJehssD/XyJAc5xc5uHOBHQjJqPmBoymarisL5atrXRQ6YySpVOY+P1 NvsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755702274; x=1756307074; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=++r0iAI2yCp7ByMWBTkoq4eZJInhcfQbLd7c4fa729Y=; b=vO061MJf+grbz15Kag3yIk2EthdE7A9WZr3PiKDWzuaWKfTha5CqbtoCN8vZWVdwag B00FGVd9MxZMJUFiasz1unhblGD3l1bc8Ca5cr68K2g2BZCmBAb8U7t4ip+ZNCpeveOg T6HpjpaLP/X04r7n2U+oW42IulgvzB92A7+M9E9VXyElO1vYO2gu6+ksxakuuJ5UMW+f RYhR+F/lo5TSBoXh3DpBOE2HoUB1v8IxY+lmhyRUDkJSnJJ1nRa4WXWtMSAdUk0NkYEk 9n1//ujihPjjBvyIUcGc4FwfTmNh1ozj2jjU35lP2ENPOEnXWBs6sCZGClQ2MZi3W/ea M+Qw== X-Forwarded-Encrypted: i=1; AJvYcCXd79INj8YIs6JkmgeVSxzXE/crWJSjIfsWT8itTmzsAwaNxP2Ybheew+fegWTJOaVGZ31Ku1HYXuCNmw==@lists.infradead.org X-Gm-Message-State: AOJu0YyIBsWDgkVskAd3tIDOt46oH6JfyCmT/4uczg/ySFETwZtjvQ0H bc43nmagQLtJbpO66AKRSz7Bg/2Co4u+qZUgKblLwR/NDiESgHMe7lFW X-Gm-Gg: ASbGncvU8zz7FuymPE3Xu7r+O3PuJknG9I+Pkm36ogo5pzIjjpjWVl/DwQURveig3K2 SxXsdH887vCmPmsYz6DzS5eKYu/Sk2fhpyRB4MFD6irbTCDGiYSzMi4wVrUNTDFacx6DQi+j2Bt Uvz6sQtJxF6tKkTrQLiyx5dXymdYTIjSpJAhGP3hsEaU5PKwlS6xRPxsiH/o9pnAAfUElJCkIOH jnN9ccy8Er63cExZL9XSvGAd2o2ShtIt78YZt7dkviS86CCkEFoeYGNuee9LyIFoLf4cNknN8aw ktzSFNV4m57tXAy4ajkpQ+3T8iWq00RaWcPdoafoIaTTnIhfWvv6n+pK8LsaXasSnXzjPSGZHYa 3mY6NfM161g6u5IGQiHYITw== X-Google-Smtp-Source: AGHT+IG5GibFX4nRPe3uAIyd9oVrLLUMsOnz3s+oCgefLCLc1FqEY0SeoiyMrK+0hu5OLASgGFtLgg== X-Received: by 2002:a17:903:1b6e:b0:245:fc41:eb53 with SMTP id d9443c01a7336-245fc41ecefmr466235ad.30.1755702274208; Wed, 20 Aug 2025 08:04:34 -0700 (PDT) Received: from localhost ([216.228.127.129]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-245ed53eb8bsm29017525ad.166.2025.08.20.08.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Aug 2025 08:04:33 -0700 (PDT) Date: Wed, 20 Aug 2025 11:04:31 -0400 From: Yury Norov To: Vivian Wang Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Rasmus Villemoes , Vivian Wang , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/6] riscv: bitops: Convert to use_alternative_likely Message-ID: References: <20250820-riscv-altn-helper-wip-v1-0-c3c626c1f7e6@iscas.ac.cn> <20250820-riscv-altn-helper-wip-v1-5-c3c626c1f7e6@iscas.ac.cn> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20250820-riscv-altn-helper-wip-v1-5-c3c626c1f7e6@iscas.ac.cn> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250820_080435_186797_2A785808 X-CRM114-Status: GOOD ( 20.12 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Wed, Aug 20, 2025 at 09:44:49PM +0800, Vivian Wang wrote: > Use use_alternative_likely() to check for RISCV_ISA_EXT_ZBB, replacing > the use of asm goto with ALTERNATIVE. > > The "likely" variant is used to match the behavior of the original > implementation using ALTERNATIVE("j %l[legacy]", "nop", ...). > > Signed-off-by: Vivian Wang > --- > arch/riscv/include/asm/bitops.h | 112 ++++++++++++++++++---------------------- > 1 file changed, 50 insertions(+), 62 deletions(-) > > diff --git a/arch/riscv/include/asm/bitops.h b/arch/riscv/include/asm/bitops.h > index d59310f74c2ba70caeb7b9b0e9221882117583f5..0257d547a96293909d90b017c8a48b508d0fd642 100644 > --- a/arch/riscv/include/asm/bitops.h > +++ b/arch/riscv/include/asm/bitops.h > @@ -47,20 +47,17 @@ > > static __always_inline unsigned long variable__ffs(unsigned long word) > { > - asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0, > - RISCV_ISA_EXT_ZBB, 1) > - : : : : legacy); > - > - asm volatile (".option push\n" > - ".option arch,+zbb\n" > - "ctz %0, %1\n" > - ".option pop\n" > - : "=r" (word) : "r" (word) :); > - > - return word; > - > -legacy: > - return generic___ffs(word); > + if (use_alternative_likely(0, RISCV_ISA_EXT_ZBB)) { I don't think that 'likely' is used properly here. The likely/unlikely wording has a meaning of a hint to the compiler: if (unlikely(WARN_ON(cond)) goto err; In your case, it's just meaningless, because whatever is 'likely' for one CPU, will be always 'unlikely' for another. > + asm volatile (".option push\n" > + ".option arch,+zbb\n" > + "ctz %0, %1\n" > + ".option pop\n" > + : "=r" (word) : "r" (word) :); > + > + return word; > + } else { > + return generic___ffs(word); > + } > } This tabs wipe most of the history. Can you reorganize your patch such that it preserves as much history as you can? if (use_alternative_unlikely(...)) return generic___ffs(); asm volatile (".option push\n" ".option arch,+zbb\n" "ctz %0, %1\n" ".option pop\n" : "=r" (word) : "r" (word) :); return word; And so on. Thanks, Yury _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 2D08E322746 for ; Wed, 20 Aug 2025 15:04:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755702276; cv=none; b=bWnYdVuS7ZRaW9F/BzpsgA6UCqjSBk/4oBvftUbkcJjS9SXqIhcKQfb6d6ELOTJPFrcwZVA0O09UEfAvYd4rjdfP+0X8vmwiFa9uJYOrcDIbWNxhUBfgJw/JBNPEqthwhdTm77cWX4LILSCXvbhXnu3ewmd2cunu64taGHVWvNs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755702276; c=relaxed/simple; bh=tb1q0p61kk4ggtfW+I2HjxsfCAKSB23I9pUdrtecWhw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=XQ/d+0d029B1+SUaX/Wj61E1JyhlSiNHuUFxQqIqnS7UH5LItjUAzNHdvSQ/40DpY/NbY10IuiWFZwO8P+Vf1UQ1tLGbJTvTy9KFfXRKBAN0vPwL3Iidv2E4imhgtLhDJhwB2Y08XKn/sT5HcH/UwEPpad9xGAtBCRNzHgR9IjA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=kYYnC95Z; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="kYYnC95Z" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2445811e19dso53114705ad.1 for ; Wed, 20 Aug 2025 08:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755702274; x=1756307074; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=++r0iAI2yCp7ByMWBTkoq4eZJInhcfQbLd7c4fa729Y=; b=kYYnC95Zl9vfSncYR4QXrYXo6Ala70ZicCFFNZNyrWcjG6LA+vsXBicOaN2m7Yrj+Y P9dFNK2KmdAd+y8gEWlxF7S4jKQVfv5umGCoDiu2Jwyv+ijlhawacuVXpC31kEV1HLLT TR03gbqD6FL2Bh++z0rOprkdjmmneO7lc6kqvOte/g9ZW1ZDqkQED0L0+p/S2i4YZqaR dEpsOMl4h0PqN6CjM/IfxkgtlbJ8HxC/1S883jN+Of2mFCGrd7fdCN1IQzyQy1eOZsUm re4FmimHxqT2NEB7b2hzIc/VE3WtZRQWeOk4nzQ3X8aE/nNjT6SRbA0WyVXYNy5zM2bE giRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755702274; x=1756307074; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=++r0iAI2yCp7ByMWBTkoq4eZJInhcfQbLd7c4fa729Y=; b=ptn+UNTwL03pJcRyGBSWOcAL/dnsC076MO5DZbPWKwLyQaysDmPktYGX5HYou8r5K8 Hd7RliLhlmF2FezwKfDUo2uhOMDsO1lFH5kDpi1BZqgJSNRmvv+wdwqfIlv8aJwxY1YN PP4k0aSdOyqUdkUw3JvL3AfpYEPWyLt1PvJ5MYBjPoX3buOv4oMdl3BvWKIxqf5UALYy 8khTyNAgIqtKLkiTL53q5dhZ+Td9VvBjG1emVypwXxsasTnfOYt2+djAFYrPR2cq7DQa f+J1mPIBUHCnMO4/eXdoDpQLCFPl+7/vdCpyki/94OOqvjpp8W3HDfqF3OrecRaARYGI r1SQ== X-Forwarded-Encrypted: i=1; AJvYcCUbUnt4yUCFgQi5FDGTWFQuHq+tGkAq3bzEtFV1KQ3nZIrrS5Lif95q2R5KUqXux8QjBqvZIWBrT0sV77o=@vger.kernel.org X-Gm-Message-State: AOJu0Yxd+Zn76M64FLMa77o78g/EppnfAVolRqpkZbi3/7W1tidwFfha I9NzCTwlLPJ1TqsHNcv47yWvk55i1mDye4WDdjfiVLWB0F9cGYvxV5AL X-Gm-Gg: ASbGncsrrhQDbuNUqG2pa1d1+xL8EmMxRm+g54Iw61gjNsx6GipVrx8hGek/zvifghr qWu2/7XAe7N9QDGQHPxADNjvAuMp0Em1WWjWmRUEqQGK/qaAK5guWYNvG7ILp6VaTWcr8XR/Oe1 oWJGOLQVGpH9vSWxcXRekMVJ0XJ83RO3Qxbwi6hV6+7+MTdVp0n+zYzhmL/YdcOIYPIhGq4kcB6 gh7sNrpb0nrQR2x9vpF3U3nQH5HfhkYYgkpDYLyvSMmCOJm0PoHNIar/g+XiCGDFO1xdGTEs9C7 EwLJZIcP97GKSu6e3gqsxXEMw8Tloupqi0aKoStHzpkqZHLoJIoUv84OxKVYNLIRfT4lPbB/aks NfFNsIp/FVt4nHWq8fy9reQ== X-Google-Smtp-Source: AGHT+IG5GibFX4nRPe3uAIyd9oVrLLUMsOnz3s+oCgefLCLc1FqEY0SeoiyMrK+0hu5OLASgGFtLgg== X-Received: by 2002:a17:903:1b6e:b0:245:fc41:eb53 with SMTP id d9443c01a7336-245fc41ecefmr466235ad.30.1755702274208; Wed, 20 Aug 2025 08:04:34 -0700 (PDT) Received: from localhost ([216.228.127.129]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-245ed53eb8bsm29017525ad.166.2025.08.20.08.04.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Aug 2025 08:04:33 -0700 (PDT) Date: Wed, 20 Aug 2025 11:04:31 -0400 From: Yury Norov To: Vivian Wang Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Rasmus Villemoes , Vivian Wang , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/6] riscv: bitops: Convert to use_alternative_likely Message-ID: References: <20250820-riscv-altn-helper-wip-v1-0-c3c626c1f7e6@iscas.ac.cn> <20250820-riscv-altn-helper-wip-v1-5-c3c626c1f7e6@iscas.ac.cn> 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=us-ascii Content-Disposition: inline In-Reply-To: <20250820-riscv-altn-helper-wip-v1-5-c3c626c1f7e6@iscas.ac.cn> On Wed, Aug 20, 2025 at 09:44:49PM +0800, Vivian Wang wrote: > Use use_alternative_likely() to check for RISCV_ISA_EXT_ZBB, replacing > the use of asm goto with ALTERNATIVE. > > The "likely" variant is used to match the behavior of the original > implementation using ALTERNATIVE("j %l[legacy]", "nop", ...). > > Signed-off-by: Vivian Wang > --- > arch/riscv/include/asm/bitops.h | 112 ++++++++++++++++++---------------------- > 1 file changed, 50 insertions(+), 62 deletions(-) > > diff --git a/arch/riscv/include/asm/bitops.h b/arch/riscv/include/asm/bitops.h > index d59310f74c2ba70caeb7b9b0e9221882117583f5..0257d547a96293909d90b017c8a48b508d0fd642 100644 > --- a/arch/riscv/include/asm/bitops.h > +++ b/arch/riscv/include/asm/bitops.h > @@ -47,20 +47,17 @@ > > static __always_inline unsigned long variable__ffs(unsigned long word) > { > - asm goto(ALTERNATIVE("j %l[legacy]", "nop", 0, > - RISCV_ISA_EXT_ZBB, 1) > - : : : : legacy); > - > - asm volatile (".option push\n" > - ".option arch,+zbb\n" > - "ctz %0, %1\n" > - ".option pop\n" > - : "=r" (word) : "r" (word) :); > - > - return word; > - > -legacy: > - return generic___ffs(word); > + if (use_alternative_likely(0, RISCV_ISA_EXT_ZBB)) { I don't think that 'likely' is used properly here. The likely/unlikely wording has a meaning of a hint to the compiler: if (unlikely(WARN_ON(cond)) goto err; In your case, it's just meaningless, because whatever is 'likely' for one CPU, will be always 'unlikely' for another. > + asm volatile (".option push\n" > + ".option arch,+zbb\n" > + "ctz %0, %1\n" > + ".option pop\n" > + : "=r" (word) : "r" (word) :); > + > + return word; > + } else { > + return generic___ffs(word); > + } > } This tabs wipe most of the history. Can you reorganize your patch such that it preserves as much history as you can? if (use_alternative_unlikely(...)) return generic___ffs(); asm volatile (".option push\n" ".option arch,+zbb\n" "ctz %0, %1\n" ".option pop\n" : "=r" (word) : "r" (word) :); return word; And so on. Thanks, Yury