Received: by 2002:a05:7412:8d08:b0:f9:2d0a:d759 with SMTP id bj8csp10103rdb; Sat, 16 Dec 2023 23:14:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGEGT1XJVpT43KfQNiLMmpDwbHSvjIf33te47gRjvUL5yt5bl18py+zY0TikNnkP4GOQcfO X-Received: by 2002:a05:6808:1146:b0:3ba:32b:2539 with SMTP id u6-20020a056808114600b003ba032b2539mr16355297oiu.91.1702797263226; Sat, 16 Dec 2023 23:14:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702797263; cv=none; d=google.com; s=arc-20160816; b=n6vNSamtLYWkdFWxKLZgY/fm+eizE9zmHgTkYTXSfQLG/E2M8lfUmoi58Lr3UI3Oal K/Wyz+Uy8t4j+OspiLSSgR2EnakBQ4lzsQO38EEh52kVcjY2+9+zzKuQBT1houLMFwHe kWdzOZS4S8BXWxiY41yhn4EGt10NJ+56NhpLWWcxZd+S9WwLurBYhM/bjLj/McvdYn0r L5gkDaZGHuALHvzKyBDzR3tBtrThYJlNuKFDVhutihPkmLxa4PjEvQGU+kBaroh4mheR 3B5BogIE7gr+dtBevupS9JKCQ34uGQF7ynRBSzp4UWXlrq9/af+105nV6vs6iQ+FWEtW prTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:sender:dkim-signature; bh=8vyhSqduyGw//DWggAhtjkJM+OOGpuFMjvvJjdOe8jo=; fh=O+LHMXuc4QZ+LwJ18sh+OSxw9k9Vm9ydCfTOjonl8SY=; b=s25leDNLdhtEjTvZE37ETG0g/aktLJAmNUs1W141IxBcC9msLVJKYQt+YXtzS7IigN dbIN9vVTt+4LL7yjNOzs2qF2QpZ1cUp+mpefnKtaKZtCZ/AKGLgUMXbR3FL0d1+j348i 2y8Q/tEPsqKWDUhtlUFPUdEP2rohG51j8gguScx27jxhGVf6geZqdTe+i7byEshzvdzW qppB0J9UC7QM0tTH9OwbgWiR0N3yN/H9WMhv2sMtSfWxIL1BUWWXglt4aImrybRn4ON8 g5OhrnudKc62k89vVo4fDo4XnYovY2nLSC6QS4+S4uUiyKT+H3JAoLzxv0TTvkGgsrC8 YbnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=k30N9yvj; spf=pass (google.com: domain of linux-kernel+bounces-2493-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ot1-20020a17090b3b4100b0028b67c91156si1153842pjb.99.2023.12.16.23.14.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 23:14:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2493-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=@gmail.com header.s=20230601 header.b=k30N9yvj; spf=pass (google.com: domain of linux-kernel+bounces-2493-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr 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 BF007282C08 for ; Sun, 17 Dec 2023 07:14:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD17A79E2; Sun, 17 Dec 2023 07:13:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k30N9yvj" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.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 60FB76FD5; Sun, 17 Dec 2023 07:13:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=wanadoo.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-3ba00fe4e94so1705082b6e.1; Sat, 16 Dec 2023 23:13:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702797215; x=1703402015; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=8vyhSqduyGw//DWggAhtjkJM+OOGpuFMjvvJjdOe8jo=; b=k30N9yvjoCL8Oux3twFbUdaV8+ZgXrVdikZwowb1Zfr4q/fYxUWwp+nLraGTSODz6t CQx5j9s541072br1zWdfPHmZQGn1ULbM8RdB7+ojxyxSzHhH4qgr5vYBKs9aVcqeR8sj KL4yXC9ZoHhkqDcFKL/ImiLYR8bQP6QHAF+Y3u/+IhSJquqSypaSegDjyuAv8vtUNC0I QYeeE8xGOk9md87TW9mQvxvfhcikXKhBsE9OHsmTxEojnK4CXND8zfTqS5VeGsJHlO60 /i+qgiF+1GqB6tVZIxri45D9ManLLVhLYcDFrgqSC+gKyYuL+4sGki6P5Orv0RncCVMx kEow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702797215; x=1703402015; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8vyhSqduyGw//DWggAhtjkJM+OOGpuFMjvvJjdOe8jo=; b=gr6Sc90dJmMoK/02sZ56qXPp8SnZMMLesO2RCWsyVGpFNA7nXoa4MHRR6mw5JHEbrr 3cVN9PI3zmK2yKu2gQWpdnvSrNK2MYiIlHCZ5LhTzrSQV4C9BqqE7m5QhRSOD+Sqj11D SY/t1Dc6R9NCMYUO7NyGeKLYXXcv8IMv2iV2UnPgi8Ym/ReErHmpYy/+8T5XxT364AZq ZAoQAs+ACwmSVUI+I6R8S8t4X9SaHIIiocHLLfC32kwu23305n7UWHaiTgYQGVyZa1Ya 9OcQhayRoylrWvrKGukAzq7jJdhTPLI9n4Hia00H0gepkV099RcjHvYnoBnvlEmOrjpW iJ8w== X-Gm-Message-State: AOJu0YyaYYF5xBllLhVeVpfYqSpsx16kSULZv72lLGnKMjqA/RzcTwkY OmJwfWZXg+bKuiP8v1q7B2I= X-Received: by 2002:a05:6808:3309:b0:3ba:231:cd44 with SMTP id ca9-20020a056808330900b003ba0231cd44mr19137878oib.43.1702797215473; Sat, 16 Dec 2023 23:13:35 -0800 (PST) Received: from XH22050090-L.ad.ts.tri-ad.global ([103.175.111.222]) by smtp.gmail.com with ESMTPSA id b17-20020a056a000cd100b0068ffb8da107sm15740231pfv.212.2023.12.16.23.13.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Dec 2023 23:13:35 -0800 (PST) Sender: Vincent Mailhol From: Vincent Mailhol To: Andrew Morton , linux-kernel@vger.kernel.org, Yury Norov Cc: Nick Desaulniers , Douglas Anderson , Kees Cook , Petr Mladek , Randy Dunlap , Zhaoyang Huang , Geert Uytterhoeven , Marco Elver , Brian Cain , Geert Uytterhoeven , Matthew Wilcox , "Paul E . McKenney" , linux-hexagon@vger.kernel.org, linux-m68k@lists.linux-m68k.org, Vincent Mailhol Subject: [PATCH v3 4/5] hexagon/bitops: use __builtin_{clz,ctzl,ffs} to evaluate constant expressions Date: Sun, 17 Dec 2023 16:12:49 +0900 Message-Id: <20231217071250.892867-5-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231217071250.892867-1-mailhol.vincent@wanadoo.fr> References: <20221111081316.30373-1-mailhol.vincent@wanadoo.fr> <20231217071250.892867-1-mailhol.vincent@wanadoo.fr> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The compiler is not able to do constant folding on "asm volatile" code. Evaluate whether or not the function argument is a constant expression and if this is the case, return an equivalent builtin expression. Reference: commit fdb6649ab7c1 ("x86/asm/bitops: Use __builtin_ctzl() to evaluate constant expressions") Link: https://git.kernel.org/torvalds/c/fdb6649ab7c1 Signed-off-by: Vincent Mailhol --- arch/hexagon/include/asm/bitops.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/hexagon/include/asm/bitops.h b/arch/hexagon/include/asm/bitops.h index 950d4acc2edc..12c6ad1ea2ed 100644 --- a/arch/hexagon/include/asm/bitops.h +++ b/arch/hexagon/include/asm/bitops.h @@ -204,6 +204,9 @@ static __always_inline long ffz(int x) { int r; + if (__builtin_constant_p(x)) + return __builtin_ctzl(~x); + asm("%0 = ct1(%1);\n" : "=&r" (r) : "r" (x)); @@ -221,6 +224,9 @@ static __always_inline int fls(unsigned int x) { int r; + if (__builtin_constant_p(x)) + return x ? BITS_PER_TYPE(x) - __builtin_clz(x) : 0; + asm("{ %0 = cl0(%1);}\n" "%0 = sub(#32,%0);\n" : "=&r" (r) @@ -242,6 +248,9 @@ static __always_inline int ffs(int x) { int r; + if (__builtin_constant_p(x)) + return __builtin_ffs(x); + asm("{ P0 = cmp.eq(%1,#0); %0 = ct0(%1);}\n" "{ if (P0) %0 = #0; if (!P0) %0 = add(%0,#1);}\n" : "=&r" (r) @@ -264,6 +273,9 @@ static __always_inline unsigned long __ffs(unsigned long word) { int num; + if (__builtin_constant_p(word)) + return __builtin_ctzl(word); + asm("%0 = ct0(%1);\n" : "=&r" (num) : "r" (word)); @@ -282,6 +294,9 @@ static __always_inline unsigned long __fls(unsigned long word) { int num; + if (__builtin_constant_p(word)) + return BITS_PER_LONG - 1 - __builtin_clzl(word); + asm("%0 = cl0(%1);\n" "%0 = sub(#31,%0);\n" : "=&r" (num) -- 2.25.1