[PATCH 05/12] Make rand_bool a macro
[email protected] Fri, 6 Mar 2015 14:31:21 -0800
| Newsgroups | org.kernel.vger.trinity |
|---|---|
| Message-ID | <[email protected]> |
From: Tyson Smith <[email protected]> Since rand_bool is used a heavily used operation simplifying it may shave off some cycles here and there. Also replaced %2 with &1 with the same intention. --- include/random.h | 3 ++- random.c | 5 ----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/include/random.h b/include/random.h index 69ccfa3..b8f8d2c 100644 --- a/include/random.h +++ b/include/random.h @@ -13,6 +13,8 @@ #error "Unexpected RAND_MAX value. Please add support." #endif +#define rand_bool() (rand() & 1) + extern unsigned int seed; unsigned int init_seed(unsigned int seed); void set_seed(struct childdata *child); @@ -20,7 +22,6 @@ void reseed(void); unsigned int new_seed(void); void generate_rand_bytes(unsigned char *ptr, unsigned int len); -unsigned int rand_bool(void); unsigned int rand32(void); u64 rand64(void); unsigned int rand_range(unsigned int min, unsigned int max); diff --git a/random.c b/random.c index 063912f..a1ff7a8 100644 --- a/random.c +++ b/random.c @@ -64,11 +64,6 @@ unsigned long set_rand_bitmask(unsigned int num, const unsigned long *values) return mask; } -unsigned int rand_bool(void) -{ - return rand() % 2; -} - /* * Pick a random power of two between 2^0 and 2^(__WORDSIZE-1) */ -- 1.9.1