Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2030263ybl; Thu, 29 Aug 2019 02:32:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqzn6iG4q0Bc6mbBBZ+OGDbQAootiGhevDnNdxxAauDhOAtRvI/N55Ge1lR1S5wNxdaMdrRK X-Received: by 2002:a63:2744:: with SMTP id n65mr7338850pgn.277.1567071142248; Thu, 29 Aug 2019 02:32:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567071142; cv=none; d=google.com; s=arc-20160816; b=eWq8IbXjK5tIeVE+iEnpKz9nn2EMGzisDddbkRzq3wk0dy3HDM54PmjXLJIlfGgiQr 2+oQIWbp/CgEWUZMl1TrKSBWqOSevfHWPZTa0afbtVQQQeamnWmvgBndT3lA/cFZEiPF ASYAQ6W/JEC4AFiBpoiAFwQ+MwIsbc5kF6IYglDBYCe7x5v58GurSEbHf7nmWq0AB6mx WcN7zh+qWMLOG0OXxGX8qANSaC/qozKBferOOkqYXbcyQEq42Ulcf/IOxvmAXY0W/XSr MKuiTtkZ7hgzFwosa+WjqOELy0gkT7QK5HWFkV9LsAwv3ag6wGcoMUsZ9uSq7m5te8ex t5jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=rCGISQyK/CqSKT+aR9Rsl5/9L4NcBCG9bnaseeSeY1Y=; b=aXKrc9l7+D2d4IkZnklNmyusT0Ywl1n2gqIhA59anEKW+Bx0opVFzXNnAX9oRwAxjM 7oydtKxySRc12OZ/bwHqOqIGSneNXLwSFh6k8m4z16UyxXSQk0JI5jiDNS+Hz4NmHzKH D7WVjrsioY5BMuekq4dS+xKaDzd0zBozCEIwlhR/sR6UiKsJyb49h6iFHsPzMIXUXIfR +1qgc9S1zRBtLIqNtJMgHonIBBRLeVIbbqZTRdyEO1R+5vi0jQnZTengyGa0O15irg5i CYj8Hi86Rz40FGPVJLu0hh1PjzmcR6H4GWN5ocF5gOTGcWZNcyAy2CU91v9snx1GqjOE vl/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=18iUK6Bi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ck12si1658864pjb.26.2019.08.29.02.32.05; Thu, 29 Aug 2019 02:32:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=18iUK6Bi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726416AbfH2JbC (ORCPT + 99 others); Thu, 29 Aug 2019 05:31:02 -0400 Received: from merlin.infradead.org ([205.233.59.134]:56298 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725776AbfH2JbC (ORCPT ); Thu, 29 Aug 2019 05:31:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=rCGISQyK/CqSKT+aR9Rsl5/9L4NcBCG9bnaseeSeY1Y=; b=18iUK6BiAKQ7aTuYvA36ir/D2 QTVoOmvI3b0nQn49YFDhLADhEXBOsvt2/sEDyBpWqI9XTZRDpAcZNWm6xDqz/kDt+xL/ZoPs8arGm qHKWzieqhODRlc3qWvVa1XAcqN+goAcGqXnih9AhAT7LiQ6PRbz5JccICBNHkVbPU73tSz/xEKe0S SCsmV5DwUDUzg0HfDICOswzc7/8pcH/9LropZKkJKpBnOxZk1RDiYaDAZSojA+Y4tmn+lKrG6CN+l M43KU8hjS2cTUwC/b1d/cqF6KvGbzOprs+iAX+B6x1ri051YontGpJ1sLvump5rKKXsV8wsKfNSlS ZPZ4f0NZw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92 #3 (Red Hat Linux)) id 1i3Gla-0000ms-Sa; Thu, 29 Aug 2019 09:30:55 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 40D11307138; Thu, 29 Aug 2019 11:30:19 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 681352235E598; Thu, 29 Aug 2019 11:30:53 +0200 (CEST) Date: Thu, 29 Aug 2019 11:30:53 +0200 From: Peter Zijlstra To: kan.liang@linux.intel.com Cc: acme@kernel.org, mingo@redhat.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, jolsa@kernel.org, eranian@google.com, alexander.shishkin@linux.intel.com, ak@linux.intel.com, x86@kernel.org Subject: Re: [PATCH] x86/math64: Provide a sane mul_u64_u32_div() implementation for x86_64 Message-ID: <20190829093053.GR2386@hirez.programming.kicks-ass.net> References: <20190826144740.10163-1-kan.liang@linux.intel.com> <20190826144740.10163-4-kan.liang@linux.intel.com> <20190828151921.GD17205@worktop.programming.kicks-ass.net> <20190828161123.GQ2386@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190828161123.GQ2386@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 28, 2019 at 06:11:23PM +0200, Peter Zijlstra wrote: > On Wed, Aug 28, 2019 at 05:19:21PM +0200, Peter Zijlstra wrote: > > On Mon, Aug 26, 2019 at 07:47:35AM -0700, kan.liang@linux.intel.com wrote: > > > > + return mul_u64_u32_div(slots, val, 0xff); > > > > But also; x86_64 seems to lack a sane implementation of that function, > > and it currently compiles into utter crap (it can be 2 instructions). This one actually builds defconfig :-) --- Subject: x86/math64: Provide a sane mul_u64_u32_div() implementation for x86_64 From: Peter Zijlstra Date: Wed Aug 28 17:39:46 CEST 2019 On x86_64 we can do a u64 * u64 -> u128 widening multiply followed by a u128 / u64 -> u64 division to implement a sane version of mul_u64_u32_div(). Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/div64.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h index 20a46150e0a8..9b8cb50768c2 100644 --- a/arch/x86/include/asm/div64.h +++ b/arch/x86/include/asm/div64.h @@ -73,6 +73,19 @@ static inline u64 mul_u32_u32(u32 a, u32 b) #else # include + +static inline u64 mul_u64_u32_div(u64 a, u32 mul, u32 div) +{ + u64 q; + + asm ("mulq %2; divq %3" : "=a" (q) + : "a" (a), "rm" ((u64)mul), "rm" ((u64)div) + : "rdx"); + + return q; +} +#define mul_u64_u32_div mul_u64_u32_div + #endif /* CONFIG_X86_32 */ #endif /* _ASM_X86_DIV64_H */