Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2191317pxa; Mon, 3 Aug 2020 09:37:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwk8k8rBWqV6zbjQeXRWOk2/iWcXfwKZhxPpLQQUGAX6omyS6zs4hD1dubVooOTIPEqnNG X-Received: by 2002:a05:6402:1d93:: with SMTP id dk19mr16170450edb.382.1596472673255; Mon, 03 Aug 2020 09:37:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596472673; cv=none; d=google.com; s=arc-20160816; b=EQzd1qVHKKOdHbTdEE33xUrWojWkhvapwM0MSElXNTdG8qKETjMUPNApeJUaRi6qqN W8nh68Nz9KCIx/BPGBYJq4AYP742Lyy2MEZlPnk1sWG79Sbo/6r6m+CJqNx0tHt5zPs8 +X27OKrv53RH31WJg2ngoAyUnuDOKuZEsqeWsGi+IyHFds7zVZXlx1EhD4aaxv3qIQfa RzTUsDTVMdzBS0Oo6PJe0aVDBN/D01ji6nBYVw10vrAxAuplIzTfXsvHk/5fghjBBFW2 8gIgOU0Gv8Xl73fxAx1vlQ2NTpdvRXtJHvVQ6wOAqJCJKlXN9/56xhNVMZelW3PN5X6Q /2Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=aRy5XNlke5IVnZt6sTMSjwcVBGjttryTgAPuHqOx9j4=; b=ki1HmnV65eRZJ35iDAxlUon+HVrnPRfE7C/6eglORUvgOXMqCg/IAGN/ar+TONsXZw ZgFfd/aTYF2o9H761PsFqiwVOMe0p0pJXG58qv7uOaXElLpILkUWXRrCsj3SE6TslsJk RZJUZsrbKPefu5UQtXvL2QS1jwZfHxyv1PjLaWoRQwEYPUCo/+R3Bw9fAl+oAg45bHhT L1L3B2/kTw/9N4CxcpWCGZMvM7jX79aAL8KBy10H8syhZZpJ9DxUqwENQQzx821ebaYI 4j/0G89tDqxvwyN8D3aE1gMafvsOSbmmMTLGYd67SYGQ8r/0BQcS+cxfuSF/zE8cg7tg c/wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kn6i3PXU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r7si7556636ejo.640.2020.08.03.09.37.31; Mon, 03 Aug 2020 09:37:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=kn6i3PXU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726767AbgHCQfI (ORCPT + 99 others); Mon, 3 Aug 2020 12:35:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726189AbgHCQfI (ORCPT ); Mon, 3 Aug 2020 12:35:08 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B284C06174A; Mon, 3 Aug 2020 09:35:08 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id z5so20172503pgb.6; Mon, 03 Aug 2020 09:35:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aRy5XNlke5IVnZt6sTMSjwcVBGjttryTgAPuHqOx9j4=; b=kn6i3PXUFUQH/VqSaREbKFj2TJx+e0PLygDMv6IaDSVQfrXGBMhv6TUWQHxLltsG3B wDsOB9pM3Ap+XeBiV5JNbVFAbYOFZsgRMm7hiMxiBEu6Ni5r2bhbZhSjCWqSyGdIYdYF Q9XugV1ayVllr2VDlYiEqUlNqSFZQi2MSvBxf2ANCfQq36gF0LEm7oMKzv01arOnFSuX dTDdYUSA5X6s4l5v8trsyS9X8PGnjTAhzXB6OhsPalc6x7rCImzB56apFixz4UYpkexH /GUp3uQFriJRmfWZL9VzwXBTYTHQWn2qJhQzWPv1O0Ks4epx/gTLmlSjIrvHkUWIiY7t LVMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aRy5XNlke5IVnZt6sTMSjwcVBGjttryTgAPuHqOx9j4=; b=Ig1haYh2eQRvqgiKwU4yBfZ/pFs3SlEnBuAHeWKE9ZeTcqOUCSxJ8H5VSjuBU1dzdp JHdtY0tvijywjWDz5bOLrQNH7oxR+Hut23Ml618pivVXykp0vjj95y0tD0EEHaYmsUTl m/JSas1q47Kwpi0X9JcU1W78na9zX1pANygroHHuYbcn/rStWsmlFUxC34oBMJhx198a zKUqs6LySHX0S+/BJ+KEIioD37pNquyMNpmUo+8segUNyb8jAa2rXEGIkzu9EmJJc2U5 5Na+7D4CYD4lt9iGatjox4j01z3QW9GJM+2B2+dHih1nlW6Vv927dzh+HQy+F1hWLLIt FcCw== X-Gm-Message-State: AOAM530Z8+mcCwHH1fEDwVgeZfuNQp3cEWsQRTIzO6fIv6nj5u9PMMyZ 6GNa+zc3J/KDs6u9srdV3lNIBv8tQvENwcZTTZA= X-Received: by 2002:a62:758f:: with SMTP id q137mr15998175pfc.170.1596472507773; Mon, 03 Aug 2020 09:35:07 -0700 (PDT) MIME-Version: 1.0 References: <20200803151656.332559-1-cmo@melexis.com> In-Reply-To: <20200803151656.332559-1-cmo@melexis.com> From: Andy Shevchenko Date: Mon, 3 Aug 2020 19:34:52 +0300 Message-ID: Subject: Re: [PATCH] iio:temperature:mlx90632: Reduce number of equal calulcations To: Crt Mori Cc: Jonathan Cameron , linux-iio , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 3, 2020 at 6:17 PM Crt Mori wrote: > > TAdut4 was calculated each iteration although it did not change. In light > of near future additions of the Extended range DSP calculations, this > function refactoring will help reduce unrelated changes in that series as > well as reduce the number of new functions needed. Okay! > Also converted shifts in this function of signed integers to divisions as > that is less implementation-defined behavior. This is what I'm wondering about. Why? ... > - Ha_customer = ((s64)Ha * 1000000LL) >> 14ULL; > - Hb_customer = ((s64)Hb * 100) >> 10ULL; > + Ha_customer = div64_s64((s64)Ha * 1000000LL, 16384); > + Hb_customer = div64_s64((s64)Hb * 100, 1024); Have you checked the code on 32-bit machines? As far as I can see the div64_*64() do not have power of two divisor optimizations. I bet it will generate a bulk of unneeded code. ... > - calcedKsTO = ((s64)((s64)Ga * (prev_object_temp - 25 * 1000LL) > - * 1000LL)) >> 36LL; > - calcedKsTA = ((s64)(Fb * (TAdut - 25 * 1000000LL))) >> 36LL; > - Alpha_corr = div64_s64((((s64)(Fa * 10000000000LL) >> 46LL) > - * Ha_customer), 1000LL); > + calcedKsTO = div64_s64((s64)((s64)Ga * (prev_object_temp - 25 * 1000LL) > + * 1000LL), 68719476736); > + calcedKsTA = div64_s64((s64)(Fb * (TAdut - 25 * 1000000LL)), 68719476736); > + Alpha_corr = div64_s64(div64_s64((s64)(Fa * 10000000000LL), 70368744177664) > + * Ha_customer, 1000LL); This is less readable and full of magic numbers in comparison to the above (however, also full of magics, but at least gives better hint). ... > + TAdut4 = (div64_s64(TAdut, 10000LL) + 27315) * > + (div64_s64(TAdut, 10000LL) + 27315) * > + (div64_s64(TAdut, 10000LL) + 27315) * > + (div64_s64(TAdut, 10000LL) + 27315); Shouldn't you switch to definitions from units.h? (perhaps as a separate change) -- With Best Regards, Andy Shevchenko