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=-0.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 18144C54FCF for ; Mon, 23 Mar 2020 12:15:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E2E9B20787 for ; Mon, 23 Mar 2020 12:15:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BWJ9F0zX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727486AbgCWMPw (ORCPT ); Mon, 23 Mar 2020 08:15:52 -0400 Received: from us-smtp-delivery-74.mimecast.com ([63.128.21.74]:32579 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727401AbgCWMPv (ORCPT ); Mon, 23 Mar 2020 08:15:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584965751; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=STBVOZ4+HTCp+/CYO9CQUgh44ZzKbpQfDmFXO2XUPKg=; b=BWJ9F0zXDNxEstdE42l7O8KzmASs84LsnL9JtORlsF5ty16FU2yjC6QWq41OWNI6cIzvXZ MiwX7FhjN2JjAeeblT/qIwn40VECfADA8d8ZCu+sLMRVxN22Tj8zouuFfF1hMjzJp7Cw1b PwSWvYZF+xEVnidjM4k0yWxaw0Ij//Q= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-318-7A9IluPYNSO8LOmaQ1My8A-1; Mon, 23 Mar 2020 08:15:47 -0400 X-MC-Unique: 7A9IluPYNSO8LOmaQ1My8A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6D6758017CC; Mon, 23 Mar 2020 12:15:45 +0000 (UTC) Received: from elisabeth (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3FA569497C; Mon, 23 Mar 2020 12:15:38 +0000 (UTC) Date: Mon, 23 Mar 2020 13:15:31 +0100 From: Stefano Brivio To: Andy Shevchenko Cc: Deepak R Varma , 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: <20200323131531.1d6c8f93@elisabeth> In-Reply-To: References: <20200323014935.48048405@elisabeth> Organization: Red Hat MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org 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). -- Stefano