Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp558261rdb; Sat, 27 Jan 2024 21:07:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEaOSKzfXud855l28gnsyksxflgGfOOFl4184aIXSoEoOFgGKT1J4/ZQ4LhrOt7R/05Nb5f X-Received: by 2002:a05:6e02:17ca:b0:363:76b5:9a8b with SMTP id z10-20020a056e0217ca00b0036376b59a8bmr3069263ilu.32.1706418466829; Sat, 27 Jan 2024 21:07:46 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706418466; cv=pass; d=google.com; s=arc-20160816; b=cMa4jzYg8FlLkhar9SOqMFhjizx0Ecb2s4oMyW4O5iZCdIjuAExkOZ6+n+yAZin1dv kXteh6+SfmdmOYy/H9hs8F8glp0bgsUbeCNs/7ar1Dyu/WHpAK5qIutJh7VqbKaWf4Nj Ke0aUKE6Zab56cfZgkfPlq5CEJ1PKs4lSA+kWY/Orfuzu8mpattvNpN2wUF6W82B8aQz T3H1O4mC1vksUeZY4nV6oRKry+fYOPDBl5ZeOqLIFEsZSOCAZqCcgaB338l6N9BkQV+C nceh0CCcTCCCXtYdAqnZa6Gm++FnNOgwZyrk2O+Br97pAgtND5GsNlvWRmJT/gyTB2q1 KxdQ== ARC-Message-Signature: i=2; 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=FQBsNQfE0P3AMOj6B4RUDeOxeQtA43qqvQ0BuQwr7rw=; fh=FAZ7izxbqRRoU9uRgS6zahQ/zrZFMjmCvtZwzKwvMTc=; b=YPBUkGcFn2C2qLr2IPRQ3ciA9cBe3hePmADZNjIiQZmVRt3VkwMs+auNs8KL+/nSly GrM4ZK1fFCLXy9L51wE/eyXQfpXlp5X54VuzTKUw8vtm7v4jk5aDAXWdWdh4FnlMsoG/ Hpfj41+NWsVOAwB3n8SRGpzYw3BAPrvhemfLKv9r8cPDbnqHP0CLGOm6ylqwTJRpXbdX 3U34jUwm3SFj1gJIoeXNkSEDpWNGebo1MkWWopBrFrvTq1CUHYt1Y2kfrJ8oo0LEVlJy 3EJnMj14CM2YmT7IZUD7WNEWnA+I6MqUHxoP2SOak3QCpZxPaRdYiXP7JItHfPsetZfi Q62A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=V0wmCgX7; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-41538-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41538-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wanadoo.fr Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id q136-20020a632a8e000000b005d8b8f09180si1748186pgq.550.2024.01.27.21.07.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 21:07:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41538-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=V0wmCgX7; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-41538-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41538-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 38DAAB22868 for ; Sun, 28 Jan 2024 05:07:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 714111F955; Sun, 28 Jan 2024 05:06:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="V0wmCgX7" Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) (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 E67B81EB27 for ; Sun, 28 Jan 2024 05:06:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706418383; cv=none; b=UNfSTETIPKMDH3C9xomKSbNjHZtIFwL45sLv89VN7qxDes82RS/ss8ZSpEoHml1vA0kROcbgW7wu7BQLCsLEu/wy7nHgIBDfGNUGOTorPAdDelrCnqEnTuR4Stl4hbQP8K0OobIu28rtYs5tXdrb2XLzr4QeFEy+xqQtC6y1i2s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706418383; c=relaxed/simple; bh=R1pbFLI03IlZKTp/TgcUS71vFBkjz46xTjfOd1hIJ0k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XO7PV3s41/qIV6wzoHClEkHmVdhLUreOc4L42sx4cbJbt2aa7TK9FJEan0NIM+UaN/pqhnoe6UUzvK6E7bIkR0/7vhnl5uuvv4PwoTTCT0ukwgdhIjB0VlagtJcIfNY3gMD3lw/lkO4vFq8SvDAVDDcvuJcMkZXCjBcbTgKBymM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=wanadoo.fr; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=V0wmCgX7; arc=none smtp.client-ip=209.85.161.45 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-oo1-f45.google.com with SMTP id 006d021491bc7-59927972125so992648eaf.3 for ; Sat, 27 Jan 2024 21:06:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706418381; x=1707023181; 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=FQBsNQfE0P3AMOj6B4RUDeOxeQtA43qqvQ0BuQwr7rw=; b=V0wmCgX7E5aOxkoYKhW0gCF7B0ohqszlzAy+69baGiBHa8s/hLMMSdb3WW4tEtXcG+ mJTa5/7br8eWyEBDBl8zA+qVhBCGgujAjX7DnF1DanyQew/VjLtekiCPu7CBbsHQaKCY ROX4BvdcadezTVoL8RoaEst18MiUIDMEejp96ok5gJ1C0wiz08Hy4ysR1DJLeVLfuthv IyG3RKP7sMgPL0Ug15DBiyLdlq/ltC8TUuBpYO4XL7SjAh4IOz41URZl46VyaTjPZbdO PC1fxweQV2WDwHHVtxUD1JNqDflu39rphFDIP0C4gqAtpmLbgdccdkR7CaB1QS0kflBc H4mA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706418381; x=1707023181; 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=FQBsNQfE0P3AMOj6B4RUDeOxeQtA43qqvQ0BuQwr7rw=; b=saeVgFsZZdqvLOzpZ1pQbrWBLvuDhmAxtqOYaWV4neUHkQqHeikGxnynBtDrTjBnwU YEcbVZBvXbVIrixCQJYgMVZ1ofmDOYaWorlOb+nicfxIRja3tidGUrUsfCqOKwuEpNyj dV3o92qbyPRijO6QGScJFPqAi4e1OvN9FeAn66iwzaLIy05/k0JCn6jZILOoEMwpsFwn TRfsOUYawy2DOJlVc1GIUQ+mkU4a9SphyzndDYg/RwzV286Nuxa5DX0UbD2/0O+rwsXx tgvGD+9tjktmW/bdpr+1htMdX5+/mSb5lwaLgMK1zR8FUPA5Ljq23lk40yaDH3GoVPJa mrxg== X-Gm-Message-State: AOJu0Yydo9b4cCx61Lf2C0aH/YMGOG8vKTLPKER6wf6geSAU32w9RSr1 yE4EU7CFl/ZaYyq6TqEhJ63Evud+zoH0OLBUqbsbN3jc9c3x/xyn X-Received: by 2002:a05:6830:4106:b0:6db:b046:2189 with SMTP id w6-20020a056830410600b006dbb0462189mr3439811ott.24.1706418380989; Sat, 27 Jan 2024 21:06:20 -0800 (PST) Received: from localhost.localdomain (124x33x176x97.ap124.ftth.ucom.ne.jp. [124.33.176.97]) by smtp.gmail.com with ESMTPSA id lp17-20020a056a003d5100b006ddd182bf1csm3550372pfb.46.2024.01.27.21.06.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 21:06:20 -0800 (PST) Sender: Vincent Mailhol From: Vincent Mailhol To: Andrew Morton , linux-kernel@vger.kernel.org Cc: Yury Norov , 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-m68k@lists.linux-m68k.org, Vincent Mailhol Subject: [PATCH v4 4/5] hexagon/bitops: use __builtin_{clz,ctzl,ffs} to evaluate constant expressions Date: Sun, 28 Jan 2024 14:00:10 +0900 Message-ID: <20240128050449.1332798-5-mailhol.vincent@wanadoo.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240128050449.1332798-1-mailhol.vincent@wanadoo.fr> References: <20221111081316.30373-1-mailhol.vincent@wanadoo.fr> <20240128050449.1332798-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. On linux 6.7 with an allyesconfig and clang 17.0.6, it saves roughly 4 KB. $ size --format=GNU vmlinux.before vmlinux.after text data bss total filename 4827900 1798340 364057 6990297 vmlinux.before 4827072 1795060 364057 6986189 vmlinux.after 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 e856d6dbfe16..c74a639c84f3 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.43.0