From patchwork Mon Nov 2 22:33:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 55916 Delivered-To: patch@linaro.org Received: by 10.112.61.134 with SMTP id p6csp1525314lbr; Mon, 2 Nov 2015 14:49:01 -0800 (PST) X-Received: by 10.66.121.110 with SMTP id lj14mr29436659pab.61.1446504540531; Mon, 02 Nov 2015 14:49:00 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cv1si38134031pbb.202.2015.11.02.14.49.00; Mon, 02 Nov 2015 14:49:00 -0800 (PST) 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; 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 S1754008AbbKBWsy (ORCPT + 28 others); Mon, 2 Nov 2015 17:48:54 -0500 Received: from relais.videotron.ca ([24.201.245.36]:41140 "EHLO relais.videotron.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753529AbbKBWsq (ORCPT ); Mon, 2 Nov 2015 17:48:46 -0500 Content-transfer-encoding: 7BIT Received: from yoda.home ([96.23.157.65]) by VL-VM-MR007.ip.videotron.ca (Oracle Communications Messaging Exchange Server 7u4-22.01 64bit (built Apr 21 2011)) with ESMTP id <0NX700ARRLBYRU40@VL-VM-MR007.ip.videotron.ca>; Mon, 02 Nov 2015 17:33:36 -0500 (EST) Received: from xanadu.home (xanadu.home [192.168.2.2]) by yoda.home (Postfix) with ESMTP id 1B0F42DA04BA; Mon, 02 Nov 2015 17:33:34 -0500 (EST) From: Nicolas Pitre To: Alexey Brodkin , =?UTF-8?q?M=C3=A5ns=20Rullg=C3=A5rd?= Cc: Arnd Bergmann , rmk+kernel@arm.linux.org.uk, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] div64.h: optimize do_div() for power-of-two constant divisors Date: Mon, 02 Nov 2015 17:33:26 -0500 Message-id: <1446503610-6942-2-git-send-email-nicolas.pitre@linaro.org> X-Mailer: git-send-email 2.4.3 In-reply-to: <1446503610-6942-1-git-send-email-nicolas.pitre@linaro.org> References: <1446503610-6942-1-git-send-email-nicolas.pitre@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 32-bit targets, gcc is able to do the right thing with a constant divisor that happens to be a power of two i.e. it turns the division into a right shift inline. Signed-off-by: Nicolas Pitre --- include/asm-generic/div64.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/include/asm-generic/div64.h b/include/asm-generic/div64.h index 8f4e319334..47aa1e2134 100644 --- a/include/asm-generic/div64.h +++ b/include/asm-generic/div64.h @@ -41,7 +41,12 @@ extern uint32_t __div64_32(uint64_t *dividend, uint32_t divisor); uint32_t __base = (base); \ uint32_t __rem; \ (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \ - if (likely(((n) >> 32) == 0)) { \ + if (__builtin_constant_p(__base) && \ + (__base & (__base - 1)) == 0) { \ + /* constant power of 2: gcc is fine */ \ + __rem = (n) & (__base - 1); \ + (n) /= __base; \ + } else if (likely(((n) >> 32) == 0)) { \ __rem = (uint32_t)(n) % __base; \ (n) = (uint32_t)(n) / __base; \ } else \