Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp4001433pxb; Fri, 11 Feb 2022 12:38:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJy++iQmex5gSbVuMXpiMfX/V4bmZO9WcqRsUWBY2YW9KPeCR/VvoUZ927s4wGLrsG6pRbeP X-Received: by 2002:a17:90b:3b52:: with SMTP id ot18mr2223090pjb.34.1644611927537; Fri, 11 Feb 2022 12:38:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644611927; cv=none; d=google.com; s=arc-20160816; b=Lcx2tzXqxRxxaizzAC7m6yYI0UYaGi/O0vo4jmKdg4WWskBSAfX7K7XheiDM+sXcOF YYnbAEj55Y+H3UDsEKFwYlBS75FJkt9fbFYe9LQKWnEb2mWu12GEbwYM6pohCDr5M12U MtwFM5e8DxdavD2nsUoYpZQbHzOqjSQYWIYneJKhonhPNEILj8uMBIzDjdUBJ6tJ3gDF Ypr7UagPcGtb6Qvu31k+tH+ZFdKckUOe1SikEKSbcwX9TJeuShuuX1iwEh37wZlPFBHG sozXuxzigPvBwGL4/AIXOaxILE0nzH5o713P7TYT1P28IRyR4ICqcCNHXCkHze80C00q 7mwQ== 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=WkdOPXep2zug4BeJcT6GM/nnRZcBXeVNcITLDylLkJk=; b=JRrIOMhVhPZqw2O0Cd2EcEPosbKlQ9JqFENXCqF8bPGOq9YM9u/SyXoxxJgsTyJHIm 5M8KB2tnMeubBqir0eIMZTq/0x53eNkZ1b021Nuazi774VnxAuBBhc+s9zNlcKuUetBX IPuZPEdra3APAinVYfLOzJezmR/oANGktBNkalwdPokZdgL6Z3dClYEkZ/VzG21u0YCp AnMGcpHpcsuypvMuv8R/PmMcAHnQkB8LWsXncQ9UFbD5MpYACSW1gR4VnEM8itD0fjDg whwgLZ1/EU8QOo9+ryz48TeXs1cwX7BwlmWzdxFHzab1BQ+nnuobmAoEFC5YdGQsVHU6 F+fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wj+9Wb+C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j63si1255586pge.499.2022.02.11.12.38.23; Fri, 11 Feb 2022 12:38:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Wj+9Wb+C; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S1346202AbiBKTMv (ORCPT + 99 others); Fri, 11 Feb 2022 14:12:51 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343767AbiBKTMr (ORCPT ); Fri, 11 Feb 2022 14:12:47 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DC85CE7; Fri, 11 Feb 2022 11:12:46 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id CCD0E61F35; Fri, 11 Feb 2022 19:12:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C94BC340E9; Fri, 11 Feb 2022 19:12:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1644606765; bh=/kRr5IqKtgAB6PuFxk7QjfVSXaEzJJ5qpIyJSbD3iEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wj+9Wb+CZtHszzgJ+ck+1SkW0c4aQ8Pox7l5ywg2DmQlaPfXOUTSKbuMBNIcTXCRo W8KQvmDXlQO7fHSBE9l2XXC1MWvVBjZ4c21RMHWnretX0Q71qtKTQbL7szMxgUMzNQ 4gUYfcwuMiu6LFY/ZGMS529OY9aUnc0FR5Gn7B25FywTlLAkzQzu6Nca6+jt5YUiOZ DER+Sat5I1j9eecxwZL1cu+JHVn9s13aY8tTHZeZ2dXAg9lZwdJCAyi5Vbbyu0o4Kt CemlHDyDk4afLe7Hfn1s6Y+Mmr6B/F3rEQE9HiP19pYeRw53iyUPRqAhw67vofN6aI sV6GCYN9loMew== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Stephen Boyd , Michael Turquette , Greg Kroah-Hartman , Gregory Clement Cc: =?UTF-8?q?Pali=20Roh=C3=A1r?= , linux-clk@vger.kernel.org, linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Marek=20Beh=C3=BAn?= Subject: [PATCH v8 1/6] math64: New DIV_U64_ROUND_CLOSEST helper Date: Fri, 11 Feb 2022 20:12:33 +0100 Message-Id: <20220211191238.2142-2-kabel@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220211191238.2142-1-kabel@kernel.org> References: <20220211191238.2142-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pali Rohár 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 Reviewed-by: Marek Behún Signed-off-by: Marek Behún --- Changes since v7: - added Marek's Reviewed-by tag --- 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.34.1