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 X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EC5AC3F2CD for ; Mon, 23 Mar 2020 17:52:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71A442072D for ; Mon, 23 Mar 2020 17:52:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QqKcyBZO" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726962AbgCWRwd (ORCPT ); Mon, 23 Mar 2020 13:52:33 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:41264 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725880AbgCWRwd (ORCPT ); Mon, 23 Mar 2020 13:52:33 -0400 Received: by mail-pl1-f195.google.com with SMTP id t16so6218559plr.8 for ; Mon, 23 Mar 2020 10:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=NTsJVXFyBe5n2J4yvrNhtYB6s8FILu94rLXAvDE+4Gk=; b=QqKcyBZOabFgMGkIZO+TEilyn0nNbsds6TzI6VKrhH3UaZ316WHPhXT7W5z9ibLcZZ 0WdK7LJGolrpMlmObvNl33iYMNE61QNV1WO1tprnzIqew5+YnkZIANSR1iiAMKMm7VtQ /vDMVoM84lf7I0A3r279o3Hg4Sbkj2/4xSsTrIgsSnJdfRrZe80ayPyuzNv9mNi/KUMz o/yC18rucrBUcU20OwrRBN3QQQOPA/CZ9r/Nu+5DZU2BMv97KWGVRWbAT6R7QYiQlH84 l+HUcnufMcljStmESnn9dZnDawarsJkIqEC4xSKgtUnsUXOp8s51XqBVhzd1LqMhQRwM U1ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=NTsJVXFyBe5n2J4yvrNhtYB6s8FILu94rLXAvDE+4Gk=; b=JNIvcz7W8MLKOsejkQEmJ0aRuTqeX4xXDalvqC1hVDq0fJS6iDa8f2c0QlzN+Y/Sge 6sopbeqEHWDvpsV3SwIg0weHjAP54dvb14f1hm6aTPZICuG6opPLwhO/8WFL1TAUZPJE R/VAqhqTU/KJR4vE6YNMJcl2gmQjWXWkwJCCFPxnVXwVbzVhVn691sCx6+PEDimeltfY Rf2GkujyybYYwXB8FRz9f/bvNQcO1cU7E1I85uf0k1D35xSj38fgweSwMq3hfrR2ybJx QFN4frg6t0ntKT8+BkEDiX7LWA6KhlbXFOO5aPsKQHL3WIKXl1PsiK0Q3ujf/26Xw8qK U8AA== X-Gm-Message-State: ANhLgQ1hRut480srqHdPYRU++/nFCA8qfHdw3u1R0HZd1xXG5zkpqr8M m9kXUdVkvRjpHl3ExAwGMaM= X-Google-Smtp-Source: ADFU+vuYP7OS5jVAvY0oLvrokrcY96CYIAJFNHNrsBj4EmVocePSJeFsEI3QicVVWxxXtbusYmNWBQ== X-Received: by 2002:a17:90a:fa96:: with SMTP id cu22mr482775pjb.187.1584985952666; Mon, 23 Mar 2020 10:52:32 -0700 (PDT) Received: from deeUbuntu ([103.240.207.191]) by smtp.gmail.com with ESMTPSA id 189sm4195902pgh.58.2020.03.23.10.52.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 23 Mar 2020 10:52:32 -0700 (PDT) Date: Mon, 23 Mar 2020 23:22:24 +0530 From: DEEPAK VARMA To: Stefano Brivio Cc: Andy Shevchenko , outreachy-kernel@googlegroups.com, Greg Kroah-Hartman , Daniel Baluta , kieran.bingham@ideasonboard.com, Lars-Peter Clausen , Michael Hennerich , Jonathan Cameron , Hartmut Knaack , Peter Meerwald , linux-iio Subject: Re: [Outreachy kernel] Re: [PATCH v3 3/4] staging: iio: adc: ad7192: get_filter_freq code optimization Message-ID: <20200323175223.GC22110@deeUbuntu> References: <20200323014935.48048405@elisabeth> <20200323131531.1d6c8f93@elisabeth> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200323131531.1d6c8f93@elisabeth> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org On Mon, Mar 23, 2020 at 01:15:31PM +0100, Stefano Brivio wrote: > On Mon, 23 Mar 2020 11:28:52 +0200 > Andy Shevchenko wrote: > > > On Mon, Mar 23, 2020 at 2:49 AM Stefano Brivio wrote: > > > On Mon, 23 Mar 2020 01:44:20 +0200 > > > Andy Shevchenko wrote: > > > > On Sun, Mar 22, 2020 at 9:57 PM Deepak R Varma wrote: > > > > > > > > > > Current implementation of the function ad7192_get_available_filter_freq > > > > > repeats calculation of output data rate a few times. We can simplify > > > > > these steps by refactoring out the calculation of fADC. This would also > > > > > addresses the checkpatch warning of line exceeding 80 character. > > > > > > > > I'm not sure you did an equivalent changes. I believe in the original > > > > code precision is better. Consider low clock frequencies when 10 bit > > > > right shift may hide some bits of the division. > > > > > > Note that those bits are eventually "hidden" in the same way later, > > > > Even if mathematically (arithmetically) evaluation is correct, we have > > to remember that computers are bad with floating point and especially > > kernel, which uses integer arithmetic. That said, it's easy to get > > off-by-one error (due to precision lost) if we do big division before > > (not so big) multiplication. > > That's exactly the point I was trying to explain below: swapping steps > in a sequence of DIV_ROUND_CLOSEST() (*not* of arithmetic divisions), > *should* not affect quantisation ("off-by-one") error. > > I'm not entirely sure in this case, so a quick "demonstration" in > Python or suchlike as you suggested would be nice to have, indeed. > > > > despite the different sequence, due to DIV_ROUND_CLOSEST() being used > > > at every step (both before and after the change) without other > > > operations occurring. > > > > By the way, where AD7192_SINC3_FILTER and AD7192_SINC4_FILTER > > multiplications disappear and why? > > Those were in fact divisions (multiplications of the divisor). Overall, > these steps are now arranged in a way closer to how they are presented > in the datasheet mentioned here (up to "Chop Enabled" paragraph, page > 26). > Thank you Andy and Stefano for your comments. Its very thoughtful. I am not much familiar with Python so far, but thinking on evaluating your suggestion in a sample c program. I will share the outcome shortly. Deepak. > -- > Stefano >