From patchwork Mon Aug 2 14:45:24 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: 12414163 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACF51C4338F for ; Mon, 2 Aug 2021 14:49:47 +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 7B97E60F70 for ; Mon, 2 Aug 2021 14:49:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7B97E60F70 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=7jBexU4GCRc7fmPx566fqDD+c3eRk+UvOqAqNnOk6M0=; b=t1jzz3aE4QZsA6 3BPBbFUNDipg1GGe+mnyxnV6v8EQDI/coY1gpyOXLO7RLlVGtTOVikYawIe8f8gxa4jVuI6FL4HzE ZUqQMh+EO8QGn175O8ocdjAu1TEUwpPjlomteQkKRV8QYtDmw/OLHvEDz4JzXOoULE4Po1AnQRM8r rxQ9loQhPTVM/ptaCXnVX8gmRK5yIwa1v/S6gk/ZNE1IgzrhAwu0FXD+BrHZNuTtCsT4LhtX4I7Ho /7yaC2PC04wNGpa+9kB4fmcthNsBGlTEqLXI2Lh5axT9zUHgT+0Ayb0N7diDsGsrC03a4n4YH7Yhr Y2bPu3JifKdN2HxzlaDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mAZD6-00GifN-LV; Mon, 02 Aug 2021 14:46:32 +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 1mAZCU-00GiR2-3f for linux-arm-kernel@lists.infradead.org; Mon, 02 Aug 2021 14:45:55 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9F8BD610CC; Mon, 2 Aug 2021 14:45:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627915553; bh=PS8ZKE3pdHYqi+dT0eaCxhAkUEsUIJhdbc4pPLOtZm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cqRmJUh3f9hWCeQIhrasBN4WECMZzCennJ/lYHYtRjcF16pePAPkiDxixths/RJA5 3fhETvRqLWKwW9LbhrJaRWCz8AWr1FBexMSCMRdaz1mCfRYIbCRb5pK/H6eYQ/HcEC rbavTPsdDEWz2M1opBJAUfbMseIgz0ArETApFGEhTMnEgMTeZnhvroq9kroKEW9gWI CTSlHO0nFeT5RtOTVvbM8dSpq4scc9Ujv6Q7euizeTyENnJQeHs+8EI7UM0YP7WV/D AHOfWHGz8+PR0S0702EAs61c5gGgJP1DJR56Uw8Ncp3kdTi3N2pMG/kMZlbGx6fVhu cyP6Qibg/j4Kw== Received: by pali.im (Postfix) id C3D1BBDD; Mon, 2 Aug 2021 16:45:51 +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 Subject: [PATCH v4 1/6] math64: New DIV_U64_ROUND_CLOSEST helper Date: Mon, 2 Aug 2021 16:45:24 +0200 Message-Id: <20210802144529.1520-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210802144529.1520-1-pali@kernel.org> References: <20210624224909.6350-1-pali@kernel.org> <20210802144529.1520-1-pali@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210802_074554_243217_DE5506E7 X-CRM114-Status: UNSURE ( 8.55 ) 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 66deb1fdc2ef..1cc61d748e1f 100644 --- a/include/linux/math64.h +++ b/include/linux/math64.h @@ -281,6 +281,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