From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751739AbbJ2Heb (ORCPT ); Thu, 29 Oct 2015 03:34:31 -0400 Received: from smtprelay4.synopsys.com ([198.182.47.9]:55392 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750916AbbJ2He3 (ORCPT ); Thu, 29 Oct 2015 03:34:29 -0400 From: Alexey Brodkin To: "nicolas.pitre@linaro.org" CC: "rmk+kernel@arm.linux.org.uk" , "linux-kernel@vger.kernel.org" , "Vineet.Gupta1@synopsys.com" , "shemminger@linux-foundation.org" , "mingo@elte.hu" , "linux-snps-arc@lists.infradead.org" , "davem@davemloft.net" Subject: Re: [PATCH] __div64_32: implement division by multiplication for 32-bit arches Thread-Topic: [PATCH] __div64_32: implement division by multiplication for 32-bit arches Thread-Index: AQHREdKqJ9hBuINsYEu79ImC2YEdpZ6BfXmAgACGkwA= Date: Thu, 29 Oct 2015 07:34:23 +0000 Message-ID: <1446104062.2584.8.camel@synopsys.com> References: <1446072455-16074-1-git-send-email-abrodkin@synopsys.com> In-Reply-To: Accept-Language: en-US, ru-RU Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.225.15.89] Content-Type: text/plain; charset="utf-8" Content-ID: MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id t9T7YhD9012842 Hi Nicolas, On Wed, 2015-10-28 at 19:32 -0400, Nicolas Pitre wrote: > On Thu, 29 Oct 2015, Alexey Brodkin wrote: > > > Fortunately we already have much better __div64_32() for 32-bit ARM. > > There in case of division by constant preprocessor calculates so-called > > "magic number" which is later used in multiplications instead of divisions. > > It's not magic, it is science. :-) Indeed, but I was under impression that's how people call that value in that particular case. So for me it looks appropriate here. > > It's really nice and very optimal but obviously works only for ARM > > because ARM assembly is involved. > > > > Now why don't we extend the same approach to all other 32-bit arches > > with multiplication part implemented in pure C. With good compiler > > resulting assembly will be quite close to manually written assembly. > > You appear to have left out optimizations where there is no overflow to > carry. That, too, can be determined at compile time. That might be the case - let me look at that a bit more. But that was not the biggest problem. I actually wanted to send it as RFC but due to last minute change I made "git pathc-format -1" and forgot to change topic from PATCH to RFC. > > But there's at least 1 problem which I don't know how to solve. > > Preprocessor magic only happens if __div64_32() is inlined (that's > > obvious - preprocessor has to know if divider is constant or not). > > > > But __div64_32() is already marked as weak function (which in its turn > > is required to allow some architectures to provide its own optimal > > implementations). I.e. addition of "inline" for __div64_32() is not an > > option. > > You can't inline __div64_32(). It should remain as is and used only for > the slow path. > > For the constant based optimization to work, you need to modify do_div() > in include/asm-generic/div64.h directly. I thought about that but if I replace existing implementation of do_div() with proposed here some arches like SH and MIPS won't be able to use their own __div64_32() in do_div() any longer. So how to deal with that then? > > So I do want to hear opinions on how to proceed with that patch. > > Indeed there's the simplest solution - use this implementation only in > > my architecture of preference (read ARC) but IMHO this change may > > benefit other architectures as well. > > > > Signed-off-by: Alexey Brodkin > > Cc: linux-snps-arc@lists.infradead.org > > Cc: Vineet Gupta > > Cc: Ingo Molnar > > Cc: Stephen Hemminger > > Cc: David S. Miller > > Cc: Nicolas Pitre > > This email address has been unused for the last 7 years. Please update > your reference. My bad - I blindly took that email from your prehistoric patch "[ARM] 3611/4: optimize do_div() when divisor is constant". -Alexey{.n++%ݶw{.n+{G{ayʇڙ,jfhz_(階ݢj"mG?&~iOzv^m ?I