Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1239476pxv; Fri, 25 Jun 2021 08:24:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSenY7zD3hI6vLjd7XpoFPLu5QpzN9LuUNotJi/tuXuChEbQx/v4yi26cmfJ7+rglKeivV X-Received: by 2002:a92:c886:: with SMTP id w6mr7803586ilo.227.1624634673799; Fri, 25 Jun 2021 08:24:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624634673; cv=none; d=google.com; s=arc-20160816; b=jUji9cANPm7EdiI7LAIHK87AIXuYNj5s743OlCv3k5PkGvMPAirflBwhnNER4wsq4Q lf4h4KpX9YdxRYCQzMnJyL5TZ60/osHUVN08gC0fvrt4k1pI9Sym/F1ieMyXSBL9q/cW 70puyt43lthwmKGBl0PoIqZSvnOkY8uJjx4xA9eazyHxGMjJelv4lB8YhNDFRwsY3+C6 za7klwx82brMbvgCK5V6Io/xNSB73G52apbcyPDe+0SA3ky+yzPVdChfl0M2fqEugfYj uF5hpkt6VowK+xTfAxjM3rqKuwIsGbuOiKSoOnK3UlSQOEg+p2MYuDPzk3HHRKFlXX8S jPZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=Q5IIQV/EHjAsn0lYb5qn9RJF1rimM5/8FO6E0z+mYho=; b=SPR5Vl4WYpSg+ajn1ubRZghHX8dCgB0VfPHIwaMAUMP3bec3FSIzBdw5BN1Iz4tYe9 bb8ilGzc+JOYTMC//+8gKkqnce0+wKEYTao8o+jC/t2bpfgx14bP7bBMBAq7/HYS7pPy 7TMRBLE8cl/6B+GhKhIFiu1r3JnXw/vdCZXpf4SsVp97oWsMuE9K9HyPWouLyvHJuZ3J 6E0L+BCIQM+nhp6OVeK+zAzdvDWD8TFLPY6eZloRDf9hfLcJChFpsPFkfFR4+RkyYbIn FfC/1cnl2R6OqXKO979ib8XBA+Fn+c1oiTLa2HHaTnnVr7EJdmoVAG+rWwsceoQoymeY cFpg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 15si7270330ilz.158.2021.06.25.08.24.21; Fri, 25 Jun 2021 08:24:33 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229818AbhFYPZE convert rfc822-to-8bit (ORCPT + 99 others); Fri, 25 Jun 2021 11:25:04 -0400 Received: from mail-ua1-f51.google.com ([209.85.222.51]:33382 "EHLO mail-ua1-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbhFYPZD (ORCPT ); Fri, 25 Jun 2021 11:25:03 -0400 Received: by mail-ua1-f51.google.com with SMTP id x22so3706629uap.0; Fri, 25 Jun 2021 08:22:42 -0700 (PDT) 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:content-transfer-encoding; bh=dckc1Y5oArfmqGf9uhmcW+nVHTA44z1zSQ9JQ8A7cx0=; b=OdFz68Ss39x1a3x9wewTT1eEq+Owq4P92wZJSjxYbRsN75VneRc0R979vQnEjDAQ3R htxICHBUvvcrZFGud10IQS4rrn8vYVa4wFpP3DIl13JpwVUQGPUCyFwsFJUhki7Wgo3m 7YixqNtyUdyxLHfsmCb+4gDlAq6Ypa79BCavSC/trjPtPh/PRfUJlqFli/H9uPN7U3vO BIOmCwpaWHNm9oIZJBm2RuLy1rXDNMT9p9Zdyz0tzAz9wcj7dqdPHPoPCnU4Ggk5KZS3 4bZ+z/9uyhU/NuoA7FrmfDNDJs94lBn4zPEc9X9Xzpkz75ITXKKUqH/bPoOJPdOqXug+ x6eQ== X-Gm-Message-State: AOAM532Ra1lXQYquyWN0TEMxj6/hNrCks/8V24AZjnBn+G54EKPX7JFL aT3P2UCKMGzOidvWfkaGtj7lYawUqooo9M6jTlc= X-Received: by 2002:ab0:647:: with SMTP id f65mr11970038uaf.4.1624634562204; Fri, 25 Jun 2021 08:22:42 -0700 (PDT) MIME-Version: 1.0 References: <20210624224909.6350-1-pali@kernel.org> <20210625143617.12826-1-pali@kernel.org> <20210625143617.12826-8-pali@kernel.org> In-Reply-To: <20210625143617.12826-8-pali@kernel.org> From: Geert Uytterhoeven Date: Fri, 25 Jun 2021 17:22:31 +0200 Message-ID: Subject: Re: [PATCH v2 07/11] math64: New DIV_U64_ROUND_CLOSEST helper To: =?UTF-8?Q?Pali_Roh=C3=A1r?= Cc: Michael Turquette , Stephen Boyd , Rob Herring , Greg Kroah-Hartman , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Vladimir Vid , =?UTF-8?B?TWFyZWsgQmVow7pu?= , linux-clk , "open list:SERIAL DRIVERS" , Linux Kernel Mailing List , Linux ARM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Pali, On Fri, Jun 25, 2021 at 4:37 PM Pali Rohár wrote: > Provide DIV_U64_ROUND_CLOSEST helper which uses div_u64 to perform > division rounded to the closest integer using unsigned 64bit > dividend and unsigned 32bit divisor. > > Signed-off-by: Pali Rohár Thanks for your patch! > --- a/include/linux/math64.h > +++ b/include/linux/math64.h > @@ -281,6 +281,19 @@ u64 mul_u64_u64_div_u64(u64 a, u64 mul, u64 div); > #define DIV64_U64_ROUND_CLOSEST(dividend, divisor) \ > ({ u64 _tmp = (divisor); div64_u64((dividend) + _tmp / 2, _tmp); }) > > +/* > + * DIV_U64_ROUND_CLOSEST - unsigned 64bit divide with 32bit divisor rounded to nearest integer > + * @dividend: unsigned 64bit dividend > + * @divisor: unsigned 32bit divisor > + * > + * Divide unsigned 64bit dividend by unsigned 32bit divisor > + * and round to closest integer. > + * > + * Return: dividend / divisor rounded to nearest integer > + */ > +#define DIV_U64_ROUND_CLOSEST(dividend, divisor) \ > + ({ u32 _tmp = (divisor); div_u64((u64)(dividend) + _tmp / 2, _tmp); }) Given "dividend" should already be an unsigned 64-bit value, I don't think the cast to "u64" is needed. Similar macros in this file also don't have the cast. > + > /* > * DIV_S64_ROUND_CLOSEST - signed 64bit divide with 32bit divisor rounded to nearest integer > * @dividend: signed 64bit dividend With the above nit fixed: Reviewed-by: Geert Uytterhoeven Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds