From patchwork Sun Jul 28 14:17:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13744002 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57873C3DA64 for ; Sun, 28 Jul 2024 14:18:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CC3FD6B007B; Sun, 28 Jul 2024 10:18:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4DB66B0083; Sun, 28 Jul 2024 10:18:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AEEDA6B0085; Sun, 28 Jul 2024 10:18:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8E1296B007B for ; Sun, 28 Jul 2024 10:18:27 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 522AAA31A7 for ; Sun, 28 Jul 2024 14:18:27 +0000 (UTC) X-FDA: 82389366654.08.9B9C025 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by imf23.hostedemail.com (Postfix) with ESMTP id F2E19140012 for ; Sun, 28 Jul 2024 14:18:24 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf23.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722176246; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DjZVGJZdnfX63W8j/hevc8uS49pFHS0tB9VoukTPFEw=; b=2MMl0yqociK0spSv187vsiAhCjJHHxeeTHT6soiDllgEYEgv5WIvZXemrIlQnXdpsGkLKx 3r2+NJ2aVUxz0froJG7aWMMGCbz6r15ZSNgL8JyO1hWURTn1u2CXSxaHTWbTy3KXV0Qlk/ a+P5rep4EdiApHXExrTN31rQqXdIYLM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722176246; a=rsa-sha256; cv=none; b=5KWttwuSzaoAIP4faySqFmfOf7d2w5+44PuWPnZrVHG5zd78QcmJdTDTyNW7EheLPprI9+ sh2TELt8UWC1Wpjgm5ZXGtdIzqnqj4REx4eDipkplqC3q/2ZqqpwOpYIb4hyfUvzuy2O7L 9G3oLrI7up0z7ylRItIFDc1ulBxQFcI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf23.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@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-68-U7LTviH9N2qGDn-NaZVzAQ-1; Sun, 28 Jul 2024 15:18:20 +0100 X-MC-Unique: U7LTviH9N2qGDn-NaZVzAQ-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, 28 Jul 2024 15:17:36 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jul 2024 15:17:36 +0100 From: David Laight To: "'linux-kernel@vger.kernel.org'" CC: 'Linus Torvalds' , 'Jens Axboe' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , 'Arnd Bergmann' , "'Jason@zx2c4.com'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , 'Lorenzo Stoakes' Subject: [PATCH v2 1/8] minmax: Put all the clamp() definitions together Thread-Topic: [PATCH v2 1/8] minmax: Put all the clamp() definitions together Thread-Index: Adrg+PsJWBOjJVDsQ/+qaYGHKHGutQ== Date: Sun, 28 Jul 2024 14:17:35 +0000 Message-ID: <5cd3e11780df40b0b771da5548966ebd@AcuMS.aculab.com> References: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> In-Reply-To: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: F2E19140012 X-Stat-Signature: jop63age4hq7uxp7exqjis8ipswy1ewj X-Rspam-User: X-HE-Tag: 1722176304-605801 X-HE-Meta: U2FsdGVkX1+tDmmox8dfBtJmjLRY/al7vsoiS/nW4dhKtiW+rKbdNUhc0pe4sUjRdqq6yqyw7QtCZm3J/sB5gtR3qULi3P+aXLUJkYWgR7amiNCe+KYqlcvk7pNS6H/JQjiiH+iuc+1Ioi72cANnc3cx7GrinJr3auhbM5gL0pj1ApWci7mJJNDdZHhfIhBTAgTY3AVS/5hPTeXj7UaHLkQ5wn8Ni54purxOjBpyOsNVTTsSp1fWzpPnVREos7LkYGngK3ZK3JnMtOMuv/GTa/DZ4ocVMkkueEyCOKNsPj90YtH55iJskt89IPE55N0YbUmCrYIJQL/WvVihH/43E+2FEe4UGQzbKqsPXmqQ43kRSdiJu0veN9Z0MGnK58sJmgt+teCc7q3mRDqaXQCftsFkz8STgOutftkdMDzpmYriidBooOoIrJ0OaqYKf6n+CGYXM0R3MkTYgIa6W1bOCg3VOcIYYUtHD+5GwyfcUQQ/Uu25j5LwA8LbaJuDO6akIv4UQO4T8Xegw6KthNFWcIPxtQato79a25DV8oZrgQ3kPf2vhOKe1Nw6JxIqhMNIJdV2h4Npu5StyEGXxrDAYyBwAkz1s+5O1ymq3j7ddHd4CvZJ7MtnBej7FDrni7GuLFxn+/73gEH6gQ8FDZEMuR/RDugVMI9sU8X2k6TxqCxoTcMU61my7uXdjD6tw+kTcBexb9qsr5DL6r5tYVb6Vlzo3ROhU/nPeZKGtpkv5ykTBKO/lx65ykUuFWCOjFZAKEXW4f6KwOYGuVzkx2ZGpHDGgt1gqIfcQpV1h3mOFbd/j7qFr21z52CbrY8FB8Yzrr7upjbIBcm5pVptPiBaFXzs8lyehHiyv76z2sm6lMUTf+uVYRbrn0BhI8mAWzyXV6c085o+z7ImekKjVSngx/vtRs8PejYq8UdMDFmKEcqiEJHUroahbALn7c/mDX78n0egLUU2SthIN5e2f8M 99Vjnc21 KzhCKrvwk0jH9Wx1VhCyGKdgQ+Xh43t/UtB2z32Trq7lcp/LRngJkZnV2zeqKqXZ9NpDH1vNZNYWuURs6plSB+ICmgwcGOAFGj6fA5tgparhVLQPst7LPvocNkBb57lQmk7i1rmh7muvuwCqGsunyWDSq73Ln+1nErIHJiWnmKdD0gFdAu8YM5zWR8mLsU8rn4mJKSeK844MH6WB+cDpRhDR/rxISkY7s/pxEscb+YjaSPUVoq1VSj3cM+jOFIK2g5mLrKpd9r8tbG/e6vZBMulj4H7u7rsOEy76JWZRrzNwneH4xDoA/NiLi3uAuyeJDTSaNIG5s4biaEvVuGWE6AlnOfgNpoSudwWTutUNPGmKMrUO51ScZ+5dSb1xJUEtf/7BxqNnk4HARWBqm2jvbVbsOkQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The defines for clamp() have got separated, move togther for readability. Update description of signedness check. Signed-off-by: David Laight --- v2: - No change. include/linux/minmax.h | 120 +++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 64 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index a7ef65f78933..cea63a8ac80f 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -57,26 +57,6 @@ __cmp(op, x, y), \ __cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) -#define __clamp(val, lo, hi) \ - ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) - -#define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({ \ - typeof(val) unique_val = (val); \ - typeof(lo) unique_lo = (lo); \ - typeof(hi) unique_hi = (hi); \ - static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ - (lo) <= (hi), true), \ - "clamp() low limit " #lo " greater than high limit " #hi); \ - static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ - static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ - __clamp(unique_val, unique_lo, unique_hi); }) - -#define __careful_clamp(val, lo, hi) ({ \ - __builtin_choose_expr(__is_constexpr((val) - (lo) + (hi)), \ - __clamp(val, lo, hi), \ - __clamp_once(val, lo, hi, __UNIQUE_ID(__val), \ - __UNIQUE_ID(__lo), __UNIQUE_ID(__hi))); }) - /** * min - return minimum of two values of the same or compatible types * @x: first value @@ -124,6 +104,22 @@ */ #define max3(x, y, z) max((typeof(x))max(x, y), z) +/** + * min_t - return minimum of two values, using the specified type + * @type: data type to use + * @x: first value + * @y: second value + */ +#define min_t(type, x, y) __careful_cmp(min, (type)(x), (type)(y)) + +/** + * max_t - return maximum of two values, using the specified type + * @type: data type to use + * @x: first value + * @y: second value + */ +#define max_t(type, x, y) __careful_cmp(max, (type)(x), (type)(y)) + /** * min_not_zero - return the minimum that is _not_ zero, unless both are zero * @x: value1 @@ -134,39 +130,60 @@ typeof(y) __y = (y); \ __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) +#define __clamp(val, lo, hi) \ + ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) + +#define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({ \ + typeof(val) unique_val = (val); \ + typeof(lo) unique_lo = (lo); \ + typeof(hi) unique_hi = (hi); \ + static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ + (lo) <= (hi), true), \ + "clamp() low limit " #lo " greater than high limit " #hi); \ + static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ + static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ + __clamp(unique_val, unique_lo, unique_hi); }) + +#define __careful_clamp(val, lo, hi) ({ \ + __builtin_choose_expr(__is_constexpr((val) - (lo) + (hi)), \ + __clamp(val, lo, hi), \ + __clamp_once(val, lo, hi, __UNIQUE_ID(__val), \ + __UNIQUE_ID(__lo), __UNIQUE_ID(__hi))); }) + /** * clamp - return a value clamped to a given range with strict typechecking * @val: current value * @lo: lowest allowable value * @hi: highest allowable value * - * This macro does strict typechecking of @lo/@hi to make sure they are of the - * same type as @val. See the unnecessary pointer comparisons. + * This macro checks that @val, @lo and @hi have the same signedness. */ #define clamp(val, lo, hi) __careful_clamp(val, lo, hi) -/* - * ..and if you can't take the strict - * types, you can specify one yourself. - * - * Or not use min/max/clamp at all, of course. - */ - /** - * min_t - return minimum of two values, using the specified type - * @type: data type to use - * @x: first value - * @y: second value + * clamp_t - return a value clamped to a given range using a given type + * @type: the type of variable to use + * @val: current value + * @lo: minimum allowable value + * @hi: maximum allowable value + * + * This macro does no typechecking and uses temporary variables of type + * @type to make all the comparisons. */ -#define min_t(type, x, y) __careful_cmp(min, (type)(x), (type)(y)) +#define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi)) /** - * max_t - return maximum of two values, using the specified type - * @type: data type to use - * @x: first value - * @y: second value + * clamp_val - return a value clamped to a given range using val's type + * @val: current value + * @lo: minimum allowable value + * @hi: maximum allowable value + * + * This macro does no typechecking and uses temporary variables of whatever + * type the input argument @val is. This is useful when @val is an unsigned + * type and @lo and @hi are literals that will otherwise be assigned a signed + * integer type. */ -#define max_t(type, x, y) __careful_cmp(max, (type)(x), (type)(y)) +#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) /* * Do not check the array parameter using __must_be_array(). @@ -211,31 +228,6 @@ */ #define max_array(array, len) __minmax_array(max, array, len) -/** - * clamp_t - return a value clamped to a given range using a given type - * @type: the type of variable to use - * @val: current value - * @lo: minimum allowable value - * @hi: maximum allowable value - * - * This macro does no typechecking and uses temporary variables of type - * @type to make all the comparisons. - */ -#define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi)) - -/** - * clamp_val - return a value clamped to a given range using val's type - * @val: current value - * @lo: minimum allowable value - * @hi: maximum allowable value - * - * This macro does no typechecking and uses temporary variables of whatever - * type the input argument @val is. This is useful when @val is an unsigned - * type and @lo and @hi are literals that will otherwise be assigned a signed - * integer type. - */ -#define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) - static inline bool in_range64(u64 val, u64 start, u64 len) { return (val - start) < len; From patchwork Sun Jul 28 14:18:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13744003 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1B19C3DA49 for ; Sun, 28 Jul 2024 14:19:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 858436B007B; Sun, 28 Jul 2024 10:19:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 809126B0083; Sun, 28 Jul 2024 10:19:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D03E6B0085; Sun, 28 Jul 2024 10:19:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 52F6D6B007B for ; Sun, 28 Jul 2024 10:19:42 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C323516051E for ; Sun, 28 Jul 2024 14:19:41 +0000 (UTC) X-FDA: 82389369762.12.81F0CB3 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by imf11.hostedemail.com (Postfix) with ESMTP id 8D15B40007 for ; Sun, 28 Jul 2024 14:19:39 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722176327; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MuvoUgdtghS6rQkUL1LMIng5Fy8TT6pQDoAeXgc4g8Y=; b=8S+m3j/yyJ0T5IEvucs5yIe6xbL2+8S6DPVL7+vasP6XVt2LRCHJ7lQ1XQQWdFioBbYRBT HlCDilvIK8ZzOELc+nwSunZaJIzfbZIYfVPkjTvDG5wRnywXGURciOoxBlRvu6mXoKJcsW okb/yj0ul5Nyqc+dW7SfMxpYkeHsabQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722176327; a=rsa-sha256; cv=none; b=0tLRjLkeYQC1SAQ6BP6frbG5fa6p1IvFDSuvH3Qn7/WnZyTwgCSWVyPG/ZtjcHbhq2sS6U uDEootD+ke1QPueHBzAlMa0nVNZR883b8bQkGltND96cVVUWgd/W0oDVRtFmWebcet0lmG 1LefN0RtS2e2RaJDCBv2bsTwa/mjpDA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; spf=pass (imf11.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=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-44-u0K9Dgy5NXe-98MhLF4xEg-1; Sun, 28 Jul 2024 15:19:32 +0100 X-MC-Unique: u0K9Dgy5NXe-98MhLF4xEg-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, 28 Jul 2024 15:18:47 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jul 2024 15:18:47 +0100 From: David Laight To: "'linux-kernel@vger.kernel.org'" CC: 'Linus Torvalds' , 'Jens Axboe' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , 'Arnd Bergmann' , "'Jason@zx2c4.com'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , 'Lorenzo Stoakes' Subject: [PATCH v2 2/8] minmax: Use _Static_assert() instead of static_assert() Thread-Topic: [PATCH v2 2/8] minmax: Use _Static_assert() instead of static_assert() Thread-Index: Adrg+SQVeb05XypLRkeZ+5Y+23noEA== Date: Sun, 28 Jul 2024 14:18:47 +0000 Message-ID: References: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> In-Reply-To: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 8D15B40007 X-Stat-Signature: k9xgcn97kayc3yg5x6firpkxsnym6hkt X-HE-Tag: 1722176379-713799 X-HE-Meta: U2FsdGVkX18GH9p6+TJTOhHaBeTi1QX1c4zmwykGbaI6kb1qralCNtfsnqzID5ICUg5UfPNi+Z/MpIix7GyRAzLJ+06eOFaBHswp/1ywp96AuZsNV2dpDJlisKWWVzuaLRYdn5iHP1UE7lbzxA8fX2o0OIypb8WTcirvyejIiQA65icWIpabzYhc0uoIOfZ4qdDlZuFrnEmndQRPkhzaSY8bMp9DFWc22T/r5xvFciaDqGSc5kmHjQ0RrCg0MAhYAI6mWFKIOylyA3yumbDidZU+f4IIhDqIsqYkb1UthC7JryyIYScF0pb+Q/LuaXcNA5Go2afKiA3hNtGk0v+B7WjQePv0aRJ/biZ052Pyn7JK5CI6nFReUEsHa0KWbIJqdBk8LFKNBRBdddHPRUPPkCKdd9mb/BkyBSIPBw3ZpyqhZKPTxDp/pEYmmzVmsEM30XLAZ//rj85p4rbTtxT3W5c+hKvtXKxSuX6b3Jx26oHVk4+fo/Ydr+D4JRWkevT9dzhDvknN8sVw7wrQSVOvumSr60VJzyasOCmC86Vt2RlTXTb1aNCleWjzoALYTP9N7mkMC4jtmgmfzUYFFyX2XOwB35N7tNycssDMy9wmQoAEekqoiLyvY0YqQNf+6+K/zzs3PaSDY+iRh6/9Heqa7EH3xAgJxXITE6PjVXls14+giPGc+yzDXkAHP5WjtScMDnVP2whz2xPWrEGeCozoRKM1biFIvF5abmwxe4z6JW9kt2YXlzvpepJ6EGFcmU5zgJ13zJ9nMi94QH1eByMiSXqngrSiqo0Opd3+gGF3vpAlzorKZJyYHadaAB9u8SAJLUfT3ht6F+AxLyTfPxnjHS9Mq3d4nSyY1GQnvEY4JdMvl4uXu6I23XK4pQTNSZZfHCMcUwQTlDiAEYkzLLIiOB9ZMReAXXUJ87Vk3e2Tpf7YRk4Pki1p3Vi8xSOnqxrejtXRTgF+deR6N1n2oHG SNzh3yeN 0bjhWeo2s41BnLm4QX9+//JNtgr8S9/UUuPSdxwJ0p76ZRE6L+WtxqURue1rZGOh6H8pOptXjlnHtojlnA8/dWBprFkHy87yB/75Joh59hJCzzJTZihuFr8HG8BzL74w/p4ddahzvu1cfxNsnLL5M63isoLkKXG0llQxPmXQcAD+nHsFkWFGKigliVbdcjFLnxRVXaGacLfJJ/tmX7ha5c94L8Q3F4iryU+rjOrQtW/g4egmGuhxMo5Hw+osfR5ykQkoSJmyK6/q1JnxWAv9gI3Ul+MW6xFxlbkZDTkIY7Xhg0lsOSz+Ydzfxj1oQk3BcLza+Jv+MRH/6UG2i1pjYzufmSgKYNqV6k/guA0loWfmD5NrlNQisvU4eoeEkMhtaHlmAaC+NPpwk2p+mlSHKwvpvLM8n0vN6gaFpUfjUWofyXg3o9vB7cps3Ujf9IBeYoOmr X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The static_assert() wrapper provides the text of the expression as the error message, this isn't needed here as an explicit message is provided. If there is an error (quite likely for min/max) the wrapper also adds two more lines of error output that just make it harder to read. Since it gives no benefit and actually makes things worse directly using _Static_assert() is much better. Signed-off-by: David Laight --- v2: - No change. include/linux/minmax.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index cea63a8ac80f..ab64b2e73ae5 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -48,7 +48,7 @@ #define __cmp_once(op, x, y, unique_x, unique_y) ({ \ typeof(x) unique_x = (x); \ typeof(y) unique_y = (y); \ - static_assert(__types_ok(x, y), \ + _Static_assert(__types_ok(x, y), \ #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ __cmp(op, unique_x, unique_y); }) @@ -137,11 +137,11 @@ typeof(val) unique_val = (val); \ typeof(lo) unique_lo = (lo); \ typeof(hi) unique_hi = (hi); \ - static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ + _Static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ (lo) <= (hi), true), \ "clamp() low limit " #lo " greater than high limit " #hi); \ - static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ - static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ + _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ + _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ __clamp(unique_val, unique_lo, unique_hi); }) #define __careful_clamp(val, lo, hi) ({ \ From patchwork Sun Jul 28 14:19:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13744004 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 619B1C3DA64 for ; Sun, 28 Jul 2024 14:20:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE9656B007B; Sun, 28 Jul 2024 10:20:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E98E36B0083; Sun, 28 Jul 2024 10:20:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D60C26B0085; Sun, 28 Jul 2024 10:20:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BA3FB6B007B for ; Sun, 28 Jul 2024 10:20:44 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6EBEFA02F5 for ; Sun, 28 Jul 2024 14:20:44 +0000 (UTC) X-FDA: 82389372408.09.E68D8D6 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by imf25.hostedemail.com (Postfix) with ESMTP id 3118BA0019 for ; Sun, 28 Jul 2024 14:20:41 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722176415; a=rsa-sha256; cv=none; b=dFvNjwporjQ57msI1aIlHIT/O4oaRg2fjDAWTMP3MftpqhxELxmyWnoBDjs3j1eb34q6KY TSXA71G1lvDu4s0EiIqq0xDcwn0B1XR09WvXmpyeIydT1XtBmqBH5M6pAChfV0iqrrZz02 rtKISpYqQTyO/YyZUF5Qeg1toue8Fqw= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=none; spf=pass (imf25.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722176415; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i+qXpk5ITjdTzby+FlajwQpXJK3tpsKkVHmafvHvxRg=; b=Ymj3e6O47DPLTn4ZunS1JFThgQR37IgpRw/dqXc8t7vq/OqGMeN7082vbTtQPy8RPWHT+7 QAGXRDtjUgdXcvQuNnCyOj6+L2fOWEyteIx83xlmbJoJ0EzSavaUe8R8Ekje72w0GBvIrE jHU3Eh1ofwc9Mv4FuNHc1ulris/AY2w= 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-176-ASX4DscfNW6QCi1PP5Mc6g-1; Sun, 28 Jul 2024 15:20:36 +0100 X-MC-Unique: ASX4DscfNW6QCi1PP5Mc6g-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, 28 Jul 2024 15:19:52 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jul 2024 15:19:52 +0100 From: David Laight To: "'linux-kernel@vger.kernel.org'" CC: 'Linus Torvalds' , 'Jens Axboe' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , 'Arnd Bergmann' , "'Jason@zx2c4.com'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , 'Lorenzo Stoakes' Subject: [PATCH v2 3/8] compiler.h: Add __if_constexpr(expr, if_const, if_not_const) Thread-Topic: [PATCH v2 3/8] compiler.h: Add __if_constexpr(expr, if_const, if_not_const) Thread-Index: Adrg+UWL9B3xHw3xQ5CeKplMo1TYvg== Date: Sun, 28 Jul 2024 14:19:52 +0000 Message-ID: <2e12aefe29884e578283129411e1df26@AcuMS.aculab.com> References: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> In-Reply-To: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Stat-Signature: ixxon9dyu1ix6ugfrma3n1q6mzxqrujm X-Rspamd-Queue-Id: 3118BA0019 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1722176441-996756 X-HE-Meta: U2FsdGVkX184C48JqLnofDZplzLwM+EVLag+JxrfdN+lKQC0dFSX95UlSDCfiOiuvQ27m8WlWKgBqPwxSokzFmkeSPShOT7SQzMRuFXk5ea+IohYiIiRTbl1OdG/e8hy4rWBGUvyi/M1u+jfymp9BXedlrZtPohTKY0jugXnwfYAsSVny+MPYzR5lwjgR5inRg+la4gF60JFEljQnxgnIS6B4d5TBn4LqaKfzxOXmSrrbTCZTLTo2odreH4UbDcLZxF8bTd4GyTkK74WxOXq+n2N4Lk+R0RSTno7q0NyfDzYFyK5pu9CiW4EXn9+SsDU9NtTeFlV91bHwKf16JUk09VDhuQw4ATwC9U/j6GCgQFU+nFvgvSXiprJNf1w+dGrNZqNm0HccCYTF526fpKpNWGZ70OIZDXJr9B3500JLKrdHdwdqoMM2jLzCmn5EmEv9NmyiIE9PKap55RwXWOfBSBkpj3NJTPpF8zzZuDrY444QZ6Vb3vV3UypBrGyIWQUz6fbSkhtHyI8JQ5NGfLN3lBDWhnCPMFBzUVcV977f09j1skxvh7+sJVgIoRFGGPcxF28otf5oJe2+b6SVjyKqu/r5x1ma2ws5o0po9p2H4sCXEgBcUrS6AQ255ICSCx27Hm6nc8I3p5FXKUS1Cei5OICPZtku7HOPqD1/PsttMFsjYsvJxWht4FcX4223PAsOJJItpctJ97ACdfFaqK5qSP015vQQvDbkUo3GcDbvJOiO1bZRXpEHDrKXjIcxVl0ExITi1pkWeDwulQtjdX5nSdqK/eIrAR5ZNhhHjxOA9hg5zQ03ybVt8XRIsQUJL8cVEIVwUU484Krlui30UhFAhOxFJkQnmV2n//vMHyNHDUaoPfeQGyOhBgX6WJBCNeSJQWDExrLdQqKi0NVYwZXiLu4Zvn+i4NwDG1Y1MHipig2XezlGxWQHj5T4EjV/Q9yMw/ABmV0g0QZ0gcTUmz X9m2hX3I sCeNbxe5iCWfow9oR5Ybv5pWD68fNifI8Grchvqcz33XIhhnkMW/81vJATrAvJwynXdDUFQvFp5ZArKJF39ceF2Yf4zB0UpL55tmgMZtYojtAqlUEZU/GaKDGgXwzvfxyPv064ek6puncjnzsrk37RNDg8t3ZKGq3PPRo3W+CTL8u79N5J+IxuioSjTUUykWx5EV6LalfFcamcaB4de4JhpoLPPzyCFsf1Q6gxGtFGbl90skWmP8pOL9yWJMDR3uzOxCM+v0f96CLUYv/8UPoNZndS2mTYmdebTZ8aV9XP54c1yiPTbUcUrXpmQwk2Y/0cazX/78J2gi5ZmfL15EHthseQwn1wzMB/gfmYn3BaPzCZrvu8NJydsQ+XcKZP1NYxSNz8sztmQAk+hO/5YPJWnPuEwmaJnHyqHAUEwX7Z8+phuPLy9LDYsZdf17QCmaR68+M X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: __if_constexpr(expr, if_const, if_not_const) returns 'if_const' if 'expr' is a 'constant integer expression' otherwise 'if_not_const'. The two values may have different types. __is_constexpr(expr) is equivalent to __if_constexpr(expr, 1, 0). Signed-off-by: David Laight --- v2: - Don't change __is_constexpr() include/linux/compiler.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/compiler.h b/include/linux/compiler.h index 2594553bb30b..35d5b2fa4786 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h @@ -242,6 +242,23 @@ static inline void *offset_to_ptr(const int *off) /* &a[0] degrades to a pointer: a different type from an array */ #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0])) +/** + * __if_constexpr - Check whether an expression is an 'integer + * constant expression' + * @expr: Expression to test, not evaluated, can be a pointer + * @if_const: return value if constant + * @if_not_const: return value if not constant + * + * The return values @if_const and @if_not_const can have different types. + * + * Relies on typeof(x ? NULL : ptr_type) being ptr_type and + * typeof(x ? (void *)y : ptr_type) being 'void *'. + */ +#define __if_constexpr(expr, if_const, if_not_const) \ + _Generic(0 ? ((void *)((long)(expr) * 0l)) : (char *)0, \ + char *: (if_const), \ + void *: (if_not_const)) + /* * This returns a constant expression while determining if an argument is * a constant expression, most importantly without evaluating the argument. From patchwork Sun Jul 28 14:20:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13744005 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4A44C3DA64 for ; Sun, 28 Jul 2024 14:21:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3783F6B007B; Sun, 28 Jul 2024 10:21:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 328676B0083; Sun, 28 Jul 2024 10:21:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F0136B0085; Sun, 28 Jul 2024 10:21:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 03FF06B007B for ; Sun, 28 Jul 2024 10:21:32 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7BAF01202F5 for ; Sun, 28 Jul 2024 14:21:32 +0000 (UTC) X-FDA: 82389374424.07.89187D6 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by imf24.hostedemail.com (Postfix) with ESMTP id 24487180003 for ; Sun, 28 Jul 2024 14:21:29 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722176463; a=rsa-sha256; cv=none; b=NkG1hI4Ga7v9CNlPmS/mErRmpaCNVD6URaF3iR+QDURgDvTEBWan+2n6uJz75t7S7UBUTS Lu0JVNWDYlD0u3OjenmNP3iFxrnSHiEzSf3hFYP0Glcv47i+W/RpPx4FjlL7D7jAluGUWY WflTf93ojJE6fgsG03/lx54+CTjYDZU= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722176463; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1ScHcBhe6toW73FIdpd2QEq4DTHDTnTuCAdGm27/GBA=; b=6cM44dCNlN4fFtlmKVNu+Ud3dMiqUvCn/rjWejar7+cKXsoWsVGbm0Fa1x+GqD1Mp1TZdH 5SQghZcxmUPTwnoRQNv1BFgxhyKCJ7v4bF5nk0+G9LRDjbdNShHxIoSAIjQYOo6Zzayvdo lsL3eLH4bO6BAdP7aR+F87aDcjonB9A= 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-240-gyu3qikDN8SBJ-lv0Ijmhg-1; Sun, 28 Jul 2024 15:21:25 +0100 X-MC-Unique: gyu3qikDN8SBJ-lv0Ijmhg-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, 28 Jul 2024 15:20:41 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jul 2024 15:20:41 +0100 From: David Laight To: "'linux-kernel@vger.kernel.org'" CC: 'Linus Torvalds' , 'Jens Axboe' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , 'Arnd Bergmann' , "'Jason@zx2c4.com'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , 'Lorenzo Stoakes' Subject: [PATCH v2 4/8] minmax: Simplify signedness check Thread-Topic: [PATCH v2 4/8] minmax: Simplify signedness check Thread-Index: Adrg+WoBXlsaZZWKRzqVZpRDUvrsDQ== Date: Sun, 28 Jul 2024 14:20:41 +0000 Message-ID: <74e0b027a908461da879b69b0e12c0de@AcuMS.aculab.com> References: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> In-Reply-To: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Stat-Signature: ujarzgnjum9by36q9emiyrdoioxfwymp X-Rspamd-Queue-Id: 24487180003 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1722176489-159046 X-HE-Meta: U2FsdGVkX1/TfbmluhMq8KEdv2wuYfdudatbOff9Y8O9RRs4ArqA95ZvdKM0xOfHMJls9eNoxbiFu560NSmy7qXRPi2t8UOz8HsxolHnFEL6bWhqHjUwkthUhCqGcS1prcFGib+PmigFRhGgMar+G3sIL24GLeOF8iS0TxORlX90rbWMCqhwMSab1odpEbKhz686pKN/MfFqH/CnsqkMmBfWj4/50v6k5+yitDC78nXrvZj1l6Az6VlJ7QYTkjF2ZQWXtGWNZow0z9NKx1076EgZLpr0eai6FW6foux9Xxm/TO0virNbt9ZN3lyRE17oY0XzdZ7lmnYeCQoi3qyXYclrlqu3etNWIfNs2VW6mpSM/9Tw0/9sfPZlquvESSTeSKCCJ0Krz4uQvC2MQIE3Fkrr7E/tCaxWmu1ZU02TgQeVXBKn/cvoOV2ttuc7RvVxXmdZfACAEDpCpghw4lkyLzE9o+hy7I95Dj+1DJMj50z4LKRTghtqmwYqhfccyvDpWmanCKk+kMSJfg0DdxlmaStz/IknqtrgW8fc+DDCDMjZywOM9wc/IqVOf3NYBNnr3UXQvkg9yt9NhbEfIX5GoK31Z7tCjz6UHXMK4xC8isgcONcnyiA+bwh0Suzf5UGEx+weqjcuI2Xw375zoZbH9nTgZYOqk41f5ysWxKz9QulY279KKxsQVUqQ0vMBNN7ihaWjYbJQ6eQ+0INWjTmNc35xc5QRjTa1HY8BeLP/VfZT2vLFzCIyMAL/l+mjPlgnE5DzkmV01dyNUD8Vl9BFJ3fOk9itt9KEmBFnB4sJLxJXjQmUOSZr7dsfoThEOZ6kh+Pcm4O8/wmEBezyNiHWVxOpKtBey9w7WG4bIzxzCV0hCb3qxrVes8ZvCjCOQjKKMw0zBLCiJx5hnlqz+woEbLrzKsUrTawWdY74NVDgwTp6xEG3GvH1p+Wa6+4SF8Uimd6FEygiadPq8z+NIgB qhUBB2xi rbjMSfjiNTJiWltWFoOm1H0iPTtS26DXvhI3NGmALKdc1u7mqaF4lZOD6Hd4pnENUTYTNEBiBF0kUhP6HM9aSmvW5jacZBP+1j+uij8ueHueABf8CT28to6IJr5QK1L5Re3qhmgS6xv0nLqa5UF/WnW+ZsQEp3ADBDogRS6THOiA+ly1GmvB135l5yk6fNG8+IMsdlPXagLpT3+vzKOOo0ifXQRzbZQ6DULCIgBrMWj5lgbCr2oPcu5ONl1CXHC8MLbmlMxcTW9mnoYHhjYcS+nWc24A/v/Cw1xAcJB1cO2zz4hFD3yQGyx69jkX3YuWWPjHLQwX8/TF6kJjOovDpXM/tNDj82KdXLqH+JCTDeCwoauJPpTQE+jJ17nIC9jcuZvkB9HaxLbCS3OxUluYuQQtkKQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: It is enough to check that both 'x' and 'y' are valid for either a signed compare or an unsigned compare. For unsigned they must be an unsigned type or a positive constant. For signed they must be signed after unsigned char/short are promoted. Order the expressions to avoid warnings about comparisons that are always true. Signed-off-by: David Laight --- Changes for v2: - Wrap is_signed_type() to avoid issues with pointer types because (foo *)1 isn't a compile time constant. - Remove the '+ 0' from __is_ok_unsigned(). This converted 'bool' to 'int' to avoid a compiler warning and is no longer needed because of the implicit conversion dome by ?:. include/linux/minmax.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index ab64b2e73ae5..b9b5348a3879 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -8,7 +8,7 @@ #include /* - * min()/max()/clamp() macros must accomplish three things: + * min()/max()/clamp() macros must accomplish several things: * * - Avoid multiple evaluations of the arguments (so side-effects like * "x++" happen only once) when non-constant. @@ -26,19 +26,20 @@ #define __typecheck(x, y) \ (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1))) -/* is_signed_type() isn't a constexpr for pointer types */ -#define __is_signed(x) \ - __builtin_choose_expr(__is_constexpr(is_signed_type(typeof(x))), \ - is_signed_type(typeof(x)), 0) +#define __is_signed(x) \ + __if_constexpr((typeof(x))1, is_signed_type(typeof(x)), 0) -/* True for a non-negative signed int constant */ -#define __is_noneg_int(x) \ - (__builtin_choose_expr(__is_constexpr(x) && __is_signed(x), x, -1) >= 0) +/* Allow unsigned compares against non-negative signed constants. */ +#define __is_ok_unsigned(x) \ + ((!__is_signed((x)) ? 0 : __if_constexpr(x, x, -1)) >= 0) -#define __types_ok(x, y) \ - (__is_signed(x) == __is_signed(y) || \ - __is_signed((x) + 0) == __is_signed((y) + 0) || \ - __is_noneg_int(x) || __is_noneg_int(y)) +/* Check for signed after promoting unsigned char/short to int */ +#define __is_ok_signed(x) __is_signed((x) + 0) + +/* Allow if both x and y are valid for either signed or unsigned compares. */ +#define __types_ok(x, y) \ + ((__is_ok_signed(x) && __is_ok_signed(y)) || \ + (__is_ok_unsigned(x) && __is_ok_unsigned(y))) #define __cmp_op_min < #define __cmp_op_max > From patchwork Sun Jul 28 14:21:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13744006 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72D2EC3DA64 for ; Sun, 28 Jul 2024 14:22:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01D7D6B0083; Sun, 28 Jul 2024 10:22:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F101A6B0085; Sun, 28 Jul 2024 10:22:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFF1D6B0088; Sun, 28 Jul 2024 10:22:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C50796B0083 for ; Sun, 28 Jul 2024 10:22:24 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 749D2C0316 for ; Sun, 28 Jul 2024 14:22:24 +0000 (UTC) X-FDA: 82389376608.10.87D49C1 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf17.hostedemail.com (Postfix) with ESMTP id 295D040021 for ; Sun, 28 Jul 2024 14:22:21 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf17.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722176483; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7xWS8bC3ipEiV088zSFiCALDFShdXNdTChmKS9F3s+s=; b=Ee2XoPcSx2RCSzQiSI71gOo8BtwLNqskJ6hWRkSpRm7iOfkVYY1NWWSYbSyj1wfa3ghiGp pkoOdt1g3k4TtvRdvmS0QGwftFizfwCn/RWaTXkEcjMK3KcxkQgxAEvPFLeaZUdGDwy+Cu jt3SW3rk8FczPiNi5J0GGlyTTRyK0q4= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722176483; a=rsa-sha256; cv=none; b=ufAZCYT2ThwwKad4kjMVrL3a9ErZkhzG/0ScddBmy0ZZQDygzGRpP8yiynG/csmb4UpABJ SzpS/Uu++g3IknFiz0fW+Cc/87Ai6U1xsK6w6DqEr1GtT5B/ST0XqEqVrHUnAA7ueRNYbP dSuDMZMBkXBb7jZWPLwxUJB8qXjog1U= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf17.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@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-55-06CRokqUOX-KjYRbAhL1jw-1; Sun, 28 Jul 2024 15:22:11 +0100 X-MC-Unique: 06CRokqUOX-KjYRbAhL1jw-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, 28 Jul 2024 15:21:27 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jul 2024 15:21:27 +0100 From: David Laight To: "'linux-kernel@vger.kernel.org'" CC: 'Linus Torvalds' , 'Jens Axboe' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , 'Arnd Bergmann' , "'Jason@zx2c4.com'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , 'Lorenzo Stoakes' Subject: [PATCH v2 5/8] minmax: Factor out the zero-extension logic from umin/umax. Thread-Topic: [PATCH v2 5/8] minmax: Factor out the zero-extension logic from umin/umax. Thread-Index: Adrg+YXyDMjC+R5zRZ+wfV++JCCsqA== Date: Sun, 28 Jul 2024 14:21:27 +0000 Message-ID: <3e11fa68f33b4fb5beec1fc3f41b123e@AcuMS.aculab.com> References: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> In-Reply-To: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 295D040021 X-Stat-Signature: 5q8x3zyf5m84jenyd9qz7o7q56y7qmgn X-Rspam-User: X-HE-Tag: 1722176541-284140 X-HE-Meta: U2FsdGVkX180tpee7J97drBfAaTYvh0LlCB9zZlYTJomEcN+cVloVdb8MhYGY7Ci/N+QGdY0BcsXqPcjNIjvlOa2GsomWzC9o1WM6ZbctCwYXqbCeK1AqJNlYunXTrBYfkmindhRazLByZWSVtcl2ebH4/F2yvLPAUBiJVStfU+YKpxJq0y8ipjH8TqGNL2E9zi0GfKwaPwtd10E1qDVzW7c2uF91b6tFbw0N+ubIVjukC9HYlY2wnr3R6JqDiMADhl+tTK6MMbbH9WygSNxZ+3icbk2xwmuBBFVhQBdXueromddjjl9XY5iXADI00KAFzfea+evyCRvgAGiIP4whq5Pgb7tPA+5w77g4UwcplLhaxhiF1fAmQDCCWmWcksRLvHYV09XUO5g1fEw7y3oH2YTCRJntbGk+t7dU1ZKRqGN7pq+dNAe39+0N1LhQTK5Qpu5c8kVf0Vb1vquGj/TqKX6hriaoJSC5ej3xTkrSX/c+YSMwGS59BGwapVgk0PsInlmjm144VbftFcPcYm9UVmWLkdubIm1SyY5OoOOCLUm98ZYC26Dp5NNs5UCP/is/jNKl+4Es89d9ke3hpng6WOJTDfxXzDjdJz9jlNDLFBJh8aq+59nrf2G1dNmbOMMBdhjLSPH6aUE2SYlDQTIDF3gr+Fg8+9OZA/roj+2llkv8UqeETPpjO+T3QKgj329Kk8S8Tv8FKdRFZejlpIE9pIHCfWXnhYx7DxvZ0GQ36vRaxdxZ/GTCRXvDzwG9vsg/rdusKlI5WrwhY/Ib/Cm0WCTADWDdcju/Ky62f1G6+FuBFH915x3eR1kZMP5YXLPcF+RiUe6iXcZ+vPjVcg88oVAgfRrcBKMR63+LGUgSkgZOu6RsEkQovvSoj7icB0xI+t4WFMYsPgxYDeBDCHOxZ7czrbYcx3xN0Yw74xeuEIsxOBlbkF3D1K0byZYrYq0y/vfLZnC+0/vMyoetsx W1W17JHk nPD4vVrbBk43q5yOrgoaeUrJlJQ2xnHYUWxFWoUjmFc7nU2ggsNBHLAkwAtjkEAnzGVA5O5S3f/EKgb/sqYBMFJfy3NK7bG//rtN/RfOws1kwBc4VyOTTQgrUfDRUCS+QPyXIHsr2M53S4E1jf5KVcUIjMO/QbpD2O2CXnQmNM87wtEWps1fTyhXo/BEJiYdZ0HYbWbXMlvX5Vfdk+V+y38xGjL9CDuPxHryEROoZYMK1kyET+aqp+sT0vWvdDQm/67ZM9iwabxHksWzOHXyWzz+Yng2lBUf7aEfNUkWBbCwaLtkG0F8mFYTcseLlwuxuzjlvdQZz+hUKr/lviHqZksOsfIuszbcdWBtSz1DhvmBV/Uc6NYMYdOiFlVANtDQlk6K1Sx/Q6GPn2kqJtI7tTaDrcQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The '+ 0u + 0ul + 0ull' to zero extend to 64bit on both 32bit and 64bit systems was replicated 4 times. Factor out and then join up some 'not overlong' lines. Signed-off-by: David Laight --- v2 - no change include/linux/minmax.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index b9b5348a3879..a0c948ad576d 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -72,22 +72,26 @@ */ #define max(x, y) __careful_cmp(max, x, y) +/* + * Zero extend a non-negative value to 64bits. + * Undefined for negative values. + * The extension to 64 bits is often optimised away. + */ +#define __zero_extend(x) ((x) + 0u + 0ul + 0ull) + /** * umin - return minimum of two non-negative values - * Signed types are zero extended to match a larger unsigned type. * @x: first value * @y: second value */ -#define umin(x, y) \ - __careful_cmp(min, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull) +#define umin(x, y) __careful_cmp(min, __zero_extend(x), __zero_extend(y)) /** * umax - return maximum of two non-negative values * @x: first value * @y: second value */ -#define umax(x, y) \ - __careful_cmp(max, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull) +#define umax(x, y) __careful_cmp(max, __zero_extend(x), __zero_extend(y)) /** * min3 - return minimum of three values From patchwork Sun Jul 28 14:22:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13744007 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C57ACC3DA49 for ; Sun, 28 Jul 2024 14:23:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 611B36B0085; Sun, 28 Jul 2024 10:23:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5E8FB6B0088; Sun, 28 Jul 2024 10:23:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B0626B0089; Sun, 28 Jul 2024 10:23:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2EF006B0085 for ; Sun, 28 Jul 2024 10:23:10 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C783C40322 for ; Sun, 28 Jul 2024 14:23:09 +0000 (UTC) X-FDA: 82389378498.23.C6ACB02 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf18.hostedemail.com (Postfix) with ESMTP id 8A8741C0012 for ; Sun, 28 Jul 2024 14:23:07 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf18.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722176584; a=rsa-sha256; cv=none; b=wXtpuNTXhgqk/9BBuCRGUtLnmKi+rFUrI1cixDha3s1ikE1vVge5JzKeuhLeyYFtuxmPPr g6VQEQKwN3iiDwRzweLm1VpbEGS+OjgAcvE3QacxgifbNULzSsYu9WNpHyiKCz9bZMYloj 62ceh1v4Jl6paIK21QOw6G6Fudwh5Qw= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf18.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722176584; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0tAgnZnNa7Oxzz94ggec/aR6GTvZMg8hnsCjUYlG5YQ=; b=rUTUtEPp7pD6XBN49fnBM+RrdUgiJ7SjtQSjOCJyqDlzcg8xGMAbcCaIaXB0XvK/pdRHje SEuEJK2mDPXUfmIDDyCpl0w/J+DYK9XnM9TMQt0iplOLItbFfmAst6Ui7xX3CkVpAYCPCM QWJS5/5jBEhOki1v6BK+d2hDvCKO0qY= 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-69-SvVKtw3EPaGCg6lHdtAGIQ-1; Sun, 28 Jul 2024 15:23:03 +0100 X-MC-Unique: SvVKtw3EPaGCg6lHdtAGIQ-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, 28 Jul 2024 15:22:19 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jul 2024 15:22:19 +0100 From: David Laight To: "'linux-kernel@vger.kernel.org'" CC: 'Linus Torvalds' , 'Jens Axboe' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , 'Arnd Bergmann' , "'Jason@zx2c4.com'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , 'Lorenzo Stoakes' Subject: [PATCH v2 6/8] minmax: Optimise _Static_assert() check in clamp() Thread-Topic: [PATCH v2 6/8] minmax: Optimise _Static_assert() check in clamp() Thread-Index: Adrg+aI2g2sJGNTJQ4aVVAXDWlMAag== Date: Sun, 28 Jul 2024 14:22:19 +0000 Message-ID: References: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> In-Reply-To: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspam-User: X-Rspamd-Queue-Id: 8A8741C0012 X-Rspamd-Server: rspam01 X-Stat-Signature: dbek4y5a6bwjjefqkqy1k1ceamnazr4b X-HE-Tag: 1722176587-619526 X-HE-Meta: U2FsdGVkX18t75icrjtXduaNlG9TBVdH5uS6YUqClKPkAfHhoEVW0zw4XmsGnAskNbMaudnKJvwlbHP0/esgEA9tGO3t04yAd2ZgBjcLXZs5hseLjyjKzRY34fNf/J0n0MD2MoWdXDP7BbHnO1bOE5HTwyFT5kV69q9RkLEpIn+rsNJ6HdvsLtEJNmY4TwZYfZyJRzd552WXoz/uluHHPpqJwlUUMMIHjzzp57n56l8aZLSaw8uhdSBVFfq7pmXc+8E+iKnMjWSTVH84wy8mqFASf0gKMvyJx+UAu1Bi6pArr4TlHURVoov8dUnYNZZFqCzjLvt9SiCxUqxsZxngUPpC5tMYBFVd1vIAAwO0HWOokwDJclbKlsArhMgKkGP7YN0dttzRWHUuxtUPUO2rjGphElDTfPxYcadNgrAakTE4plJhpSgiuiXwjv8gLc6lhA/Nzy9AetohTzBl1TPTIfDELOW+apFvQzt2xExQsiDDQP3Cw1to4A6xL502uP3Q5BjGmGZlq3d8FWeui39TvR/7RNA8OGbetTgzSk1J0CIvKeKV2kiy4HGIaI4W+ATLLB9pUyds3r8/kIr/v2w2WMi8Qwd1zfrrAiB9kGfbBIE0gSigcx57BSMzpaJkuJxHnyrGiB5xn76bbpEWlufO6BL/vSckZogpIw/xmh8frQlP8U8m2/N80HC/38lA41pv6jv8nw+g7q0XSVgbt/8rFzv8NJFm11vkcgNriWXtnd0hTyeMpiOmfHzBJmrqF/X6egJJX4bfdhT+MtKr6VvdZe1lIOSUpClWEALB7N0kM5GoaB8JyM3HQLy3hHDA9T2pBJXm6vxrgkazJM3w/H/WxHPEWy1tlZvp5Q9qKArSHsWeDCJcWwFhxQdNo7yZR9DUg5YVqNBAgDMmNFbBH/PKbRtvK8axS0a31eCTIk+AwC3fG/OvLc1jSV6pa02vREI19uCVNEFyui8IIVhSvlR KOq7w75y BD8bcbBlHisFdMLRazQ/ef2dm5FGXoW4w+llyIzVE0TRGOE1eHFlTrB7Mg2nhgCd/cEcP0zg7iaYR82pYiRsUMqhR+feRS8puX21Obh9AtdICbi4Jlga+KsG+ezSqSh6h9NpOx1iNxYfnGy5D/C0Pqj2EDzshpPXT6u2a+UeryNU7PhVGxpWcWW3ck85+C25JqErmizzxPIqJJWgQqlIQyKNwubEV4im06wwFfRXz+yKJ3CAp4ZYFSoyKRo00ZGT3ja141zL710mvE18HSNBTc0nR3aCKrN3mAWyyo/DPKDUFSEXMzhhGWYYUoVw6CN+XFUwo/GmisxF25Nt+lZXz5Q54xalypLv+OVrf7fYMm5XTLPzRZRW/mFLD+XIYrJc9YaErz225iD++SsMxkv6LGN/ezDEGOexx36G/LtSoVurjzSip1/i9YNuPdmTbsAArn9bg X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Use __if_constexpr() instead of __builtin_choose_expr(__is_constexpr()). Signed-off-by: David Laight --- v2 - no change The misaligned \ is fixed in a later path. include/linux/minmax.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index a0c948ad576d..ad57c8eddc8a 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -142,8 +142,7 @@ typeof(val) unique_val = (val); \ typeof(lo) unique_lo = (lo); \ typeof(hi) unique_hi = (hi); \ - _Static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ - (lo) <= (hi), true), \ + _Static_assert(__if_constexpr((lo) <= (hi), (lo) <= (hi), true), \ "clamp() low limit " #lo " greater than high limit " #hi); \ _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ From patchwork Sun Jul 28 14:23:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13744008 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1E717C3DA49 for ; Sun, 28 Jul 2024 14:24:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA6D86B0085; Sun, 28 Jul 2024 10:24:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A57726B0088; Sun, 28 Jul 2024 10:24:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91E8D6B0089; Sun, 28 Jul 2024 10:24:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 764426B0085 for ; Sun, 28 Jul 2024 10:24:47 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 292EEA3244 for ; Sun, 28 Jul 2024 14:24:47 +0000 (UTC) X-FDA: 82389382614.17.A359D23 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf12.hostedemail.com (Postfix) with ESMTP id D0C4A40018 for ; Sun, 28 Jul 2024 14:24:44 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722176682; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eLNGDMHkgt4RmoWDWNbhDdjLfGJfa5I0/Di1Ur+Ex5s=; b=SeMiaCHSdFrlmazmbY7cEQn87e7iau3mdm37EUNAPkl30UyzEMYMbJ5UmEOZHFbKguLsm6 2JmYeGsQZQqVHItSpjA7lIgjeramWRnMvAH7SuvhwD7rgNZgrGOhGECbojfRgFkKdbOSVR IXJFS8NixHjs6h7+mUOrsO9P36+KlgM= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722176682; a=rsa-sha256; cv=none; b=Y8hYJWqoFLTARKZ1tubwil3RWyjmYj+vKOCYinN2eN9cYvQP69ZXpZQtG3LAlFTyt4Rc7s 4KuL0bW3RMTP7yjIXu7WNJPBzoWsdlUzQFjJz2CEqGlYqQqmq7SONIO62dis0JuPRoB1Z5 Nv+xv6UhQuJVCLZLAgVOCxLY0CdA/3A= 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-277-nlUHsBjeMUSsZCF2tSpzXw-1; Sun, 28 Jul 2024 15:24:37 +0100 X-MC-Unique: nlUHsBjeMUSsZCF2tSpzXw-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, 28 Jul 2024 15:23:52 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jul 2024 15:23:52 +0100 From: David Laight To: "'linux-kernel@vger.kernel.org'" CC: 'Linus Torvalds' , 'Jens Axboe' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , 'Arnd Bergmann' , "'Jason@zx2c4.com'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , 'Lorenzo Stoakes' Subject: [PATCH v2 7/8] minmax: Use __auto_type Thread-Topic: [PATCH v2 7/8] minmax: Use __auto_type Thread-Index: Adrg+b/Mt8JjzpFvR/SgdqY3jGnUug== Date: Sun, 28 Jul 2024 14:23:52 +0000 Message-ID: <431f7c45e7294d4da4f8abcd57ce7b5e@AcuMS.aculab.com> References: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> In-Reply-To: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspam-User: X-Stat-Signature: 43x8dzkreag714w8y54w6og3s6etx4a4 X-Rspamd-Queue-Id: D0C4A40018 X-Rspamd-Server: rspam11 X-HE-Tag: 1722176684-325652 X-HE-Meta: U2FsdGVkX19lHVhx06J2CfBUEoGWtLRUrWq3G4zhBeTBrWm0pTRs2jTHuGdGd7BtslFYmpobuZbhEXdMDpopB7xih1ASFkNitlzTqpmw5pmMR2on+tFYeTFu/4hqB+BAx3uX11HgDFQm7dX9EFXyiW3msCmoG1GxQGlc4VG5V9A8OPYRoEXRKSHrX1hvbafB2aaEPtPaEwb9LlT2x6MBejQ4KXzW6jFzAAeMc6eRm9WUDmXrMfIs3u3mWvSQENfbOgYQ6wurprA58OHOhQRShoGWMshc60/kmrXsvlAxC24nYix5AZK2mMKYjCFwCtdYK68rT+1bTRldPjsNgpW7kzVt7IOgC3J7IsjZw3lmCP3G4UWi3vzWs+sK2PJT7mKnYasFU1BXZGfgOKbQIpBpxsPKRr4UL/Edq+WvOOClzhKbsLCD5GEbLME9YwNpr3B+ES48Mkqd7RMeBBXRpZ8I4w2x6sCPLOahp/lQGm7AnQyyW+9rHHeZyJjvf2WFqH+6EsF58o1MHdLxIEqRybYPVoqDhC/RLbEF0CfmC9Vag6dKSEDWmHWP/sXlcbe1C1nJUHCSYCeH6nCmDXESNRkXPqnu82AFUpb6u0H7QkrwlTaoX774mrVHGQl+ArG76c35/O/5SgFlTDBRcTL8oT4y8rl9tfnSyVx68jVm3I1jLjxB3oZ9b2Y0Y9CH4Y69bEFMkWjguDb65q7ybpADEn5FFvGY9P4/nx3sIgw0UV+1YMC1CvHmC62S5Y0+pX/Bc2he2qmqyNjMugfutTP04jUfxK11GIaEpHnfPntzmglDnt656MDEiY0xMzIaI0Ywht4WEswP8M991fCqLDwohjT/VrL42XA/+X6odFbTTQrC3iIgYlfsIEhLWSvtMwu7ifB/mgDexcac2mQSqLPZ1FikxtRKk8H9+qhWrLnbcLZvN1nk7sIbXyQE9/S+4gLaz5LLnGEq5wWPqp5rypxzJOb vtVeskdN CXN0P/Ii0J7mDLvKMQDGwYN24HIPJjjEIxEq7n1S2LyDQpf0N++Xd0baDWPgCP5FMuoe2tkUrjQaRFcJCeKI3CwPuyzTK1rr9aOtkRm+lSzts6hu95VXRy14xxmQ4arMgKtQvbQd3ccOQZ5ADiWAUQYT/89KLOj2I8zhu3wONDaaRHqpmGpz+aiJVGgY7BklpJuEIE4LMB5Q2eMQgQd1oTwa55TeM3PR0QGyW4szXrytF6hYSCIrOLt0tmxs6S8oiN4WRJYwl1bGJ3prlhifu3wRMGj7EtRW7Xnfx/Vv/ufqkHz9EZ/aVBfb+oh8shNsd7jSagiFvJU+JTfl4hvOAKiqT4/Tg7qGWWOor2yTe0Sqk8XAvU9cL31IqRzfrdSAz6RVKUsIQkkS/p5yUS94rJJVQNScCh7aWkfDJZ0GT1grsRNPoKmgufDPXRKjCQMIZpVJH X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Replacing 'typeof(x) _x = (x)' with '__auto_type _x = (x)' removes one expansion of 'x'. Signed-off-by: David Laight --- New patch for v2 include/linux/minmax.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index ad57c8eddc8a..cb3515824a64 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -47,9 +47,9 @@ #define __cmp(op, x, y) ((x) __cmp_op_##op (y) ? (x) : (y)) #define __cmp_once(op, x, y, unique_x, unique_y) ({ \ - typeof(x) unique_x = (x); \ - typeof(y) unique_y = (y); \ - _Static_assert(__types_ok(x, y), \ + __auto_type unique_x = (x); \ + __auto_type unique_y = (y); \ + _Static_assert(__types_ok(x, y), \ #op "(" #x ", " #y ") signedness error, fix types or consider u" #op "() before " #op "_t()"); \ __cmp(op, unique_x, unique_y); }) @@ -131,18 +131,18 @@ * @y: value2 */ #define min_not_zero(x, y) ({ \ - typeof(x) __x = (x); \ - typeof(y) __y = (y); \ + __auto_type __x = (x); \ + __auto_type __y = (y); \ __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); }) #define __clamp(val, lo, hi) \ ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val))) #define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({ \ - typeof(val) unique_val = (val); \ - typeof(lo) unique_lo = (lo); \ - typeof(hi) unique_hi = (hi); \ - _Static_assert(__if_constexpr((lo) <= (hi), (lo) <= (hi), true), \ + __auto_type unique_val = (val); \ + __auto_type unique_lo = (lo); \ + __auto_type unique_hi = (hi); \ + _Static_assert(__if_constexpr((lo) <= (hi), (lo) <= (hi), true), \ "clamp() low limit " #lo " greater than high limit " #hi); \ _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ From patchwork Sun Jul 28 14:24:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13744009 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FBB4C3DA64 for ; Sun, 28 Jul 2024 14:25:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1585F6B0085; Sun, 28 Jul 2024 10:25:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 109726B0088; Sun, 28 Jul 2024 10:25:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F12C36B0089; Sun, 28 Jul 2024 10:25:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D55946B0085 for ; Sun, 28 Jul 2024 10:25:39 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5B53F12030A for ; Sun, 28 Jul 2024 14:25:39 +0000 (UTC) X-FDA: 82389384798.19.AAEF048 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf18.hostedemail.com (Postfix) with ESMTP id 0510B1C0027 for ; Sun, 28 Jul 2024 14:25:36 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722176685; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LvEureUuX7ccYh/zv402RgXxViJraceq25mQbkP5p1Q=; b=nNoN3c1mekz0B3vAonBimO9/Vro7Syidm6SkFFwZdyXcI6lz6bvJY2HO7TBguABBcYKSdu lgkjUUzLbga97fcRL8rh2lBLBZrx425gBpZ4eEDvfpYoxkqZPEOLKwwmlPL0RgOZdObcfY b8PnlyreXdn8hrFg8yZWrAWv9ksV2yM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722176685; a=rsa-sha256; cv=none; b=yPJHP/YWw04ank6yoWdnTbZ5sd8/xjbW1/9KJjyj71fFkjJUQTRekNUmJN0moG/5BrfRcv 05XuaZREWQ3WPNLBJxjcsXgQlUuhTO81IksBs2juJIxo6StAAb76EGPaIoK/vrVpLcvDYQ ruU5MMiR5J92zZylYPOpOnFTdMmOgRo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of david.laight@aculab.com designates 185.58.86.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=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-225-Ran_uoH8NAunlrVN1XlTGw-1; Sun, 28 Jul 2024 15:25:31 +0100 X-MC-Unique: Ran_uoH8NAunlrVN1XlTGw-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, 28 Jul 2024 15:24:46 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 28 Jul 2024 15:24:46 +0100 From: David Laight To: "'linux-kernel@vger.kernel.org'" CC: 'Linus Torvalds' , 'Jens Axboe' , "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , 'Andrew Morton' , 'Andy Shevchenko' , 'Dan Carpenter' , 'Arnd Bergmann' , "'Jason@zx2c4.com'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" , 'Lorenzo Stoakes' Subject: [PATCH v2 8/8] minmax: minmax: Add __types_ok3() and optimise defines with 3 arguments Thread-Topic: [PATCH v2 8/8] minmax: minmax: Add __types_ok3() and optimise defines with 3 arguments Thread-Index: Adrg+fzAGOYJcfIuRPCxFJC4Oy7+aw== Date: Sun, 28 Jul 2024 14:24:46 +0000 Message-ID: <75f18af7162c4414be28a890e9504c8d@AcuMS.aculab.com> References: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> In-Reply-To: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0510B1C0027 X-Stat-Signature: tcwr44x1kwee8mzhg3j5dho554kt7xww X-HE-Tag: 1722176736-471577 X-HE-Meta: U2FsdGVkX1/IGR/7sGPJMiJ/ThheUVKD3eCg8PFVRrLVXQyDNPKquiC3AS9B7tBQSF3nRuuR0KzPWErvU/eMxRx/r0zeWcSYzD9GdUY8dpfH7InjaEBDxzD1akinErWJBzvstNrBaO1B1A8XhziF9jm29d32gnqCSQdqBLZy8yMzoWqroBCdbc8aeHkVIVjdzXVbIR8td+BvE66z1eySQs4YmGX3AzEQPlScp1k+0PYKLuEn4h9MlVlALSr/XvOaLSH8lZJk1Hy257hP+lughXd74suKcGhfHJ2xzoshA1Z+sp/g9nlNH92qcadCdDFeGyR3NP8YUambbRxP0bLiIidLyo4aCw1CGt1WxBjT82ROWRgeItbBiEL5yeMyeQZImGVD09xrq42caQVk5BDwF8yJKmlBxIUxJ3PTyvYo3Cr9KbHfpJT/ve52LqAQSV5C4af9bhaGIE1mEvogJ8UwF6b+svufE+xAztzzZMCXksFAQTyp63Rglo7VKskFGAhaal1AAkyDycXljSjc3AnliY+FvxkTATVPnGkaDQ89/PiVQ6jCrX6KpKRh5E8zhL2/XR8r76BEo92CtgA/tjwIVHASVG2kMd9aulyNjy1XTJGOb2OVoW9yfmUba5rIiembCTQWwehHB3DanOdx2BfYXUBWQgbPQNB277TsideJjsVlotz75R52PvaSYfm0GvstTX5CW3AIwaxmpy0FwNWruP4qxHxKzdWoXyVWdE2GojLrTlBh12AIQ8mJAM1W4jPMqsgT/sjH4EMpmC0aZxlkpj9C5cC7MPlPXsxwjcHZYsxseYR7eTkOn7qSBweCxwB+Prq3CwLQUPGNy2MIzExrYn8eH3Jrtb6l5BG7hZ/gUgOYWtBHeTuMJHOuY12EmF3vtD1QnBWZ+WULXGAN7ea5LAEJwe/K3FVLFBjqIdUdVt1OWxNx0rl8z0RoGQZZW6z7FL8OOf2mWoHMQQ9rUaB Vq1FnNzx 3AifE/PqWaNGh1oDalL8r8ZJhoKNQ6ur/oG7TJmvj6uFrIGAHZybGhMfGMqggSDen9wCTXF0ihyse6FFSr2rClviwseeOcUlInLWY3cJ8g0VhEai8C9EoK+2nMNTmsFsNrcyYtBBn6fYLkDOWXVUuJaH1jm8wwttDrf8VXWGhgYYXxJmOkRnpn0OqdrnUUEiowZ6G5LmHoYdQwIbiS9eSUqfQqz2J8HJ4/GklOcUnJ19DotWuM5LKsmlpN26J8JcavQvK4nc6gJN+ggpvu1oGE53Ry0VhPZjt3pjdIFCosgsq6nHGeGBrnkEHWpBHZXKvt/OAgXfKaeOtYrVAgdiK9IN4MFAVFyn5yE9SNtp2ApdXc3RktRVAje+8ckdxJU4ShG4IfirdjfaIfx49xnloC6i73+C4KoJMEBEJMRyUy7E/oXAftcUWwBF7QUhirGJDdA6V X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: min3() and max3() were added to optimise nested min(x, min(y, z)) sequences, but only moved where the expansion was requested. Add a separate implementation for 3 argument calls. These are never required to generate constant expressiions so remove that logic. Signed-off-by: David Laight --- v2 (was pacth 7/7): - Use __auto_type. - Use an extra __xy local to slightly reduce the expansion. - Fix typos in the commit message. include/linux/minmax.h | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index cb3515824a64..e1e31a827547 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -41,6 +41,11 @@ ((__is_ok_signed(x) && __is_ok_signed(y)) || \ (__is_ok_unsigned(x) && __is_ok_unsigned(y))) +/* Check three values for min3(), max3() and clamp() */ +#define __types_ok3(x, y, z) \ + ((__is_ok_signed(x) && __is_ok_signed(y) && __is_ok_signed(z)) || \ + (__is_ok_unsigned(x) && __is_ok_unsigned(y) && __is_ok_unsigned(z))) + #define __cmp_op_min < #define __cmp_op_max > @@ -93,13 +98,25 @@ */ #define umax(x, y) __careful_cmp(max, __zero_extend(x), __zero_extend(y)) +#define __cmp_once3(op, x, y, z, uniq) ({ \ + __auto_type __x_##uniq = (x); \ + __auto_type __y_##uniq = (y); \ + __auto_type __z_##uniq = (z); \ + __auto_type __xy_##uniq = __cmp(op, __x_##uniq, __y_##uniq); \ + __cmp(op, __xy_##uniq, __z_##uniq); }) + +#define __careful_cmp3(op, x, y, z, uniq) ({ \ + _Static_assert(__types_ok3(x, y, z), \ + #op "3(" #x ", " #y ", " #z ") signedness error"); \ + __cmp_once3(op, x, y, z, uniq); }) + /** * min3 - return minimum of three values * @x: first value * @y: second value * @z: third value */ -#define min3(x, y, z) min((typeof(x))min(x, y), z) +#define min3(x, y, z) __careful_cmp3(min, x, y, z, __COUNTER__) /** * max3 - return maximum of three values @@ -107,7 +124,7 @@ * @y: second value * @z: third value */ -#define max3(x, y, z) max((typeof(x))max(x, y), z) +#define max3(x, y, z) __careful_cmp3(max, x, y, z, __COUNTER__) /** * min_t - return minimum of two values, using the specified type @@ -144,8 +161,7 @@ __auto_type unique_hi = (hi); \ _Static_assert(__if_constexpr((lo) <= (hi), (lo) <= (hi), true), \ "clamp() low limit " #lo " greater than high limit " #hi); \ - _Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error"); \ - _Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error"); \ + _Static_assert(__types_ok3(val, lo, hi), "clamp() signedness error"); \ __clamp(unique_val, unique_lo, unique_hi); }) #define __careful_clamp(val, lo, hi) ({ \