]> Git Repo - linux.git/commitdiff
lib: add lib/gcd.c
authorFlorian Fainelli <[email protected]>
Wed, 17 Jun 2009 23:28:38 +0000 (16:28 -0700)
committerLinus Torvalds <[email protected]>
Thu, 18 Jun 2009 20:04:05 +0000 (13:04 -0700)
This patch adds lib/gcd.c which contains a greatest common divider
implementation taken from sound/core/pcm_timer.c

Several usages of this new library function will be sent to subsystem
maintainers.

[[email protected]: use swap() (pointed out by Joe)]
[[email protected]: just add gcd.o to obj-y, remove Kconfig changes]
Signed-off-by: Florian Fainelli <[email protected]>
Cc: Sergei Shtylyov <[email protected]>
Cc: Takashi Iwai <[email protected]>
Cc: Simon Horman <[email protected]>
Cc: Julius Volz <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Patrick McHardy <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
include/linux/gcd.h [new file with mode: 0644]
lib/Makefile
lib/gcd.c [new file with mode: 0644]

diff --git a/include/linux/gcd.h b/include/linux/gcd.h
new file mode 100644 (file)
index 0000000..69f5e8a
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef _GCD_H
+#define _GCD_H
+
+#include <linux/compiler.h>
+
+unsigned long gcd(unsigned long a, unsigned long b) __attribute_const__;
+
+#endif /* _GCD_H */
index 8e9bcf9d3261cb09b91cb6f42e2e5750c8b16812..b6d1857bbf08fd98804e4993cd934b6dbd9812cb 100644 (file)
@@ -21,7 +21,7 @@ lib-y += kobject.o kref.o klist.o
 
 obj-y += bcd.o div64.o sort.o parser.o halfmd4.o debug_locks.o random32.o \
         bust_spinlocks.o hexdump.o kasprintf.o bitmap.o scatterlist.o \
-        string_helpers.o
+        string_helpers.o gcd.o
 
 ifeq ($(CONFIG_DEBUG_KOBJECT),y)
 CFLAGS_kobject.o += -DDEBUG
diff --git a/lib/gcd.c b/lib/gcd.c
new file mode 100644 (file)
index 0000000..f879033
--- /dev/null
+++ b/lib/gcd.c
@@ -0,0 +1,18 @@
+#include <linux/kernel.h>
+#include <linux/gcd.h>
+#include <linux/module.h>
+
+/* Greatest common divisor */
+unsigned long gcd(unsigned long a, unsigned long b)
+{
+       unsigned long r;
+
+       if (a < b)
+               swap(a, b);
+       while ((r = a % b) != 0) {
+               a = b;
+               b = r;
+       }
+       return b;
+}
+EXPORT_SYMBOL_GPL(gcd);
This page took 0.065772 seconds and 4 git commands to generate.