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=-17.2 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 18E5AC433E0 for ; Thu, 14 Jan 2021 02:08:06 +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 D0E15235E4 for ; Thu, 14 Jan 2021 02:08:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D0E15235E4 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=yiCdWK7gQLciVr+Fj/R0jVMJOOY8oTZBlSOdCY3A4Yg=; b=sBmMiTo1mr0FSrXlaBVM4ySvj DvW44slwTe0BflXVQ/EOWAe7/EvNpDv2s7Dwoh7HKr5p9oxDfdi/+czNcuJWh0or+RbTEDqQ9MvfC 3F3oJvNtefEzpnNTvT0q66ApibCBYg5VRRGKGtyYxEgLVuaG+zwPzNtUJOII5c1V7A7am1ImLv5z7 /Zsfx9Ovrb+d6yzAn4LiErcZtV3cuespY45XpqBrq5RAmYEMZ+YZuElXOVquhBLeM6kT07qH0xskr kFhgGPGdg+7FAQgmc7GRUDJMoNkvL0qZ5MeWHHFM/97R5SG7NZ8xt8QSmqbV/ulxJ9XxOGzzsrKYo vIbuzdqvQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzs1q-0001fo-Jp; Thu, 14 Jan 2021 02:06:26 +0000 Received: from mail-ot1-f54.google.com ([209.85.210.54]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kzs1d-0001aD-3a for linux-arm-kernel@lists.infradead.org; Thu, 14 Jan 2021 02:06:15 +0000 Received: by mail-ot1-f54.google.com with SMTP id d20so3907256otl.3 for ; Wed, 13 Jan 2021 18:06:13 -0800 (PST) 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=DjdlDe1r8PWcI8CJTWfGrTFm/qYeuvm3S8MlLSmS6yU=; b=pjuxtVuAq6FJdiSaGAodcnyV3k2/T1bWvM0Q+wafIByEzVyRpNU8NDZvAtwUHIVlJy enIGwarhZE2c1b3lzCBD+59Sdh3t8rbzpIKNV5rgP5PWfL8ZK4eiiiCrFeGHiBaJVjTM igoQHJoAIzfAcIkbWmVtKNDX7n2jmjZpbPowGOKNDqiR4Hn+c3BEHllh1SWuAzgNXcZr ggbXpa75n1Wh81Akm/a126ebzcaeLTGpB9iiPzUemBGcKKxwYITPcnm7P17gP8pWSF9r RiqzqMZunArkTAqvGVo98WrPyHc4jZkzdkWdE6y2Zhpf/LaVkraLjzMMBceBuPxquhdJ zLlQ== X-Gm-Message-State: AOAM531HL1MXKYCSu4ZkF4XDhgs3KgRxEr4l0GV9fngW/92b6iIx5a8T R51l6rrXIGxrIyGKyj9+Cw== X-Google-Smtp-Source: ABdhPJwQpwEW4ekRbw2RIkUs4KFaLnTel80fWDSmHIbhxUS8lcWM4UYb0B7qo8yEkwz0iyCcFotU9Q== X-Received: by 2002:a9d:749a:: with SMTP id t26mr3119716otk.277.1610589972628; Wed, 13 Jan 2021 18:06:12 -0800 (PST) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id x20sm814272oov.33.2021.01.13.18.06.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jan 2021 18:06:11 -0800 (PST) From: Rob Herring To: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa , Mark Rutland Subject: [PATCH v5 3/9] tools/include: Add an initial math64.h Date: Wed, 13 Jan 2021 20:05:59 -0600 Message-Id: <20210114020605.3943992-4-robh@kernel.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210114020605.3943992-1-robh@kernel.org> References: <20210114020605.3943992-1-robh@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210113_210613_233031_CCE9FC8B X-CRM114-Status: GOOD ( 17.20 ) 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: Ian Rogers , Alexander Shishkin , linux-kernel@vger.kernel.org, honnappa.nagarahalli@arm.com, Raphael Gault , Jonathan Cameron , Namhyung Kim , Itaru Kitayama , 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.27.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel