From: Andrew Morton <akpm@linux-foundation.org>
To: Florian Fainelli <florian@openwrt.org>
Cc: linux-kernel@vger.kernel.org, Takashi Iwai <tiwai@suse.de>,
linux-mips@linux-mips.org, Ralf Baechle <ralf@linux-mips.org>,
Ingo Molnar <mingo@elte.hu>
Subject: Re: [PATCH 1/9] kernel: export sound/core/pcm_timer.c gcd implementation
Date: Tue, 2 Jun 2009 00:26:16 -0700 [thread overview]
Message-ID: <20090602002616.d5707d6b.akpm@linux-foundation.org> (raw)
In-Reply-To: <200906020919.25162.florian@openwrt.org>
On Tue, 2 Jun 2009 09:19:22 +0200 Florian Fainelli <florian@openwrt.org> wrote:
> Le Tuesday 02 June 2009 06:50:34 Andrew Morton, vous avez __crit__:
> > On Mon, 1 Jun 2009 13:57:09 +0200 Florian Fainelli <florian@openwrt.org>
> wrote:
> > > This patch exports the gcd implementation from
> > > sound/core/pcm_timer.c into include/linux/kernel.h.
> > > AR7 uses it in its clock routines.
> > >
> > > ...
> > >
> > > diff --git a/include/linux/kernel.h b/include/linux/kernel.h
> > > index 883cd44..878a27a 100644
> > > --- a/include/linux/kernel.h
> > > +++ b/include/linux/kernel.h
> > > @@ -147,6 +147,22 @@ extern int _cond_resched(void);
> > > (__x < 0) ? -__x : __x; \
> > > })
> > >
> > > +/* Greatest common divisor */
> > > +static inline unsigned long gcd(unsigned long a, unsigned long b)
> > > +{
> > > + unsigned long r;
> > > + if (a < b) {
> > > + r = a;
> > > + a = b;
> > > + b = r;
> > > + }
> > > + while ((r = a % b) != 0) {
> > > + a = b;
> > > + b = r;
> > > + }
> > > + return b;
> > > +}
> >
> > a) the name's a bit sucky. Is there some convention for this name?
>
> We might want something better like greatest_common_divisor which is a bit
> more self-explanatory ?
Well, if gcd() is a commonly used name then let's use that. I don't
personally recall seeing it used but that doesn't mean much.
> >
> > b) It looks too large to be inlined. lib/gdc.c?
>
> And its users select it in order not to increase the size of kernel.h, sounds
> good.
>
> >
> > b) there's an implementation of gcd() in
> > net/netfilter/ipvs/ip_vs_wrr.c. I expect that this patch broke the
> > build.
>
> I did forget about this. That gcd implementation only treats the a > b case.
>
> What do you prefer, each user keeps its gcd implementation locally or we make
> a lib/gcd.c for it ?
I think lib/gcd.c would be better. Then migrate current code over to
use that.
The problem with offering a generic version is types: will it work
correctly and sensibly for all combinations of signed/unsigned
char/short/int/long/longlong? All but the last, I expect. In which
case that'll be good enough for now.
prev parent reply other threads:[~2009-06-02 7:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-01 11:57 [PATCH 1/9] kernel: export sound/core/pcm_timer.c gcd implementation Florian Fainelli
2009-06-02 4:50 ` Andrew Morton
2009-06-02 7:15 ` Geert Uytterhoeven
2009-06-02 7:19 ` Florian Fainelli
2009-06-02 7:26 ` Andrew Morton [this message]
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=20090602002616.d5707d6b.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=florian@openwrt.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=mingo@elte.hu \
--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