From patchwork Thu Sep 30 09:58:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 12527833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6580C433EF for ; Thu, 30 Sep 2021 10:02:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B8A7461507 for ; Thu, 30 Sep 2021 10:02:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B8A7461507 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9Jwp9EAaro4L1TbEITqwjAvfvZOBWETsgeXSvYTHW8M=; b=qmzOxNGKw+pZFf Sq+Xr22yL2s3thw0QvHQRbnNpN76RX4LVbcPh+YAH5NPd5un5ooXgikh71ibZWsPwqM2O7XD0lg/7 e2z9oxFQimv0oHCdOaECYA9ft94yKPEsgu/T2NRoNcw5Yfn63O2phfko3qDVUM1aIFS34LWhyR4b/ 5Gs22VKcuQUSmEH2nwtR/nkFCCgG7RodeSkWwD7lj3Qlh29toK97xZ0ZjFbXeXoK1CuQ/ZJDWp1ar FXS3EGzPEIDaoI6BqKdGUc+CpTJndIJHdU3KwIC2373VWjLaxh9fYdk9Aqp1KMx4p8s8vqSbWU566 eguXaXIC1oykuMEa9Gag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVsqj-00DgQV-Lj; Thu, 30 Sep 2021 09:59:34 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVsqG-00DgI2-Va for linux-arm-kernel@lists.infradead.org; Thu, 30 Sep 2021 09:59:08 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8B44D617E6; Thu, 30 Sep 2021 09:59:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1632995944; bh=pFht2crJ58fEPAb0efcLhPOBTsC8scTXAQlpfMeAVoo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g3u6vAjExZV/slEx0BljKTqytQT0i1Xc2U1rhiCaKdNtohO5GUJmsDU3AQAifR8Kw wLW6BnhQa+C8Sp2XafdeFqbkhiMOUrvz7Z4a0hHht7jbM2eV/fh00wngRkPESSFBZ2 RIZgx+DHPKCQjs1gSHejAjYZSX0Ucv5jI4khI8C+mnaOYU3EoM8sQl0j8VxzHqUuol QD/KorZ0Srs6z3IfdMrR46BdSqNJVeATJ0idVx4Oy3rP7e1JK/4RPzMt37+hEsVScA gaOdfRrxDDgHZHUq04cCMyPL5gDWh6p7Sgjij1M38bPsfDY76IgIuSxNuQfJac6niX WQ9JNWpWA8hlQ== Received: by pali.im (Postfix) id AEEF0169E; Thu, 30 Sep 2021 11:59:02 +0200 (CEST) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: Michael Turquette , Stephen Boyd , Rob Herring , Greg Kroah-Hartman Cc: Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Vladimir Vid , =?utf-8?q?Marek_Beh=C3=BAn?= , linux-clk@vger.kernel.org, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org Subject: [PATCH v7 1/6] math64: New DIV_U64_ROUND_CLOSEST helper Date: Thu, 30 Sep 2021 11:58:33 +0200 Message-Id: <20210930095838.28145-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210930095838.28145-1-pali@kernel.org> References: <20210930095838.28145-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210930_025905_066472_91049378 X-CRM114-Status: UNSURE ( 8.82 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- include/linux/math64.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/math64.h b/include/linux/math64.h index 2928f03d6d46..a14f40de1dca 100644 --- a/include/linux/math64.h +++ b/include/linux/math64.h @@ -300,6 +300,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); }) + /* * DIV_S64_ROUND_CLOSEST - signed 64bit divide with 32bit divisor rounded to nearest integer * @dividend: signed 64bit dividend