From patchwork Sat Feb 19 15:28:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 544379 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CFA36C433F5 for ; Sat, 19 Feb 2022 15:28:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242519AbiBSP2q (ORCPT ); Sat, 19 Feb 2022 10:28:46 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242517AbiBSP2p (ORCPT ); Sat, 19 Feb 2022 10:28:45 -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 DBA455D1B4; Sat, 19 Feb 2022 07:28:26 -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 78B1160B47; Sat, 19 Feb 2022 15:28:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04E29C340F1; Sat, 19 Feb 2022 15:28:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1645284505; bh=vUH/5R6TeSCnTi3AJJW3p5EjrFJ4SqZT0J7ODzHJu9g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QXoTRyhqCw7q2oNqk0AzPctSLoPBI730vd0lzrpHqtkMMTxAdjHX+zvwhalzf01w9 4+A73snev4Z2tFNsA/M3bjPakA3t5ghH1zryud+HltQyba3u4mCku0Lz3nV3COQCmL M/C96vNw/4MtJFC2/967XfHoUitqRMrou/A26CocD5jsYNfVAosywnqImpGW7A2klE heYbGLZmma+OPyMZCjlnQmdJeX/5WyOSHIsDAbjoX9ccI7cesSXWkbJ3li/zjfy2Ty ZEe1wjLRIGQV/YbMAel/zWmJTHfMFu0HRYWS9q+lZTgCIsvZSvnQlx3W6mJ1WoSCRB ZroNOENQwBEug== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Greg Kroah-Hartman , Stephen Boyd Cc: Gregory Clement , =?utf-8?q?Pali_Roh=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_Beh=C3=BAn?= Subject: [PATCH v9 1/6] math64: New DIV_U64_ROUND_CLOSEST helper Date: Sat, 19 Feb 2022 16:28:13 +0100 Message-Id: <20220219152818.4319-2-kabel@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220219152818.4319-1-kabel@kernel.org> References: <20220219152818.4319-1-kabel@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-serial@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 --- 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