Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4482001rwo; Tue, 25 Jul 2023 06:49:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlH09Xa6KKD4GDLj6diBIKWgnGgiQVtLoE3XrwGZVHawX3flU7W10cAtFM8cq8jLU8qIix+L X-Received: by 2002:a05:6512:3c90:b0:4f8:7568:e948 with SMTP id h16-20020a0565123c9000b004f87568e948mr9761868lfv.51.1690292985235; Tue, 25 Jul 2023 06:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690292985; cv=none; d=google.com; s=arc-20160816; b=T6A8nqwCy4m4rFFXa4jwfMRExObeI+rbWAaV/rAltbWE0zB7NgukUJdfiBYGmNgK99 lyxzbXpAANbOpHvVQ0uOpSt24k+DKgwI5A8aSiuQljw0/JSvM5IRUF0uzHSzqV7BlxGG BL0jPhqdwGK6T5kjLNIRJQkx2/rVr72+GRNMbJ7jRxLkQAZKUlK39ILcQA7mED54cSiK f0wICuDbr9UEDYWDiJW9Rt6PeDd+PLDV/gzFZ1j4aBTt6yl6jMS6o0nLb6Hfiey/0eox +saQZZh/mZjZ1RPxrVILnn/GgkVxYjjx5vapWZHH9TjsU+b14SmB6l3zP2mG+JNALXLV dPKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=KjMCPiHAwAADrUlpnrfOvmH5KWjvqtsTnORVIrnqQKw=; fh=bmxXImHBeQcsGgew25VI+0ombJEDWcW1294HVlqU95U=; b=HyMYyxM/rl7VDE3lyTFWgB8Y1Ab3juvr6jw3Fgi+pT/7LkWOFFjPzuYUoIwZVbHRqV lDQpYHJLhRI66Bqk0tXCS2v20hYgyd9vhf8/PP0vYNp62wGUllDRaXtOJL6SJdZmQR/e tsIHO643APtDnTQnNPihI3wv4csObnlwtPkY7RB/rX96/aNUn0K4KnwJ7czsu/gsv+m5 lspZDE0IrnwTeq9eBqX2S7qZ2TCQF5jb2clws9Ky+5raw+utVJpsQv91tYXuLHPn1Eq+ YRRgC14R+zX/TDoKVWBacPW6smqq2C7ckzhyrl6KCllOix1EdaWdLgB9zxwGA9Ld7pik pTIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q21-20020a056402033500b0052229f4ef42si3725462edw.192.2023.07.25.06.49.21; Tue, 25 Jul 2023 06:49:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230082AbjGYNUb convert rfc822-to-8bit (ORCPT + 99 others); Tue, 25 Jul 2023 09:20:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230018AbjGYNU3 (ORCPT ); Tue, 25 Jul 2023 09:20:29 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.86.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7F661BC2 for ; Tue, 25 Jul 2023 06:20:05 -0700 (PDT) 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-mtapsc-3-QArLaFZZPIyQRdYbCeCJSQ-1; Tue, 25 Jul 2023 14:20:02 +0100 X-MC-Unique: QArLaFZZPIyQRdYbCeCJSQ-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; Tue, 25 Jul 2023 14:20:01 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Tue, 25 Jul 2023 14:20:01 +0100 From: David Laight To: 'Matthew Wilcox' CC: "'linux-kernel@vger.kernel.org'" , "'Andy Shevchenko'" , 'Andrew Morton' , 'Christoph Hellwig' , "'Jason A. Donenfeld'" Subject: RE: [PATCH next resend 1/5] minmax: Add min_unsigned(a, b) and max_unsigned(a, b) Thread-Topic: [PATCH next resend 1/5] minmax: Add min_unsigned(a, b) and max_unsigned(a, b) Thread-Index: Adm+7eUTa4I5Whq+QJmE/BdQ09ksJP///VUA///lOfA= Date: Tue, 25 Jul 2023 13:20:01 +0000 Message-ID: <66e58cd2cffa462a979ac5415874a570@AcuMS.aculab.com> References: <62d82a41b94c475bacceb0f6b11583a1@AcuMS.aculab.com> In-Reply-To: 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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthew Wilcox > Sent: 25 July 2023 13:39 > > On Tue, Jul 25, 2023 at 11:48:14AM +0000, David Laight wrote: > > +#define min_unsigned(x, y) \ > > + __careful_cmp((x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull, <) > > What is the point of "+ 0u + 0ul + 0ull"? How is that any different > from "+ 0ull"? And why force the compiler to do a 64-bit comparison > when it could do a 32-bit comparison? The "+ 0u + 0ul + 0ull" causes a signed 32bit value to be zero extended to 64bit. This is significantly cheaper than the sign extension. (Adding 0ull first converts a signed 32bit value to a signed 64bit one - the same as a cast.) The compiler also then knows that the high 32bit are zero and optimises away any associated compares. So you get a 32bit compare (on both 32bit and 64bit) if both arguments are 32bit. This happens even at -O0. It also has no effect on pointer types. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)