From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 9EF03C43461 for ; Fri, 11 Sep 2020 21:53:19 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 47ADC22207 for ; Fri, 11 Sep 2020 21:53:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="zJOxrniE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47ADC22207 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WPiXiACk2oqyk6sdtv4BQmssV7kuSHzf5B/JSRGYFiQ=; b=zJOxrniEE++pL5sWfbX1hX0c3 Lf8uWr7Q2SGUEubYa9t0nd1ygXCMu4d3eRwlpFhfJVqp1cJkG/O44F9U4Q6Y7Cj5hF9HDenxwmJNp tNQzwRkZOOW0wLL5kNtIDQdxVtLq0n9347UkUUdbSp+ArERhM+h6lmBOeTDvine0cNhC3dI0c7bZ7 Rc15kLsN4liS5cNDQgBwgv/x5oFmu1gvgGsMjv1asTKxycTBLZmWwSvRp4fYciPUHLdR7WK125uv2 41k+tR4+uOnuZMCzNRIvYt6SayWqJPZrs9rmf6fXd36n/AhurvHsfXogNLx2LTOb0ukVC6ojaJLcw mlvYERfEQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGqxK-0003xw-NH; Fri, 11 Sep 2020 21:51:42 +0000 Received: from mail-io1-f65.google.com ([209.85.166.65]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kGqx5-0003rg-Ft for linux-arm-kernel@lists.infradead.org; Fri, 11 Sep 2020 21:51:30 +0000 Received: by mail-io1-f65.google.com with SMTP id m17so12665265ioo.1 for ; Fri, 11 Sep 2020 14:51:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vUUj1yA5C8gIyhmtCGBnAf4j9JtfhjGcWKZGvC9mD28=; b=DlMPFFfsnPNAoOHLVvHuDUjVUo1trsCtOZXFVBaqKlWMDKmxWrfouqDe7YlFcJDP57 srqvmY/n/J4FIPvYiktK6EclxSnYSuIZdp8eSwOr13ftcSR9P2xu/VN9tklOUG4unTGl QJvhAGosmF9v9GCg+UPapBCWgtjYk09oDCzFsvcIe7TK30gZOLM4mQGGQlJEZ0VJKfoC qf9Vbt5OZSfLpJIUxQf+QHHAyWU0953AKRopO9wflerCiH0+ERCbaV8XmW/bf/EtICih FGnTVXImjQLXbUzBoWgwspgJ/AaS748Q1peUo9C6SIF3/p4tXPAjrHJYDCcmV+X5o37H SZMA== X-Gm-Message-State: AOAM533ydwKrfpXSYHxa74RI735tD83biwL1SGEXMFeIus3jaIFRwLj6 ovEJ2hy0RFKDERbn/xc1tA== X-Google-Smtp-Source: ABdhPJx7DKaHLDj9Hlp1rbhOIcjYpaUy+dpBE1m+gw8Ux+APxrX75i0BhdUAVB/ATjAoyp+cEZKKjg== X-Received: by 2002:a5e:c70b:: with SMTP id f11mr3517630iop.140.1599861086588; Fri, 11 Sep 2020 14:51:26 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.251]) by smtp.googlemail.com with ESMTPSA id a20sm1927966ilq.57.2020.09.11.14.51.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Sep 2020 14:51:26 -0700 (PDT) From: Rob Herring To: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa Subject: [PATCH v3 04/10] tools/include: Add an initial math64.h Date: Fri, 11 Sep 2020 15:51:12 -0600 Message-Id: <20200911215118.2887710-5-robh@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200911215118.2887710-1-robh@kernel.org> References: <20200911215118.2887710-1-robh@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200911_175127_581639_20340997 X-CRM114-Status: GOOD ( 17.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Ian Rogers , Alexander Shishkin , linux-kernel@vger.kernel.org, honnappa.nagarahalli@arm.com, Raphael Gault , Jonathan Cameron , Namhyung Kim , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add an initial math64.h similar to linux/math64.h with functions mul_u64_u64_div64() and mul_u64_u32_shr(). This isn't a direct copy of include/linux/math64.h as that doesn't define mul_u64_u64_div64(). Implementation was written by Peter Zilkstra based on linux/math64.h and div64.h[1]. The original implementation was not optimal on arm64 as __int128 division is not optimal with a call out to __udivti3, so I dropped the __int128 variant of mul_u64_u64_div64(). [1] https://lore.kernel.org/lkml/20200322101848.GF2452@worktop.programming.kicks-ass.net/ Cc: Peter Zijlstra Signed-off-by: Rob Herring --- tools/include/linux/math64.h | 75 ++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tools/include/linux/math64.h diff --git a/tools/include/linux/math64.h b/tools/include/linux/math64.h new file mode 100644 index 000000000000..4ad45d5943dc --- /dev/null +++ b/tools/include/linux/math64.h @@ -0,0 +1,75 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _LINUX_MATH64_H +#define _LINUX_MATH64_H + +#include + +#ifdef __x86_64__ +static inline u64 mul_u64_u64_div64(u64 a, u64 b, u64 c) +{ + u64 q; + + asm ("mulq %2; divq %3" : "=a" (q) + : "a" (a), "rm" (b), "rm" (c) + : "rdx"); + + return q; +} +#define mul_u64_u64_div64 mul_u64_u64_div64 +#endif + +#ifdef __SIZEOF_INT128__ +static inline u64 mul_u64_u32_shr(u64 a, u32 b, unsigned int shift) +{ + return (u64)(((unsigned __int128)a * b) >> shift); +} + +#else + +#ifdef __i386__ +static inline u64 mul_u32_u32(u32 a, u32 b) +{ + u32 high, low; + + asm ("mull %[b]" : "=a" (low), "=d" (high) + : [a] "a" (a), [b] "rm" (b) ); + + return low | ((u64)high) << 32; +} +#else +static inline u64 mul_u32_u32(u32 a, u32 b) +{ + return (u64)a * b; +} +#endif + +static inline u64 mul_u64_u32_shr(u64 a, u32 b, unsigned int shift) +{ + u32 ah, al; + u64 ret; + + al = a; + ah = a >> 32; + + ret = mul_u32_u32(al, b) >> shift; + if (ah) + ret += mul_u32_u32(ah, b) << (32 - shift); + + return ret; +} + +#endif /* __SIZEOF_INT128__ */ + +#ifndef mul_u64_u64_div64 +static inline u64 mul_u64_u64_div64(u64 a, u64 b, u64 c) +{ + u64 quot, rem; + + quot = a / c; + rem = a % c; + + return quot * b + (rem * b) / c; +} +#endif + +#endif /* _LINUX_MATH64_H */ -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel