Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933370AbbBBTNs (ORCPT ); Mon, 2 Feb 2015 14:13:48 -0500 Received: from mail-ig0-f176.google.com ([209.85.213.176]:44042 "EHLO mail-ig0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933206AbbBBTNp (ORCPT ); Mon, 2 Feb 2015 14:13:45 -0500 MIME-Version: 1.0 In-Reply-To: References: <1422897162-111998-1-git-send-email-aksgarg1989@gmail.com> Date: Mon, 2 Feb 2015 11:13:44 -0800 X-Google-Sender-Auth: mb_Cm4cq9eoopHtUtywqV7aW4dE Message-ID: Subject: Re: [PATCH] lib/int_sqrt.c: Optimize square root function From: Linus Torvalds To: Anshul Garg , Davidlohr Bueso Cc: Linux Kernel Mailing List , anshul.g@samsung.com Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1326 Lines: 36 On Mon, Feb 2, 2015 at 11:00 AM, Linus Torvalds wrote: > > (I'm also not entirely sure what uses int_sqrt() that ends up being so > performance-critical, so it would be good to document that too, since > that probably also matters for the "what's the normal argument range" > question..) ... it's also not entirely clear that we need a whole new loop. We might just instead start off with a better guess for 'm' using some calculation that might be doable with a single conditional move instruction instead of a loop. Because I suspect that the inevitable branch misprediction of a new loop is likely as expensive as a few iterations through the core one. IOW, instead of m = 1UL << (BITS_PER_LONG - 2); perhaps something like m = 1UL << (BITS_PER_LONG/2- 2); if (m < x) m <<= BITS_PER_LONG/2; (assuming gcc can change that code into a "cmov") might cut down the "lots of empty loops" case in half for small values of 'x'. There's probably some other better cheap initial guess value estimator. Linus -- 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/