Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6231034pxv; Thu, 29 Jul 2021 09:23:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPU7qvfbxHs+X2kAK+Rrl6QgYHae6rNUIKsg3T3iRWma44wQCHh6mfw/Gb29dpLpJvcctS X-Received: by 2002:a05:6402:3492:: with SMTP id v18mr3555290edc.299.1627575797838; Thu, 29 Jul 2021 09:23:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627575797; cv=none; d=google.com; s=arc-20160816; b=RgZ/BpiJroNlAru6nYAtLJgiZt0XLbMPDNMTmHRnoPfq+7XfqVyyyCqDm7ku9RhULH +mz3XtWLv9kKvrtp6eUfQRAt0zPTfikc4c5JDrByMOiye9UEfBGmGIYrvXCjOY/tUcfM FvC0sTe29YGlrcdA+3H7igw6ST4EEmAq0+ncBDTztKlVkg/UFyTv8b2gb5gKnvlh68+W ZyqeZfRVq5cfO4clj7tZmiyVrnceyXi9pclYfK4/0G8EJbTjHL4eFD7AfpVm9uU8pk4B JJ7HNQJ8WLkFL+SP260SGEOfqfgPXwrgwVrK6RHhSwoj4E8KQ5HfP1zsyNiEo33wHntg CNCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:references:to:from:subject:cc :message-id:date:content-transfer-encoding:mime-version :dkim-signature; bh=+KrPCSnHKZvHsetzaaVnpnXvX+hBEhmIj6HrXqly/yw=; b=y0CQS1sX5MgkxobqFmXu5yEbJ2WoJD4NybTfHqMEiE5fUnUCRJ7yH58S9TMordGccK mVQ9xZ2RQc+mXmzBT20QLZDZreYLaE5nHja2DDcm+FRdw4d+RQxBdM8UBdIFbwDlh6GP Au0RyrETCmoo2ndlW/5TEGjvRX6s4Eu8E6SeHYzv5V3XE72Bor9lRkqZKcuyXoqT6x5M xhSgWSHkrj+PS4SctlVm6saqMvZzwRs/C39C9bOA847xz0daIbNn8XbZgxjIyTJh9xcs ABoVHz8GDFL+WM1z1U7wecwfO7jc5d0FB/OhimF7mH80dNIPYRe1xkwNzMHNSx1lBE/Y xIhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="hbn/daSt"; 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 gt4si3217836ejb.382.2021.07.29.09.22.53; Thu, 29 Jul 2021 09:23:17 -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="hbn/daSt"; 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 S231549AbhG2QTS (ORCPT + 99 others); Thu, 29 Jul 2021 12:19:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231193AbhG2QTR (ORCPT ); Thu, 29 Jul 2021 12:19:17 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6F17C0613C1; Thu, 29 Jul 2021 09:19:13 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id 190so6469183qkk.12; Thu, 29 Jul 2021 09:19:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:content-transfer-encoding:date:message-id:cc:subject :from:to:references:in-reply-to; bh=+KrPCSnHKZvHsetzaaVnpnXvX+hBEhmIj6HrXqly/yw=; b=hbn/daSt/1s1i1oc3sjUwYCXyQaDW0+Mlwv2Pysfhzvc/OXs2haCgtHEO5EdaCK6Ve eGapBu0EK0vdaYskUIGMEy00N0x7IYD4Sl1DTYo7S3DYzRSMufUWfzoJtT/yy9fzG3VI i4txpMPImlvJevkt/snlTeKEleeDR30pnqiis2YWhxCJ63xV3BPOyJ7bF6RCCmJxK27Q HvIJVkZzM7gx0m0mvush8FurK6KhFzhkht8U0TY3yWxB6btlNaqSWa0hQrPq9ER9owAU iWj3h0Hqi73o5ahu0FRTYwB/zsMBWz6450p2bj/kbKfSHzMv7cw80+FwF6wj+u39bClq L3QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:content-transfer-encoding:date :message-id:cc:subject:from:to:references:in-reply-to; bh=+KrPCSnHKZvHsetzaaVnpnXvX+hBEhmIj6HrXqly/yw=; b=EMILTMtkYJ1fme0hJsx8ZdD73pDHE7pdt57KtgmPtGSpuA3l50gscMIZOSs6m7FZhZ 0MY1WGPrLQoXwbjBMQ7QBRaOs9NNcGXcXv05Vsee7cZXCegerSBdxxX3kJJpk1IvQ6Ik gNWHDIWVx/bxByr1D74Im8fPDS+hb8/ZL3YEqc16yRGMHhmx/5ygNjdvq7tR2udvyYBi ZsA2gfx5/MX6vi+P/uESiYNq8ILBhpXLK6cMJ3MZmvRSkL2HEU5dQPys+e/R8GHjhqkv zVW5mIchZOWGGCCNxuT33W/TqEwoYrHjLCj9uGgBmwzTg/KUwfZBvV6W8SgfzBGOU4UA UXDQ== X-Gm-Message-State: AOAM532f6Ds1+qknEZcfl+Q0ppnTVZXoFzhF8Bc84G6BBuWrdRrIk3wZ UKe+LUxgsahdaTSs1xNPCfY= X-Received: by 2002:a05:620a:124e:: with SMTP id a14mr5958489qkl.356.1627575552888; Thu, 29 Jul 2021 09:19:12 -0700 (PDT) Received: from localhost (198-48-202-89.cpe.pppoe.ca. [198.48.202.89]) by smtp.gmail.com with ESMTPSA id g26sm1930311qkm.122.2021.07.29.09.19.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 29 Jul 2021 09:19:12 -0700 (PDT) Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 29 Jul 2021 12:19:11 -0400 Message-Id: Cc: , , , Subject: Re: [PATCH v6 09/13] iio: afe: rescale: fix precision on fractional log scale From: "Liam Beguin" To: "Peter Rosin" , , , References: <20210721030613.3105327-1-liambeguin@gmail.com> <20210721030613.3105327-10-liambeguin@gmail.com> <4e477a42-1cae-06f8-2778-fc734359d6f3@axentia.se> In-Reply-To: <4e477a42-1cae-06f8-2778-fc734359d6f3@axentia.se> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed Jul 28, 2021 at 3:58 AM EDT, Peter Rosin wrote: > On 2021-07-28 02:26, Liam Beguin wrote: > > On Fri Jul 23, 2021 at 5:20 PM EDT, Peter Rosin wrote: > >> On 2021-07-21 05:06, Liam Beguin wrote: > >>> From: Liam Beguin > >>> > >>> The IIO_VAL_FRACTIONAL_LOG2 scale type doesn't return the expected > >>> scale. Update the case so that the rescaler returns a fractional type > >>> and a more precise scale. > >>> > >>> Signed-off-by: Liam Beguin > >>> --- > >>> drivers/iio/afe/iio-rescale.c | 9 +++------ > >>> 1 file changed, 3 insertions(+), 6 deletions(-) > >>> > >>> diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-resc= ale.c > >>> index 35fa3b4e53e0..47cd4a6d9aca 100644 > >>> --- a/drivers/iio/afe/iio-rescale.c > >>> +++ b/drivers/iio/afe/iio-rescale.c > >>> @@ -44,12 +44,9 @@ int rescale_process_scale(struct rescale *rescale,= int scale_type, > >>> *val2 =3D rescale->denominator; > >>> return IIO_VAL_FRACTIONAL; > >>> case IIO_VAL_FRACTIONAL_LOG2: > >>> - tmp =3D *val * 1000000000LL; > >>> - do_div(tmp, rescale->denominator); > >>> - tmp *=3D rescale->numerator; > >>> - do_div(tmp, 1000000000LL); > >>> - *val =3D tmp; > >>> - return scale_type; > >>> + *val =3D rescale->numerator * *val; > >>> + *val2 =3D rescale->denominator * (1 << *val2); > >>> + return IIO_VAL_FRACTIONAL; > >> > >> Hi! > >=20 > > Hi Peter, > >=20 > >> > >> I do not think this is an uncontested improvement. You have broken the > >> case > >> where *val2 is "large" before the scale factor is applied. > >=20 > > I was a little reluctant to add this change as I keep increasing the > > scope of this series, but since I added tests for all cases, I didn't > > want to leave this one out. > > > Would you rather I drop this patch and the test cases associated to it? > > Why drop the tests? Are they doing any harm? Or are they testing exactly > the problem situation that fail without this patch? They are testing this problem and fail without the patch. > > In that case, I guess fix the tests to pass and preferably add tests > for the *val2 is "large" situation (that this patch breaks) so that the > next person trying to improve precision is made aware of the overflow > problem. Does that make sense? To handle large values of *val2, I could use the same logic as in IIO_VAL_FRACTIONAL with check_mul_overflow() and gcd(). would that be okay? Thanks, Liam > > Cheers, > Peter > > > Thanks, > > Liam > >=20 > >> > >> Cheers, > >> Peter > >> > >>> case IIO_VAL_INT_PLUS_NANO: > >>> tmp =3D ((s64)*val * 1000000000LL + *val2) * rescale->numerator; > >>> tmp =3D div_s64(tmp, rescale->denominator); > >>> > >=20