Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp896632rbb; Sun, 25 Feb 2024 08:51:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXnbewg/bU6UxHYCOxh2avof9IzfLtbU96KfOqFe9opMecC3+8gloI8KOAYltvKbLp9GvFEiHe0+6DSUPtzibiAygB9IBYPIJcF0Y398Q== X-Google-Smtp-Source: AGHT+IHqSCHyLiQPv6ARKopXmXceR5Y0IrClCee/CKzxwGATeL8P76Xr81GMzb1TLhf9ZIVPczJG X-Received: by 2002:a17:90a:8c0b:b0:29a:be15:9c90 with SMTP id a11-20020a17090a8c0b00b0029abe159c90mr452457pjo.34.1708879871262; Sun, 25 Feb 2024 08:51:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708879871; cv=pass; d=google.com; s=arc-20160816; b=VSqAFnUs2kEAeXwHkRpsnb4/o7SZ47/6m0ZHoyNPpjxrWPr/0KBhQiIKNE1VaOM1yD 9wKK66sDp9fcDr08YNoO3Lf2F3WfwBcv7G4SlMNdkwtj+/FoQrXCPZrDP0LfyQHLlTu7 gmQIKbbzyN8d4cYw/VeH65pzts+lRjlJG9+YPmkYBsq2x9P8F3bK5UgmXFz3D5Zb/MFD K1F8Br84VFVC+GjaF+ZnvofVF1Qg3JqBcGhRe9m/0ox5ERKUAn77RERETVuEGDNXpiwi SGCzgQnM9ceHA6dSoVz2VIU/i0xBfOYCZywboDX+zTjy3hT/sSiN5TWdoFKQrQ/dDXpL V0iQ== 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 :in-reply-to:references:message-id:date:thread-index:thread-topic :subject:cc:to:from; bh=+lOMyrz3Pc3RSh+srEYELe1hGEgmgpaasYGAX0sPieA=; fh=nGE692sbVdRvha6RYbzMUXtm1nr/30sV7frdtDN2z14=; b=lfBUx6rEZdNDfSkAstq+X47BI5NZPMNvL/xm6jTyw/nlCmW3IFmoUzhkYO6fpouG5U WGnudO2qMRjEW+UeuKULAcb/D6/H7z1UaM7M3wV3y9J6YENprS0U7sOkjwYOOtZKogA9 ZG9Z6ujtgdJI/BLNQzKPY7c+6ZlLZML4fCuwryLLbOks1BhMadEAZVqwxiAah+zxfG84 XxC1SmUMz5sqCrCdHLsmKJp2XoLFneF+k3DuvOyBRtkBEFmIVUeKoQBIENY5RtjajsRG ZroO8Jb5thSpfQjBEzk5aQCkLzBZWT91gD8kP+9mwFHO9dGq+FPPG0gwYzQxDc3i4pcw R7/g==; 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-80212-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80212-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id u4-20020a17090ac88400b0029a7c9a1bd7si2428742pjt.43.2024.02.25.08.51.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 25 Feb 2024 08:51:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-80212-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; arc=pass (i=1 spf=pass spfdomain=aculab.com dmarc=pass fromdomain=aculab.com); spf=pass (google.com: domain of linux-kernel+bounces-80212-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-80212-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 78F10281AAC for ; Sun, 25 Feb 2024 16:51:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65CE518651; Sun, 25 Feb 2024 16:50:55 +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 EF54379D3 for ; Sun, 25 Feb 2024 16:50:51 +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=1708879854; cv=none; b=bn2Pc5xRj/vaCKT9ttr8qkXVmoESE843s+5PfEKBWNnBYO6wiKrkJlrwGvv5Kjnl/XEjS3jWxqQmZfydym8oe70sPO1CTNayvoqAjaAfVgcAg6iuogGTbP7hIE5kAbafTFXJKiBzgnVBNHFem4rgcipjIxU7ivhuoem+8fV7Z68= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708879854; c=relaxed/simple; bh=+atgDbr45v2v/fK8FAQruXtzObgP16hiBnUi3W5GHsA=; h=From:To:CC:Subject:Date:Message-ID:References:In-Reply-To: MIME-Version:Content-Type; b=I8OqGg3kEWdl0LWSiWRL86+DH6uBOAaLMgJSj1ipEbC0068e9dvOUYb9n3vvdnFxJHYJP6zu1SrL+cgkMBRkt32iFLNtC4CtZVUdCNDqsFCdki+VUYNBj85uTenjEb2GOBzbNn5PIviU6TLhCk26GrHgaf/ZJFiGap/ho9TN3YI= 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-262-6W1dHPmgNxKn61PI8Ye6Yg-1; Sun, 25 Feb 2024 16:50:48 +0000 X-MC-Unique: 6W1dHPmgNxKn61PI8Ye6Yg-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:50:47 +0000 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 25 Feb 2024 16:50:47 +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 04/11] minmax: Replace multiple __UNIQUE_ID() by directly using __COUNTER__ Thread-Topic: [PATCH next v2 04/11] minmax: Replace multiple __UNIQUE_ID() by directly using __COUNTER__ Thread-Index: AdpoCsQOvIgG9TyzTYmUjuthkRVCRw== Date: Sun, 25 Feb 2024 16:50:47 +0000 Message-ID: References: <0fff52305e584036a777f440b5f474da@AcuMS.aculab.com> In-Reply-To: <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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Provided __COUNTER__ is passed through an extra #define it can be pasted onto multiple local variables to give unique names. This saves having 3 __UNIQUE_ID() for #defines with three locals and look less messy in general. Stop the umin()/umax() lines being overlong by factoring out the zero-extension logic. Signed-off-by: David Laight --- include/linux/minmax.h | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-) Changes for v2: - Typographical and spelling corrections to the commit messages. Patches unchanged. diff --git a/include/linux/minmax.h b/include/linux/minmax.h index c32b4b40ce01..8ee003d8abaf 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -8,7 +8,7 @@ #include =20 /* - * min()/max()/clamp() macros must accomplish several things: + * min()/max()/clamp() macros must accomplish three things: * * - Avoid multiple evaluations of the arguments (so side-effects like * "x++" happen only once) when non-constant. @@ -43,31 +43,31 @@ =20 #define __cmp(op, x, y)=09((x) __cmp_op_##op (y) ? (x) : (y)) =20 -#define __cmp_once(op, x, y, unique_x, unique_y) ({=09\ -=09typeof(x) unique_x =3D (x);=09=09=09\ -=09typeof(y) unique_y =3D (y);=09=09=09\ -=09_Static_assert(__types_ok(x, y),=09=09=09\ +#define __cmp_once(op, x, y, uniq) ({=09=09\ +=09typeof(x) __x_##uniq =3D (x);=09=09\ +=09typeof(y) __y_##uniq =3D (y);=09=09\ +=09_Static_assert(__types_ok(x, y),=09\ =09=09#op "(" #x ", " #y ") signedness error, fix types or consider u" #op= "() before " #op "_t()"); \ -=09__cmp(op, unique_x, unique_y); }) +=09__cmp(op, __x_##uniq, __y_##uniq); }) =20 -#define __careful_cmp(op, x, y)=09=09=09=09=09\ +#define __careful_cmp(op, x, y, uniq)=09=09=09=09\ =09__builtin_choose_expr(__is_constexpr((x) - (y)),=09\ =09=09__cmp(op, x, y),=09=09=09=09\ -=09=09__cmp_once(op, x, y, __UNIQUE_ID(__x), __UNIQUE_ID(__y))) +=09=09__cmp_once(op, x, y, uniq)) =20 /** * min - return minimum of two values of the same or compatible types * @x: first value * @y: second value */ -#define min(x, y)=09__careful_cmp(min, x, y) +#define min(x, y)=09__careful_cmp(min, x, y, __COUNTER__) =20 /** * max - return maximum of two values of the same or compatible types * @x: first value * @y: second value */ -#define max(x, y)=09__careful_cmp(max, x, y) +#define max(x, y)=09__careful_cmp(max, x, y, __COUNTER__) =20 /** * umin - return minimum of two non-negative values @@ -75,8 +75,9 @@ * @x: first value * @y: second value */ +#define __zero_extend(x) ((x) + 0u + 0ul + 0ull) #define umin(x, y)=09\ -=09__careful_cmp(min, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull) +=09__careful_cmp(min, __zero_extend(x), _zero_extend(y), __COUNTER__) =20 /** * umax - return maximum of two non-negative values @@ -84,7 +85,7 @@ * @y: second value */ #define umax(x, y)=09\ -=09__careful_cmp(max, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull) +=09__careful_cmp(max, __zero_extend(x), _zero_extend(y), __COUNTER__) =20 /** * min3 - return minimum of three values @@ -108,7 +109,7 @@ * @x: first value * @y: second value */ -#define min_t(type, x, y)=09__careful_cmp(min, (type)(x), (type)(y)) +#define min_t(type, x, y)=09__careful_cmp(min, (type)(x), (type)(y), __COU= NTER__) =20 /** * max_t - return maximum of two values, using the specified type @@ -116,7 +117,7 @@ * @x: first value * @y: second value */ -#define max_t(type, x, y)=09__careful_cmp(max, (type)(x), (type)(y)) +#define max_t(type, x, y)=09__careful_cmp(max, (type)(x), (type)(y), __COU= NTER__) =20 /** * min_not_zero - return the minimum that is _not_ zero, unless both are z= ero @@ -131,22 +132,21 @@ #define __clamp(val, lo, hi)=09\ =09((val) >=3D (hi) ? (hi) : ((val) <=3D (lo) ? (lo) : (val))) =20 -#define __clamp_once(val, lo, hi, unique_val, unique_lo, unique_hi) ({=09= =09\ -=09typeof(val) unique_val =3D (val);=09=09=09=09=09=09\ -=09typeof(lo) unique_lo =3D (lo);=09=09=09=09=09=09\ -=09typeof(hi) unique_hi =3D (hi);=09=09=09=09=09=09\ +#define __clamp_once(val, lo, hi, uniq) ({=09=09=09=09=09\ +=09typeof(val) __val_##uniq =3D (val);=09=09=09=09=09\ +=09typeof(lo) __lo_##uniq =3D (lo);=09=09=09=09=09=09\ +=09typeof(hi) __hi_##uniq =3D (hi);=09=09=09=09=09=09\ =09_Static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)),=09\ =09=09=09(lo) <=3D (hi), true),=09=09=09=09=09\ =09=09"clamp() low limit " #lo " greater than high limit " #hi);=09\ =09_Static_assert(__types_ok(val, lo), "clamp() 'lo' signedness error");= =09\ =09_Static_assert(__types_ok(val, hi), "clamp() 'hi' signedness error");= =09\ -=09__clamp(unique_val, unique_lo, unique_hi); }) +=09__clamp(__val_##uniq, __lo_##uniq, __hi_##uniq); }) =20 -#define __careful_clamp(val, lo, hi) ({=09=09=09=09=09\ +#define __careful_clamp(val, lo, hi, uniq) ({=09=09=09=09\ =09__builtin_choose_expr(__is_constexpr((val) - (lo) + (hi)),=09\ =09=09__clamp(val, lo, hi),=09=09=09=09=09\ -=09=09__clamp_once(val, lo, hi, __UNIQUE_ID(__val),=09=09\ -=09=09=09 __UNIQUE_ID(__lo), __UNIQUE_ID(__hi))); }) +=09=09__clamp_once(val, lo, hi, uniq)); }) =20 /** * clamp - return a value clamped to a given range with strict typecheckin= g @@ -156,7 +156,7 @@ * * This macro checks that @val, @lo and @hi have the same signedness. */ -#define clamp(val, lo, hi) __careful_clamp(val, lo, hi) +#define clamp(val, lo, hi) __careful_clamp(val, lo, hi, __COUNTER__) =20 /** * clamp_t - return a value clamped to a given range using a given type @@ -168,7 +168,7 @@ * 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)) +#define clamp_t(type, val, lo, hi) clamp((type)(val), (type)(lo), (type)(h= i)) =20 /** * clamp_val - return a value clamped to a given range using val's type --=20 2.17.1 - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)