From patchwork Wed Jul 24 14:31:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 13741016 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 1EF26C3DA63 for ; Wed, 24 Jul 2024 14:32:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A95236B007B; Wed, 24 Jul 2024 10:32:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A44D76B008C; Wed, 24 Jul 2024 10:32:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 90CFD6B0092; Wed, 24 Jul 2024 10:32:31 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 71BDA6B007B for ; Wed, 24 Jul 2024 10:32:31 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1EC1D120A5A for ; Wed, 24 Jul 2024 14:32:31 +0000 (UTC) X-FDA: 82374886902.19.DF1E324 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by imf04.hostedemail.com (Postfix) with ESMTP id AD63A40026 for ; Wed, 24 Jul 2024 14:32:28 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.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=1721831485; 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=jOCelJGLnUetgcH5pzDT6pVXE8U8ugE/QL3ccQvCF2c=; b=RtL6gqOjs0KvCKyat24CNpSazumz+tovwqr0Du0yY32L8FxGCQ0v/FjQOERA2Fs4cpdBZF A6eLyWIFBXE5i7PiBblkYa2TU8ihr33NTv9ggwkudDsO+/rqqlmQvBNWbuVFflkE1WPOPv dnKTgGsgMLg9Cj9l71NhxboA96w7sM8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.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=1721831485; a=rsa-sha256; cv=none; b=Ii35qi/i32uMMXN9/7MtzeoFGCKlvJAvlVWWJc/Mg6DqfBV7EcLYcwCQDZFvTwSRcX1hcR sIgg4q5Umm4/JEh1vEnMabH/Gi2lsZZXS7A5x9k//aWeLIHQWpqpAPguR+QKphOxtWn3fR n0MUUpc/7APZ+W2iKBCe/b4B0Oq2fxE= 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-201-p-9t2K8xPV2o1h-xKKZUHA-1; Wed, 24 Jul 2024 15:32:25 +0100 X-MC-Unique: p-9t2K8xPV2o1h-xKKZUHA-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 24 Jul 2024 15:31:45 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Wed, 24 Jul 2024 15:31:45 +0100 From: David Laight To: "'linux-kernel@vger.kernel.org'" , "'Linus Torvalds'" CC: "'Matthew Wilcox (Oracle)'" , 'Christoph Hellwig' , 'Andrew Morton' , "'Andy Shevchenko'" , 'Dan Carpenter' , 'Arnd Bergmann' , "'Jason@zx2c4.com'" , "'hch@infradead.org'" , "'pedro.falcato@gmail.com'" , 'Mateusz Guzik' , "'linux-mm@kvack.org'" Subject: [PATCH 5/7] minmax: Factor out the zero-extension logic from umin/umax Thread-Topic: [PATCH 5/7] minmax: Factor out the zero-extension logic from umin/umax Thread-Index: Adrd1kXn5nCrisyjTAW42k9g3Yw8yA== Date: Wed, 24 Jul 2024 14:31:45 +0000 Message-ID: References: <23bdb6fc8d884ceebeb6e8b8653b8cfe@AcuMS.aculab.com> In-Reply-To: <23bdb6fc8d884ceebeb6e8b8653b8cfe@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: rspam06 X-Rspamd-Queue-Id: AD63A40026 X-Stat-Signature: 6watda3bfu8twitgob1qoxau3o4pk19z X-Rspam-User: X-HE-Tag: 1721831548-871878 X-HE-Meta: U2FsdGVkX19Po5LnsRDfg2Tu+W0ZCRv5pck+SeL+lWpapHXnCp+oWwC9AlnRR9Z8sYx8oG8U4FwnioeBaMW7tZ8HEeGlOU8XrOBjD185wXNk6b8/RwTbKF2XTPjHE7Xj16L5U5aq5xrPlfn06S92yD9l/JX5Se+fZ02jHMGh2h2t6hyFA4kC3BJz27L/TmFKeg8nAjg1qPdEEfeFnsMq6OW+bI0QCurHX2J2SEMveBmzTCBO8LkEXHGainAe9pxuQwQxxsqPVrk9f7/FXDDtt470AtQNhcRXVmobxtorMqS3t1wfnQw3yPTMaBh58p4mPyQ9iWRbyVekh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, 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 --- include/linux/minmax.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/linux/minmax.h b/include/linux/minmax.h index d3ac65c1add7..e250957036a1 100644 --- a/include/linux/minmax.h +++ b/include/linux/minmax.h @@ -28,7 +28,7 @@ /* Allow unsigned compares against non-negative signed constants. */ #define __is_ok_unsigned(x) \ - ((is_unsigned_type(typeof(x)) ? 0 : __if_constexpr(x, (x) + 0, -1)) >= 0) + ((is_unsigned_type(typeof(x)) ? 0 : __if_constexpr(x, x, -1)) >= 0) /* Check for signed after promoting unsigned char/short to int */ #define __is_ok_signed(x) is_signed_type(typeof((x) + 0)) @@ -69,22 +69,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