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: 12752319 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 83F24C433F5 for ; Sat, 19 Feb 2022 15:29:52 +0000 (UTC) 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=tKE9Vy8E49qPn4xo6WCo3qXOlavDOublUEaa2YLArG4=; b=Qu+1sziikWNbo1 r/kg4f/TXXLYEEoql7TkZd8fBAoQ+GROGAjGwqzLJd3KjcEUKOtttPDhaXNi+/isWYKN+T1XB8PQW Fgw+LxZtKgfZ0gQu2DggZtRkY0jc7OhuAnsDWQM1hQa8bkbB7eHzA6Y9vkrGFi8XWlTEH0k1hT0G0 m4i1qNz+AZgG74YsxD7tVgEfYiPfszp8iG189GyirlGEHl8sWIKynqSF1103NnnCs2wPXZJtK6m8X bWQJcm8VIAH8TLV8v1aw0vc8W8yXp0dS2kE+DfEP6JgeGmKk8PczwqC/cbZo67GG9caEcnofB3RYH cj7DZ+OARPgRprwMS2Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nLRf7-00HA8x-Rz; Sat, 19 Feb 2022 15:28:42 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nLReu-00HA3z-L9 for linux-arm-kernel@lists.infradead.org; Sat, 19 Feb 2022 15:28:30 +0000 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 ams.source.kernel.org (Postfix) with ESMTPS id 48B33B80B38; Sat, 19 Feb 2022 15:28:27 +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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220219_072828_862387_07785733 X-CRM114-Status: GOOD ( 10.30 ) 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 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