From: James Cloos <cloos@jhcloos.com>
To: linux-kernel@vger.kernel.org
Cc: "Linux-MIPS" <linux-mips@linux-mips.org>,
Florian Fainelli <florian@openwrt.org>,
Andrew Morton <akpm@linux-foundation.org>,
Takashi Iwai <tiwai@suse.de>, Ralf Baechle <ralf@linux-mips.org>
Subject: Re: [PATCH 1/8] add lib/gcd.c
Date: Sat, 13 Jun 2009 08:16:04 -0400 [thread overview]
Message-ID: <m38wjwz5ur.fsf@lugabout.jhcloos.org> (raw)
In-Reply-To: <200906041615.10467.florian@openwrt.org> (Florian Fainelli's message of "Thu, 4 Jun 2009 16:15:07 +0200")
>>>>> "Florian" == Florian Fainelli <florian@openwrt.org> writes:
Florian> This patch adds lib/gcd.c which contains a greatest
Florian> common divider implementation taken from
Florian> sound/core/pcm_timer.c
Would the binary gcd algorithm not be a better fit for the kernel?
It avoids division, using only shifts and subtraction:
unsigned long gcd (unsigned long a, unsigned long b) {
unsigned int shift;
unsigned long d;
if (a == 0 || b == 0)
return a | b;
for (shift = 0; ((a | b) & 1) == 0; ++shift) {
a >>= 1;
b >>= 1;
}
while ((a & 1) == 0)
a >>= 1;
do {
while ((b & 1) == 0)
b >>= 1;
if (a < b) {
b -= a;
} else {
d = a - b;
a = b; b = d;
}
b >>= 1;
} while (b != 0);
return a << shift;
}
-JimC
--
James Cloos <cloos@jhcloos.com> OpenPGP: 1024D/ED7DAEA6
next prev parent reply other threads:[~2009-06-13 12:17 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-04 14:15 [PATCH 1/8] add lib/gcd.c Florian Fainelli
2009-06-04 14:21 ` Sergei Shtylyov
2009-06-04 14:31 ` Sergei Shtylyov
2009-06-04 14:39 ` Florian Fainelli
2009-06-04 15:57 ` Joe Perches
2009-06-04 19:03 ` Andrew Morton
2009-06-04 22:41 ` Andrew Morton
2009-06-13 12:16 ` James Cloos [this message]
2009-06-13 15:28 ` Alan Cox
2009-06-13 15:50 ` James Cloos
2009-06-13 19:54 ` James Cloos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m38wjwz5ur.fsf@lugabout.jhcloos.org \
--to=cloos@jhcloos.com \
--cc=akpm@linux-foundation.org \
--cc=florian@openwrt.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=ralf@linux-mips.org \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).