Skip to contentSkip to conversation

kernel: export sound/core/pcm_timer.c gcd implementation

PATCH In review Florian Fainelli 3 participants 5 messages Jun 1, 2009 – Jun 2, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/9 kernel: export sound/core/pcm_timer.c gcd implementation

This patch exports the gcd implementation from sound/core/pcm_timer.c into include/linux/kernel.h. AR7 uses it in its clock routines.

---

include/linux/kernel.h +16 -0
index 883cd44..878a27a 100644
@@ -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;
+}
+
 #ifdef CONFIG_PROVE_LOCKING
 void might_fault(void);
 #else
sound/core/pcm_timer.c +1 -16
index ca8068b..e9dbf62 100644
@@ -20,6 +20,7 @@
  */
 
 #include <linux/time.h>
+#include <linux/kernel.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/timer.h>
@@ -28,22 +29,6 @@
  *  Timer functions
  */
 
-/* Greatest common divisor */
-static 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;
-}
-
 void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream)
 {
 	unsigned long rate, mult, fsize, l, post;
#1 lore raw
Quoted 19 lines · On Mon, 1 Jun 2009 13:57:09 +0200 Florian Fainelli <[email protected]> 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.

...

include/linux/kernel.h +5 -0
index 883cd44..878a27a 100644
@@ -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) {

include/linux/kernel.h extern int _cond_resched(void); · line 164

Quoted 10 lines
include/linux/kernel.h +10 -0
+                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?

b) It looks too large to be inlined. lib/gdc.c?

b) there's an implementation of gcd() in net/netfilter/ipvs/ip_vs_wrr.c. I expect that this patch broke the build.

#2 lore raw
Quoted 25 lines · Andrew Morton
Quoted 23 lines · On Mon, 1 Jun 2009 13:57:09 +0200 Florian Fainelli <[email protected]> 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.

...

include/linux/kernel.h +9 -0
index 883cd44..878a27a 100644
@@ -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;
+        }
Quoted 8 lines

include/linux/kernel.h extern int _cond_resched(void); · line 164

Quoted 6 lines
include/linux/kernel.h +6 -0
+        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?

Well, gcd' is a quite common acronym, probably almost as well known as min' and `max'...

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#3 lore raw
In reply to Andrew Morton

Le Tuesday 02 June 2009 06:50:34 Andrew Morton, vous avez écrit :

Quoted 1 line

On Mon, 1 Jun 2009 13:57:09 +0200 Florian Fainelli <[email protected]>

Quoted 23 lines · wrote:
Quoted 23 lines

This patch exports the gcd implementation from sound/core/pcm_timer.c into include/linux/kernel.h. AR7 uses it in its clock routines.

...

include/linux/kernel.h +9 -0
index 883cd44..878a27a 100644
@@ -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;
+        }
Quoted 8 lines

include/linux/kernel.h extern int _cond_resched(void); · line 164

Quoted 6 lines
include/linux/kernel.h +6 -0
+        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 ?

Quoted 2 lines

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.

Quoted 4 lines

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 ?

Thanks

Signature · 4 lines
Best regards, Florian Fainelli
Email : [email protected]
http://openwrt.org
-------------------------------
#4 lore raw
Quoted 35 lines · On Tue, 2 Jun 2009 09:19:22 +0200 Florian Fainelli <[email protected]> wrote:

Le Tuesday 02 June 2009 06:50:34 Andrew Morton, vous avez __crit__:

Quoted 1 line

On Mon, 1 Jun 2009 13:57:09 +0200 Florian Fainelli <[email protected]>

Quoted 23 lines · wrote:
Quoted 23 lines

This patch exports the gcd implementation from sound/core/pcm_timer.c into include/linux/kernel.h. AR7 uses it in its clock routines.

...

include/linux/kernel.h +9 -0
index 883cd44..878a27a 100644
@@ -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;
+        }
Quoted 8 lines

include/linux/kernel.h extern int _cond_resched(void); · line 164

Quoted 6 lines
include/linux/kernel.h +6 -0
+        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?

Quoted 2 lines

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.

Quoted 7 lines
Quoted 2 lines

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.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

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.