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=-14.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,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 7B2A6C433E6 for ; Fri, 28 Aug 2020 20:58:34 +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 468F92075B for ; Fri, 28 Aug 2020 20:58:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HVaZD3Ng" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 468F92075B 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=IhsYOrRES65qbjAd9wEAjq9jQJF7YezuSu5Su8jf/jk=; b=HVaZD3NgYcS428m8tnhuai/jG g2QJ/4GO2XnQxJWNjD0C92rbEsDbhSg5nTup28Sssje1S04P9uquUKx5f/sSYa7Kg4WQJTl26WAQZ DlE3QaxVkRR7EM8B6urM6bYz1fIHByDeADtADt8KASTLm3gFRTlaTvoKEU2xQDeow4JUsujLQPhx4 DSanYBviBvGuiVk0vTwvP76Gsr8YdBOM9cmPkydzwGpSMpz4yCcvYcgfQT0nbhYZ+WZ7B28zAfJdS K/LWUqRMr9wJTdHWTY+lrm1R8OMfq5WFAyrVR+8sM8rPBiRkHyq1oPGYK6nIF64dHURPYeX5q3z+E /IGprsW7A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBlQh-0007cN-1C; Fri, 28 Aug 2020 20:56:59 +0000 Received: from mail-il1-f193.google.com ([209.85.166.193]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBlQB-0007PH-O5 for linux-arm-kernel@lists.infradead.org; Fri, 28 Aug 2020 20:56:29 +0000 Received: by mail-il1-f193.google.com with SMTP id j9so1806580ilc.11 for ; Fri, 28 Aug 2020 13:56: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=Mv5bR3+D06zbxqvFs+zuZPo2cV/Tfy8G7nPGXO/hjAU=; b=loHSG/5i4Y1jsp2mx3pbPe+ClxTa3D0o1eaPZP7Y4/gZmyA0RvvpFeRBQlVO5LtKel gzfnA/KYYGYJ7s2FlhkZrFwiqOK7K3MLXJz/o2Hq8/jEOAWvmLqj01+4oUDfuEfd5Rh8 ylxwNkU+C5yF96dZBylskU3h0DJpF5sdRR3x71IV/hI9bQsqz2f+nMsmSsM5qA792Q7E 7kJx7sjFK7nG8Fk8GPOxEX8KXRh11WqrGuHjY03dslnsBxQ5ZRZ5MiORrWd7YKqI1q8n IrV5M24oQKBbiQB269qO8txKp7YTP6FHD4ylmYyhQKm2sh4RCV2IgdfeygWOS/g2w1jh I/+g== X-Gm-Message-State: AOAM533htH+6YWD+mcm9YlJLoJgLW+oWq+jqKPtxGPx47LbWLG3nClSo jd6VraSKuIEk4KCJpmyEkw== X-Google-Smtp-Source: ABdhPJyxOG80OGdnAhzUR9EE/kBXC0gtLzjMiKCfzG/7ihXt64wtyAdyn2CfQE8oPVG2Xhc9SzNmbQ== X-Received: by 2002:a92:a1c5:: with SMTP id b66mr596524ill.71.1598648186927; Fri, 28 Aug 2020 13:56:26 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.249]) by smtp.googlemail.com with ESMTPSA id l203sm147089ioa.31.2020.08.28.13.56.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Aug 2020 13:56:26 -0700 (PDT) From: Rob Herring To: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa Subject: [PATCH v2 4/9] tools/include: Add an initial math64.h Date: Fri, 28 Aug 2020 14:56:09 -0600 Message-Id: <20200828205614.3391252-5-robh@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200828205614.3391252-1-robh@kernel.org> References: <20200828205614.3391252-1-robh@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200828_165627_980335_DD2E3A95 X-CRM114-Status: GOOD ( 19.17 ) 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 --- I'm not really sure what's desired here. Unlike most of the headers copied into tools/, this one is not a copy from include/linux/. Perhaps adding mul_u64_u64_div64() to include/linux/math64.h first and then copying it over is preferred? Or I could just move this into libperf? 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