From patchwork Mon Jun 23 09:43:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 4401121 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 03F63BEEAA for ; Mon, 23 Jun 2014 09:44:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 29015202C8 for ; Mon, 23 Jun 2014 09:44:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 42FB6202B8 for ; Mon, 23 Jun 2014 09:44:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752276AbaFWJoX (ORCPT ); Mon, 23 Jun 2014 05:44:23 -0400 Received: from mail-pb0-f42.google.com ([209.85.160.42]:48816 "EHLO mail-pb0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751859AbaFWJoX (ORCPT ); Mon, 23 Jun 2014 05:44:23 -0400 Received: by mail-pb0-f42.google.com with SMTP id ma3so5652530pbc.15 for ; Mon, 23 Jun 2014 02:44:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VMkMAHUgvI1tEOD2/X1/8+paAqcyuYH/hgvZ0HyxWMA=; b=bVLh7eK1flfYgtxtf2daEhT3jhuqDYiQRsFDCa6ssSyiLzRZHk2fAS4jbHgamDVntK 4kLWzIzfCffeC2NaMMjyAsCdNWBaDb0l5BFtB59FF8dn/BZMpm6w88fTI55kC/nTluL6 3gUii3tjdWD71uG9GgGtBkQDv1ccDpVRIo0WlkrZgDuu/BOjd8pzmR3fpbjs3GXkvOm1 nAkqdiiuEPL+tIMz2y8ZAwSdyNMIfEc/d7ldnt3XruhNrHWxCTqu0pPNbYhtqfbpdsXm Lm6zowrDxx1yogI9wXEr/6Mt02eKTFILJwo0eTnSt2LV33qfWFsawZtZXy/+G0tPN2Q5 k2Kw== X-Received: by 10.66.142.73 with SMTP id ru9mr26935860pab.41.1403516662856; Mon, 23 Jun 2014 02:44:22 -0700 (PDT) Received: from localhost.localdomain ([117.136.8.1]) by mx.google.com with ESMTPSA id no9sm25949264pbc.83.2014.06.23.02.44.14 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 23 Jun 2014 02:44:22 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: dmitry.torokhov@gmail.com, dtor@mail.ru, akpm@linux-foundation.org Cc: linux-input@vger.kernel.org, workgroup.linux@csr.com, Yibo Cai , Barry Song Subject: [PATCH 1/2] lib: int_sqrt: add int64_sqrt routine Date: Mon, 23 Jun 2014 17:43:00 +0800 Message-Id: <1403516581-12560-2-git-send-email-21cnbao@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1403516581-12560-1-git-send-email-21cnbao@gmail.com> References: <1403516581-12560-1-git-send-email-21cnbao@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yibo Cai Get square root of a 64-bit digit on 32bit platforms. CSR SiRFSoC touchscreen driver needs it. Signed-off-by: Yibo Cai Signed-off-by: Barry Song --- include/linux/kernel.h | 1 + lib/int_sqrt.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 4c52907..6e63081 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -418,6 +418,7 @@ struct pid; extern struct pid *session_of_pgrp(struct pid *pgrp); unsigned long int_sqrt(unsigned long); +unsigned long long int64_sqrt(unsigned long long); extern void bust_spinlocks(int yes); extern int oops_in_progress; /* If set, an oops, panic(), BUG() or die() is in progress */ diff --git a/lib/int_sqrt.c b/lib/int_sqrt.c index 1ef4cc3..2aa9fcc 100644 --- a/lib/int_sqrt.c +++ b/lib/int_sqrt.c @@ -36,3 +36,30 @@ unsigned long int_sqrt(unsigned long x) return y; } EXPORT_SYMBOL(int_sqrt); + +/* + * Square root of a 64-bit digit. + * Same as int_sqrt on 64-bit platforms where "long" equals "long long" + */ +unsigned long long int64_sqrt(unsigned long long x) +{ + unsigned long long m = 0, y = 0, b = 0; + + if (x <= 1) + return x; + + m = 1ULL << (BITS_PER_LONG_LONG - 2); + while (m != 0) { + b = y + m; + y >>= 1; + + if (x >= b) { + x -= b; + y += m; + } + m >>= 2; + } + + return y; +} +EXPORT_SYMBOL(int64_sqrt);