forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
3 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |