From patchwork Sun Feb 25 16:46:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 20933 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp1655640dyb; Sun, 25 Feb 2024 08:46:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU2usqawT6b3lSOszwo+9Vgcs1AIec0gzfn5FMgSXYz4AlNzbO346yHxFfpsKxMnxO3QWLjN3Jcmz4ya42EHH9L31x+gw== X-Google-Smtp-Source: AGHT+IG0lvKq1yTuZpzx9/JSbpw/HJey+G5nzJx0RnOpB9DJT8bK4W62gSNQRF7olkreEocI66ST X-Received: by 2002:a17:903:24c:b0:1da:190c:3481 with SMTP id j12-20020a170903024c00b001da190c3481mr6947417plh.34.1708879612303; Sun, 25 Feb 2024 08:46:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708879612; cv=pass; d=google.com; s=arc-20160816; b=Rz7V3tTIb7jgsmeNJf6Umhg84ytt4F+CwQw9ds0Ryirma4aSLDOQWsZ2xf/GYvLFBN rxIwm30uGeRa20gH+DnoH/sasU18KcE2gGSmvEHjQNBJ1bNoKD8BYtrlxuuoxIDThN8f jF99DIz2022g8cOMFghNcFNsAO6p46o/TntYm3sQ6geDh4TfP0dAJIcK86If0g+cwhhw jglI+uzwbEUyCD62+VFW4qmYcz1/7WvwGGaLUtuz077H3LXviGlPMbkPMrQ1DHxWJS3P 4LFYr03BhG3oL/qkxNrvfFnzGR2J4ducdkNkR+lC1rNrtPaWc0MNTHJY80aKx0cejxwO dwjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:accept-language :message-id:date:thread-index:thread-topic:subject:cc:to:from; bh=iBStMTDN5NwroFPP+7XojDE4N6IT0Pa+riytRe/Vd7o=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=IFPP7JuOt+bD/yZZhDdgB60gwcmUBQsuvH1wABXtiOXLbfaNXZSYWH1ogq8PG/pDXv wpIp0CrUeihlri5JR2xkzmbcfz0gzIrPIuELLhXKBbHqSxmbNU/Vz4g+mSQy/bk26r0u gqtn4HH1un2p2EoZqUHIpzYZZI1Y2fgbofODbM0Dt1j8q+mvbZaFyUTqXX6V4/p7X7Mm BRP46mf1FxfpWyOp7z8ysvRCUkRQFMrqJQ0FBNnFo4Kn79RIMqzna9pklZh+O2Ag7xm2 wouJIXFHZdHtdWIPakBm/g6PSlZU7rR/jJBJ4gFcTNHlBFCTlrqiKuw48WYhaOcLZe66 l5Nw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-80205-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80205-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id x15-20020a170902ec8f00b001dc76797a4esi2339842plg.375.2024.02.25.08.46.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:46:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80205-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-80205-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80205-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com 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 C3655B20D00 for ; Sun, 25 Feb 2024 16:46:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AEE0318622; Sun, 25 Feb 2024 16:46:28 +0000 (UTC) Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14EF314276 for ; Sun, 25 Feb 2024 16:46:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.58.85.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879587; cv=none; b=uaOZNNeSFsMQ9YjRtxHc1XNZUgtVIlrihPCm6w4FfzhKeqyFUluK5gOmtP/2aocZkhh0hkYr4ZUvG7OqFpFnihWLBu3Eb+rJ5cywS1n1J0rCutTrCVUGdp4JAyFqpgEo1TSPZiOj7BBE1GkcnHECdSt3I6HG52D2JdJV9FRrRLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879587; c=relaxed/simple; bh=vFwDF1W1RkazrGXsBXcrCyhzRqXEEq2KkvvTlcmlZCA=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=nUkK7lLpx4omh1nRFn7D9cU87spkZdbNGb2YDTCPH4cipf3gJTo/I4IpeS1L3hV6//MQ8Lh+ORvHFlo+d8nKAuswu7kX8nZGIJC7nAjnnnIHrrvinO/GVaWNoqmO5tXt2DWZ1VSfYhxOCfmwhW7ahsev5q+wko9p3ynej13dWt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM; spf=pass smtp.mailfrom=aculab.com; arc=none smtp.client-ip=185.58.85.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ACULAB.COM Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=aculab.com Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-178-yjK-uS7gN62oNJ6hHLWGlQ-1; Sun, 25 Feb 2024 16:46:21 +0000 X-MC-Unique: yjK-uS7gN62oNJ6hHLWGlQ-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sun, 25 Feb 2024 16:46:20 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:46:20 +0000 From: David Laight To: "'linux-kernel@vger.kernel.org'" , "'Linus Torvalds'" , 'Netdev' , "'dri-devel@lists.freedesktop.org'" CC: 'Jens Axboe' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , "'linux-btrfs@vger.kernel.org'" , "'Andrew Morton'" , 'Andy Shevchenko' , "'David S . Miller'" , 'Dan Carpenter' , "'Jani Nikula'" Subject: [PATCH next v2 00/11] minmax: Optimise to reduce .i line length Thread-Topic: [PATCH next v2 00/11] minmax: Optimise to reduce .i line length Thread-Index: AdpoChcPZRn+4DJyQnmPt8VEo0gk8Q== Date: Sun, 25 Feb 2024 16:46:20 +0000 Message-ID: <0fff52305e584036a777f440b5f474da@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791890148280420406 X-GMAIL-MSGID: 1791890148280420406 The changes to minmax.h that changed the type check to a signedness check significantly increased the length of the expansion. In some cases it has also significantly increased compile type. This is particularly noticable for nested expansions. The fact that _Static_assert() only requires a compile time constant not a constant expression allows a lot of simplification. The other thing that compilicates the expansion is the necessity of returning a constant expression from constant arguments (for VLA). I can only find a handful of places this is done. Penalising most of the code for these few cases seems 'suboptimal'. Instead I've added min_const() and max_const() for VLA and static initialisers, these check the arguments are constant to avoid misuse. Patch [9] is dependant on the earlier patches. Patch [10] isn't dependant on them. Patch [11] depends on both 9 and 10. Changes for v2: - Typographical and spelling corrections to the commit messages. Patches unchanged. David Laight (11): [1] minmax: Put all the clamp() definitions together [2] minmax: Use _Static_assert() instead of static_assert() [3] minmax: Simplify signedness check [4] minmax: Replace multiple __UNIQUE_ID() by directly using __COUNTER__ [5] minmax: Move the signedness check out of __cmp_once() and __clamp_once() [6] minmax: Remove 'constexpr' check from __careful_clamp() [7] minmax: minmax: Add __types_ok3() and optimise defines with 3 arguments [8] minmax: Add min_const() and max_const() [9] tree-wide: minmax: Replace all the uses of max() for array sizes with max_const(). [10] block: Use a boolean expression instead of max() on booleans [11] minmax: min() and max() don't need to return constant expressions block/blk-settings.c | 2 +- drivers/gpu/drm/amd/pm/swsmu/smu_cmn.c | 2 +- drivers/gpu/drm/drm_color_mgmt.c | 4 +- drivers/input/touchscreen/cyttsp4_core.c | 2 +- .../net/can/usb/etas_es58x/es58x_devlink.c | 2 +- fs/btrfs/tree-checker.c | 2 +- include/linux/minmax.h | 211 ++++++++++-------- lib/vsprintf.c | 4 +- net/ipv4/proc.c | 2 +- net/ipv6/proc.c | 2 +- 10 files changed, 127 insertions(+), 106 deletions(-)