Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp71478rwb; Fri, 4 Aug 2023 09:18:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHZFZA9GjfiTBtql9WeA9aQrAXctB7CY/mM/+kiC9I1yITqBZxsf5IeomUssRnrcMsYfH+J X-Received: by 2002:a05:6512:31c7:b0:4fd:fc36:68a2 with SMTP id j7-20020a05651231c700b004fdfc3668a2mr1987266lfe.1.1691165923085; Fri, 04 Aug 2023 09:18:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691165923; cv=none; d=google.com; s=arc-20160816; b=YyB9+a5yFFaCatWmJ50FPehYPSG/e8DJzBAbBV9pItaEPoeFY6Dx44OW2Z0cdwmFtQ 22ah/kuxM60VC9Eb9lQspRcS+aCIryYqYKU9Nuz6lyI42FIb07Vxmete82bDX2RVSoI0 PFPKtz3Bs6EwylOFFpPPxiEl6L+gUYEjqgmRa6/TME6FYAXDbSJ6U7i6VUsRHVkaiR7M C39GAg7anoxxgC6BhXNJhXY+ohXQZ3i/VQXhwPX4kwtGpFV6dhWiByN0w1MTvdhhlGzy xkexG0CZCpx1qjPiKUBJ7cF5favlWBkbfUNItZnvtMpdqlygsvT/E3YRr3bguc84PmP3 YW4A== 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=u037wdqROS2Zvv7xFZpzp6XU+VYpz7FyElTRxDiTM6M=; fh=ywMJn/36SNJhGK6I2XDVtZ596Z4C9/FkIwRmGccA2rA=; b=JNaFDV6c1jD+IhL7Yhzeg0T6zoE2N84uaokJZk7cBzMwMd1dx6h+LCkn1ieG0jdyYZ o8adPYd3HZjbagYybgwhcL8ANIboYJKyzz67ROnKF5YEhlDdYuBaEkYu0zKqPfBki3lj Z/jRdhxxhMn0SooqvmVa5pa2fEhGpTQM25FvvrSkBOVW8cFEBg6Ko2p4LUiuuiQ8+02N Zz8WddoLyvv7PIHD6cmTDnevDIEQpLQe25Uh544hwSzVPjTotL6e1nLgWczpzjz8nacI 0kkIm6/z2dg309RWReM1o35yJKlsN25JK2s2seXddlNOsIH90neRxfyhQPmDQo1hayD2 FgXg== 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 j7-20020a50ed07000000b005225522e9a0si542442eds.597.2023.08.04.09.17.57; Fri, 04 Aug 2023 09:18:43 -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 S231335AbjHDPuZ convert rfc822-to-8bit (ORCPT + 99 others); Fri, 4 Aug 2023 11:50:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230486AbjHDPuY (ORCPT ); Fri, 4 Aug 2023 11:50:24 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 534E0212D for ; Fri, 4 Aug 2023 08:50:23 -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-mta-76-qm7ktrQ9OHKl6gBtn9SNaQ-1; Fri, 04 Aug 2023 16:50:20 +0100 X-MC-Unique: qm7ktrQ9OHKl6gBtn9SNaQ-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; Fri, 4 Aug 2023 16:50:18 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Fri, 4 Aug 2023 16:50:18 +0100 From: David Laight To: 'Andrew Morton' , Andy Shevchenko CC: Jani Nikula , Imre Deak , Philipp Zabel , Andi Shyti , Jiri Slaby , "Greg Kroah-Hartman" , Alexey Dobriyan , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , "linux-serial@vger.kernel.org" , "linux-fbdev@vger.kernel.org" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Daniel Vetter , "Helge Deller" , Rasmus Villemoes Subject: RE: [PATCH v4 1/1] drm/i915: Move abs_diff() to math.h Thread-Topic: [PATCH v4 1/1] drm/i915: Move abs_diff() to math.h Thread-Index: AQHZxi9qpYx0cq9pFEOYLGUrdsezOq/aSRTQ Date: Fri, 4 Aug 2023 15:50:18 +0000 Message-ID: <7c1885528d474c719bb4d4e0cf985753@AcuMS.aculab.com> References: <20230803131918.53727-1-andriy.shevchenko@linux.intel.com> <20230803102446.8edf94acc77e81ab2e09cee3@linux-foundation.org> In-Reply-To: <20230803102446.8edf94acc77e81ab2e09cee3@linux-foundation.org> 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,PDS_BAD_THREAD_QP_64, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS 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: Andrew Morton > Sent: 03 August 2023 18:25 > > On Thu, 3 Aug 2023 16:19:18 +0300 Andy Shevchenko wrote: > > > abs_diff() belongs to math.h. Move it there. > > This will allow others to use it. > > > > ... > > > > --- a/include/linux/math.h > > +++ b/include/linux/math.h > > @@ -155,6 +155,13 @@ __STRUCT_FRACT(u32) > > __builtin_types_compatible_p(typeof(x), unsigned type), \ > > ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other) > > > > +#define abs_diff(a, b) ({ \ > > + typeof(a) __a = (a); \ > > + typeof(b) __b = (b); \ > > + (void)(&__a == &__b); \ > > + __a > __b ? (__a - __b) : (__b - __a); \ > > +}) > > Can we document it please? > > Also, the open-coded type comparison could be replaced with __typecheck()? > > And why the heck isn't __typecheck() in typecheck.h, to be included by > minmax.h. And why would you want to use __typecheck() anyway? It pretty much isn't the test you are looking for. If you are trying to explicitly avoid converting negative value to large positive unsigned ones then you want something like: is_signed_type(typeof(a)) == is_signed_type(typeof(b)) but it isn't even that simple :-) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)