Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp142293pxb; Thu, 30 Sep 2021 03:00:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTpvaw69myCn/SjhqK8YgCxkEs6iUYuwDdMUZdrMUY96IBqTIyxr8AGERkhSckO3HTz7wi X-Received: by 2002:a63:4b4c:: with SMTP id k12mr4225155pgl.172.1632996053511; Thu, 30 Sep 2021 03:00:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632996053; cv=none; d=google.com; s=arc-20160816; b=gt+Qn81ANY+hGiYI+espUvpKHprZq2VevvFzvpHoB8rJlgqL1LWcMrE4qZGYI+0xyj H8l1cDlcy5QhzahRnZTPRG+s1SGbjfP5DfJC5swSD9YnPuLIboO/ZlzCZ4jfw2l2gFac ulhGhnaFm5CkaKx4bTu7XyuqnN9dDt0YweG9UaowaElPQ+pDWYtjiO20pIfPsE7cGMg/ aHWVWv1qKjBLg7D6w8N7LbveMkpkJqhQQxBD62NVpz2fnf9MbEq+JUsdAaPYxWlmbp7j 06Gl5sXEg2rBNboNzb68LiAQX7YdDncy+CKjd4JJxLebtZWu9vquVKt20eQMRRpqyM/d jP5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=0mR4eYO3f86XlHSnbvu01Te2dRWDS2zIOc2L3MFmYxE=; b=g5G45DrnB86qIpVi/h11sHePetdyHWYVUbf4DVEWqTeUUDFtkN3ITOqhOHOoqs4tUS zprthgXYqEDQQAe/rP7fzKHo+Ejzl0GslaVFeexYJkiIi2tLSMPyzoFx2kDhxv0Yn/SG 4PhOWpUv2tYx4HU34TFR3rWP7VerQuB9u9UO9vWuWrRSGq4u+1IeCp/FNlTE7VA6TVEv 43qWOZQjHtDVpQToCufJLqx3KnIOGjTmhs75yIurF+OFGImY46V6V4YdavFaZBiQdDxX O8wu5vnR1shRnW0QpiPC9xl3sG7smMvg+wJ9QjzS6WZD6n9GedwsPkbLhppmQVoXTrwE iFhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=g3u6vAjE; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m6si3945666plx.221.2021.09.30.03.00.10; Thu, 30 Sep 2021 03:00:53 -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=@kernel.org header.s=k20201202 header.b=g3u6vAjE; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349662AbhI3KAw (ORCPT + 99 others); Thu, 30 Sep 2021 06:00:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:60522 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349618AbhI3KAr (ORCPT ); Thu, 30 Sep 2021 06:00:47 -0400 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=20Roh=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=20Beh=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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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 -- 2.20.1