Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932350AbbBBRNT (ORCPT ); Mon, 2 Feb 2015 12:13:19 -0500 Received: from mail-we0-f178.google.com ([74.125.82.178]:38247 "EHLO mail-we0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754452AbbBBRNL (ORCPT ); Mon, 2 Feb 2015 12:13:11 -0500 From: Anshul Garg X-Google-Original-From: Anshul Garg To: linux-kernel@vger.kernel.org Cc: aksgarg1989@gmail.com, anshul.g@samsung.com, torvalds@linux-foundation.org Subject: [PATCH] lib/int_sqrt.c: Optimize square root function Date: Mon, 2 Feb 2015 09:12:42 -0800 Message-Id: <1422897162-111998-1-git-send-email-aksgarg1989@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: X-Antivirus: avast! (VPS 150202-0, 02/02/2015), Outbound message X-Antivirus-Status: Clean Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 966 Lines: 38 From: Anshul Garg Unnecessary instructions are executing even though m is greater than x so added logic to make m less than equal to x before performing these operations. Signed-off-by: Anshul Garg --- lib/int_sqrt.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/int_sqrt.c b/lib/int_sqrt.c index 1ef4cc3..64ae722 100644 --- a/lib/int_sqrt.c +++ b/lib/int_sqrt.c @@ -22,6 +22,9 @@ unsigned long int_sqrt(unsigned long x) return x; m = 1UL << (BITS_PER_LONG - 2); + + while (m > x) + m >>= 2; while (m != 0) { b = y + m; y >>= 1; -- 1.7.9.5 --- This email has been checked for viruses by Avast antivirus software. http://www.avast.com -- 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/