lib: add lib/gcd.c

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linux Kernel Mailing List
Date: Thursday, June 18, 2009 - 3:01 pm

Gitweb:     http://git.kernel.org/linus/d2829224619866daf336141b71550e223a198838
Commit:     d2829224619866daf336141b71550e223a198838
Parent:     eae9d2ba0cfc27a2ad9765f23efb98fb80d80234
Author:     Florian Fainelli <florian@openwrt.org>
AuthorDate: Wed Jun 17 16:28:38 2009 -0700
Committer:  Linus Torvalds <torvalds@linux-foundation.org>
CommitDate: Thu Jun 18 13:04:05 2009 -0700

    lib: add lib/gcd.c
    
    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.
    
    [akpm@linux-foundation.org: use swap() (pointed out by Joe)]
    [akpm@linux-foundation.org: just add gcd.o to obj-y, remove Kconfig changes]
    Signed-off-by: Florian Fainelli <florian@openwrt.org>
    Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
    Cc: Takashi Iwai <tiwai@suse.de>
    Cc: Simon Horman <horms@verge.net.au>
    Cc: Julius Volz <juliusv@google.com>
    Cc: David S. Miller <davem@davemloft.net>
    Cc: Patrick McHardy <kaber@trash.net>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---
 include/linux/gcd.h |    8 ++++++++
 lib/Makefile        |    2 +-
 lib/gcd.c           |   18 ++++++++++++++++++
 3 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/include/linux/gcd.h b/include/linux/gcd.h
new file mode 100644
index 0000000..69f5e8a
--- /dev/null
+++ b/include/linux/gcd.h
@@ -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 */
diff --git a/lib/Makefile b/lib/Makefile
index 8e9bcf9..b6d1857 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -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
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);
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
lib: add lib/gcd.c, Linux Kernel Mailing ..., (Thu Jun 18, 3:01 pm)