From mboxrd@z Thu Jan 1 00:00:00 1970 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 2C1E4C3DA49 for ; Sun, 28 Jul 2024 17:24:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9335F6B007B; Sun, 28 Jul 2024 13:24:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E3B56B0083; Sun, 28 Jul 2024 13:24:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AAF26B0085; Sun, 28 Jul 2024 13:24:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5CE0F6B007B for ; Sun, 28 Jul 2024 13:24:53 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 0F056C0122 for ; Sun, 28 Jul 2024 17:24:53 +0000 (UTC) X-FDA: 82389836466.10.71A4CD0 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by imf14.hostedemail.com (Postfix) with ESMTP id C3A70100005 for ; Sun, 28 Jul 2024 17:24:50 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=google header.b=LLeU+yF6; spf=pass (imf14.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.43 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722187438; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mS2JdCkxSJZ3nViI33PhWYUnhFwBsNJc93+IrM3FGV4=; b=URVM1J1TILm/rQbqVmrtMhnBrHCG4gRyqZeIL1rAI1IGLkGk8WlLOcx4naAXSy1L7vv95j AYcyWml9TBVYHW73AObSY0xvGOH1eiXLw0dqN0wAOaC5L0uyx7KtQNF3PY65epjM4cQdo9 +wCPvXD/v3LUZTVEFfiNCvjgElJJsKs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722187438; a=rsa-sha256; cv=none; b=6GW1AGnzuLPrQ3foqPwZIqM3vOUeah+lMFzc1IF+r0uuEY4rSPeA1ffGGgTHO7UpvbP7IN fyChx5rBSsp6Pu8d0isXeyF2oD0rz7G4EQKnMkbtWJUDgcoMnrQyxIetpQo8aorsatwyyB xr3ipqYhjqYPraph5ErDs/K98ogT+To= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linuxfoundation.org header.s=google header.b=LLeU+yF6; spf=pass (imf14.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.43 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=pass (policy=none) header.from=linuxfoundation.org Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5a167b9df7eso4786295a12.3 for ; Sun, 28 Jul 2024 10:24:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1722187489; x=1722792289; darn=kvack.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=mS2JdCkxSJZ3nViI33PhWYUnhFwBsNJc93+IrM3FGV4=; b=LLeU+yF6GSzlF4F2fk0JPpPy+jWn9p76qpK0x+kPIRDbI5nekCC03DjLopt+KOExcm xbw+x/rdVqzs+g1jh2g6yPLiCBmCLaDJvcPgjxzG5PHtgPug/i4GXLyAuBTG0GGw7jrB bRghg8bVqMdRgiGyypz+HzhLUlikCCFLSxktY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722187489; x=1722792289; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=mS2JdCkxSJZ3nViI33PhWYUnhFwBsNJc93+IrM3FGV4=; b=lnAWv+2OPVmQQYTKZfUobrhgwKp90KLjvWBpEFIEVbwCZVr9BnRiXN/zirzWZXCCrT eOZb6EttKaXE/wVWv7g/ONENs35t4FqzK+78vrA260xgJSwHyfONxLna4RwvgdDgRpE6 RVLmNbExFy8EOFyq+vNgE2gnzBVxiQavjSzgXv7ysLDg1PJyVU/2qbuNjqAcEyFHayBw jJVAXg40/V1zvhmIKpZBz+rIbOL8+iIkPRBrP5mas3o8sr2U1Ey3WpnahtZNOXXfk9CS DxfVVq/ZREjlB8WQWUHX6/GXA2qBSqsEFGN+JKiie2sYF+iwF/o7lkOo6jLF7ySIwx/1 rtQg== X-Forwarded-Encrypted: i=1; AJvYcCUWwcYjDGqimtlEIzUQ4WK4bO2M6c7AWn++XKvN+RdCd94/id9IMSZYJToxy3RPtPu5Gwj29IF9yzPXzGDUtnZJG+g= X-Gm-Message-State: AOJu0YyO9PaRRLyz8qlud8FLzJi25Ac3Z7Vqh9OLdgZAX/WMCu/+xEPd B59Ioszmmq/NspizR2VnvP4la5PAoZAka/5y1bBhb5AFdiB978HVK28Ui0vO6nKT7OIuwYNirt1 dlHx4jw== X-Google-Smtp-Source: AGHT+IGXOx9mS25WZk4ZV4Ehr1EckS+FIMuC0Hv2e/y9yiaIbnya3BqPTuU++yFCNURqO3r6MRsJ2Q== X-Received: by 2002:a50:d4d5:0:b0:5af:874d:1b7b with SMTP id 4fb4d7f45d1cf-5b02000c604mr3332150a12.1.1722187488846; Sun, 28 Jul 2024 10:24:48 -0700 (PDT) Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com. [209.85.208.48]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5ac64eb3a27sm4581879a12.63.2024.07.28.10.24.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 28 Jul 2024 10:24:47 -0700 (PDT) Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5a1c49632deso4282606a12.2 for ; Sun, 28 Jul 2024 10:24:47 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVZHDn0EpbckrPhaY48+ACNigTmenbGi27yUfxHBWTW8FAmIjsrdDYpfrKGJokU/RH2b6J1fg8Y9qxndXoDTvKMB/w= X-Received: by 2002:a50:d59b:0:b0:58c:804a:6ee2 with SMTP id 4fb4d7f45d1cf-5b020bc1a79mr3071758a12.20.1722187487333; Sun, 28 Jul 2024 10:24:47 -0700 (PDT) MIME-Version: 1.0 References: <402c3c617c29465c898b1af55e3c6095@AcuMS.aculab.com> <5cd3e11780df40b0b771da5548966ebd@AcuMS.aculab.com> In-Reply-To: <5cd3e11780df40b0b771da5548966ebd@AcuMS.aculab.com> From: Linus Torvalds Date: Sun, 28 Jul 2024 10:24:30 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 1/8] minmax: Put all the clamp() definitions together To: David Laight Cc: "linux-kernel@vger.kernel.org" , 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 Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: orgpzntc7ue6j3gnxwd3ai4xzju1y1fx X-Rspamd-Queue-Id: C3A70100005 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722187490-180492 X-HE-Meta: U2FsdGVkX19spL2UVwk1PqEozyQtIJoVNXNZD0otE3fO45Qj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j4Izv7Vz7n8Xm4iUKcIkMKHbag8JI9Zgw4MjNJ+Wr5a+X1aXwO906lqRjWRG7L/y1psvOBKoVeZ8NJMSdU+C94A5JXVWw3WP+xOtstJQT8G4illJhjfU7llDLNAO7/qbgdkVTsJisirJydr5RFSqxfSQFBYESFr9i/q8V7jAaaoW5t6yY8toCxbufXb+Jl8NrqLT81Z2wilW3FZxK8zWxgQ5kw8psNawT0oe+XXzO3yJiIJYQUAXtarCon3uLO6cuag8SY9OLTBvtvgvtzb2Rwjse/Jo4K1Ow4L56Gv0V/XdpOgb1DYroG3CyIArGGSKXUubURp++NTFRJhBEpm+i640rJ9fxRqk= 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: On Sun, 28 Jul 2024 at 07:18, David Laight wrote: > > +#define min_t(type, x, y) __careful_cmp(min, (type)(x), (type)(y)) > +#define max_t(type, x, y) __careful_cmp(max, (type)(x), (type)(y)) This is unrelated to your patch, but since it moves things around and touches these, I reacted to it.. We should *not* use __careful_cmp() here. Why? Because part of __careful_cmp() is the "only use arguments once". But *another* part of __careful_cmp() is "be careful about the types" in __cmp_once(). And being careful about the types is what causes horrendous expansion, and is pointless when we just forced things to be the same type. So we should split __careful_cmp() into one that does just the "do once" and one that then also does the type checking. But I think even if we don't do that, I wonder if we can just do this: #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), \ ... and change it to #define __cmp_once(op, x, y, unique_x, unique_y) ({ \ __auto_type unique_x = (x); \ __auto_type unique_y = (y); \ static_assert(__types_ok(unique_x, unique_y), \ ... because while that may screw up the "constant integer" case (because it now goes through that "unique_XY" variable, maybe it doesn't? At least gcc has been known to deal with things like arguments to inline functions well enough (ie a constant argument means that the arguments shows as __builtin_constant_p(), and we already depend on that). That single change would cut down on duplication of 'x' and 'y' _enormously_. No? (You already did the __auto_type part elsewhere) Note that this would require the more relaxed "__is_noneg_int()" that I suggested that allows for any expression, not just C constant expressions) Linus