-
-
Save pfactum/82dc137080a2c632ae7b to your computer and use it in GitHub Desktop.
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
diff --git a/libpfrng.c b/libpfrng.c | |
index f41c0c2..8fccc1a 100644 | |
--- a/libpfrng.c | |
+++ b/libpfrng.c | |
@@ -56,9 +56,6 @@ pthread_mutex_t fast_lock; | |
/// Handles per-thread previous timings | |
static struct timespec *time_prev; | |
-/// Handles pre-calculated weights for bits rolling | |
-static double rolling_weights_table[UINT64_SIZE]; | |
- | |
/** | |
* Collapses uint64_t to one bit | |
* | |
@@ -75,19 +72,16 @@ static inline uint8_t pfrng_get_rolled_bit(uint64_t _x) | |
// change faster than leftmost. So it's necessary to sum them with | |
// different weights. | |
- double sum = 0; | |
+ uint64_t sum = 0; | |
for (uint8_t i = 0; i < UINT64_SIZE; i++) | |
{ | |
// Double negative trick is stolen from stackoverflow: | |
// https://stackoverflow.com/questions/47981/how-do-you-set-clear-and-toggle-a-single-bit-in-c-c | |
- uint8_t current_bit = !!(_x & (1 << i)); | |
- if (current_bit) | |
- sum += rolling_weights_table[i]; | |
+ if (!!(_x & (1ULL << i))) | |
+ sum += UINT64_SIZE - 1 - i; | |
} | |
- uint8_t integer_sum = (uint8_t)round(sum); | |
- | |
// Heart of uniform distribution: odds and evens appear with p=0.5 | |
- return (integer_sum % 2) ? 1 : 0; | |
+ return (sum % 2) ? 1 : 0; | |
} | |
/** | |
@@ -434,10 +428,6 @@ void pfrng_init(void) | |
if (unlikely(mixer_output == NULL || time_prev == NULL)) | |
abort(); | |
- // Init weights table | |
- for (uint8_t i = 0; i < UINT64_SIZE; i++) | |
- rolling_weights_table[i] = 1.0 / (i + 1); | |
- | |
// Init statistic variables | |
stats.bits_misses = 0; | |
for (uint8_t i = 0; i < UINT64_SIZE; i++) | |
@@ -471,9 +461,6 @@ void pfrng_init(void) | |
void pfrng_done(void) | |
{ | |
// Cleanup | |
- for (uint8_t i = 0; i < UINT64_SIZE; i++) | |
- rolling_weights_table[i] = 0; | |
- | |
stats.bits_misses = 0; | |
for (uint8_t i = 0; i < UINT64_SIZE; i++) | |
stats.freq[i] = 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment