mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 17:30:02 +00:00
![Chris Wilson](/assets/img/avatar_default.png)
Prime numbers are interesting for testing components that use multiplies and divides, such as testing DRM's struct drm_mm alignment computations. v2: Move to lib/, add selftest v3: Fix initial constants (exclude 0/1 from being primes) v4: More RCU markup to keep 0day/sparse happy v5: Fix RCU unwind on module exit, add to kselftests v6: Tidy computation of bitmap size v7: for_each_prime_number_from() v8: Compose small-primes using BIT() for easier verification v9: Move rcu dance entirely into callers. v10: Improve quote for Betrand's Postulate (aka Chebyshev's theorem) Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Cc: Lukas Wunner <lukas@wunner.de> Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch> Link: http://patchwork.freedesktop.org/patch/msgid/20161222144514.3911-1-chris@chris-wilson.co.uk
37 lines
1.3 KiB
C
37 lines
1.3 KiB
C
#ifndef __LINUX_PRIME_NUMBERS_H
|
|
#define __LINUX_PRIME_NUMBERS_H
|
|
|
|
#include <linux/types.h>
|
|
|
|
bool is_prime_number(unsigned long x);
|
|
unsigned long next_prime_number(unsigned long x);
|
|
|
|
/**
|
|
* for_each_prime_number - iterate over each prime upto a value
|
|
* @prime: the current prime number in this iteration
|
|
* @max: the upper limit
|
|
*
|
|
* Starting from the first prime number 2 iterate over each prime number up to
|
|
* the @max value. On each iteration, @prime is set to the current prime number.
|
|
* @max should be less than ULONG_MAX to ensure termination. To begin with
|
|
* @prime set to 1 on the first iteration use for_each_prime_number_from()
|
|
* instead.
|
|
*/
|
|
#define for_each_prime_number(prime, max) \
|
|
for_each_prime_number_from((prime), 2, (max))
|
|
|
|
/**
|
|
* for_each_prime_number_from - iterate over each prime upto a value
|
|
* @prime: the current prime number in this iteration
|
|
* @from: the initial value
|
|
* @max: the upper limit
|
|
*
|
|
* Starting from @from iterate over each successive prime number up to the
|
|
* @max value. On each iteration, @prime is set to the current prime number.
|
|
* @max should be less than ULONG_MAX, and @from less than @max, to ensure
|
|
* termination.
|
|
*/
|
|
#define for_each_prime_number_from(prime, from, max) \
|
|
for (prime = (from); prime <= (max); prime = next_prime_number(prime))
|
|
|
|
#endif /* !__LINUX_PRIME_NUMBERS_H */
|