Refactor prng* from cpp macros into inline functions.
Remove 32-bit variant, convert prng64() to prng_lg_range(), and add prng_range().
This commit is contained in:
@@ -2196,9 +2196,7 @@ arena_malloc_large(arena_t *arena, size_t size, szind_t binind, bool zero)
|
||||
* that is a multiple of the cacheline size, e.g. [0 .. 63) * 64
|
||||
* for 4 KiB pages and 64-byte cachelines.
|
||||
*/
|
||||
prng64(r, LG_PAGE - LG_CACHELINE, arena->offset_state,
|
||||
UINT64_C(6364136223846793009),
|
||||
UINT64_C(1442695040888963409));
|
||||
r = prng_lg_range(&arena->offset_state, LG_PAGE - LG_CACHELINE);
|
||||
random_offset = ((uintptr_t)r) << LG_CACHELINE;
|
||||
} else
|
||||
random_offset = 0;
|
||||
|
@@ -99,7 +99,7 @@ ckh_try_bucket_insert(ckh_t *ckh, size_t bucket, const void *key,
|
||||
* Cycle through the cells in the bucket, starting at a random position.
|
||||
* The randomness avoids worst-case search overhead as buckets fill up.
|
||||
*/
|
||||
prng32(offset, LG_CKH_BUCKET_CELLS, ckh->prng_state, CKH_A, CKH_C);
|
||||
offset = prng_lg_range(&ckh->prng_state, LG_CKH_BUCKET_CELLS);
|
||||
for (i = 0; i < (ZU(1) << LG_CKH_BUCKET_CELLS); i++) {
|
||||
cell = &ckh->tab[(bucket << LG_CKH_BUCKET_CELLS) +
|
||||
((i + offset) & ((ZU(1) << LG_CKH_BUCKET_CELLS) - 1))];
|
||||
@@ -141,7 +141,7 @@ ckh_evict_reloc_insert(ckh_t *ckh, size_t argbucket, void const **argkey,
|
||||
* were an item for which both hashes indicated the same
|
||||
* bucket.
|
||||
*/
|
||||
prng32(i, LG_CKH_BUCKET_CELLS, ckh->prng_state, CKH_A, CKH_C);
|
||||
i = prng_lg_range(&ckh->prng_state, LG_CKH_BUCKET_CELLS);
|
||||
cell = &ckh->tab[(bucket << LG_CKH_BUCKET_CELLS) + i];
|
||||
assert(cell->key != NULL);
|
||||
|
||||
|
2
src/prng.c
Normal file
2
src/prng.c
Normal file
@@ -0,0 +1,2 @@
|
||||
#define JEMALLOC_PRNG_C_
|
||||
#include "jemalloc/internal/jemalloc_internal.h"
|
@@ -871,8 +871,7 @@ prof_sample_threshold_update(prof_tdata_t *tdata)
|
||||
* pp 500
|
||||
* (http://luc.devroye.org/rnbookindex.html)
|
||||
*/
|
||||
prng64(r, 53, tdata->prng_state, UINT64_C(6364136223846793005),
|
||||
UINT64_C(1442695040888963407));
|
||||
r = prng_lg_range(&tdata->prng_state, 53);
|
||||
u = (double)r * (1.0/9007199254740992.0L);
|
||||
tdata->bytes_until_sample = (uint64_t)(log(u) /
|
||||
log(1.0 - (1.0 / (double)((uint64_t)1U << lg_prof_sample))))
|
||||
|
Reference in New Issue
Block a user