random.c: pack hash seeds
* random.c (seed_keys_t, init_seed): pack seed for rb_hash_start and rb_memhash, and fill them at once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56990 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
41a7549b8e
commit
1816e39351
44
random.c
44
random.c
@ -1473,50 +1473,35 @@ random_s_rand(int argc, VALUE *argv, VALUE obj)
|
|||||||
#endif
|
#endif
|
||||||
#include "siphash.c"
|
#include "siphash.c"
|
||||||
|
|
||||||
static st_index_t hashseed;
|
typedef struct {
|
||||||
typedef uint8_t sipseed_keys_t[16];
|
st_index_t hash;
|
||||||
|
uint8_t sip[16];
|
||||||
|
} seed_keys_t;
|
||||||
|
|
||||||
static union {
|
static union {
|
||||||
sipseed_keys_t key;
|
seed_keys_t key;
|
||||||
uint32_t u32[type_roomof(sipseed_keys_t, uint32_t)];
|
uint32_t u32[type_roomof(seed_keys_t, uint32_t)];
|
||||||
} sipseed;
|
} seed;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_hashseed(struct MT *mt)
|
init_seed(struct MT *mt)
|
||||||
{
|
|
||||||
hashseed = genrand_int32(mt);
|
|
||||||
#if SIZEOF_ST_INDEX_T*CHAR_BIT > 4*8
|
|
||||||
hashseed <<= 32;
|
|
||||||
hashseed |= genrand_int32(mt);
|
|
||||||
#endif
|
|
||||||
#if SIZEOF_ST_INDEX_T*CHAR_BIT > 8*8
|
|
||||||
hashseed <<= 32;
|
|
||||||
hashseed |= genrand_int32(mt);
|
|
||||||
#endif
|
|
||||||
#if SIZEOF_ST_INDEX_T*CHAR_BIT > 12*8
|
|
||||||
hashseed <<= 32;
|
|
||||||
hashseed |= genrand_int32(mt);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
init_siphash(struct MT *mt)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < numberof(sipseed.u32); ++i)
|
for (i = 0; i < numberof(seed.u32); ++i)
|
||||||
sipseed.u32[i] = genrand_int32(mt);
|
seed.u32[i] = genrand_int32(mt);
|
||||||
}
|
}
|
||||||
|
|
||||||
st_index_t
|
st_index_t
|
||||||
rb_hash_start(st_index_t h)
|
rb_hash_start(st_index_t h)
|
||||||
{
|
{
|
||||||
return st_hash_start(hashseed + h);
|
return st_hash_start(seed.key.hash + h);
|
||||||
}
|
}
|
||||||
|
|
||||||
st_index_t
|
st_index_t
|
||||||
rb_memhash(const void *ptr, long len)
|
rb_memhash(const void *ptr, long len)
|
||||||
{
|
{
|
||||||
sip_uint64_t h = sip_hash24(sipseed.key, ptr, len);
|
sip_uint64_t h = sip_hash24(seed.key.sip, ptr, len);
|
||||||
#ifdef HAVE_UINT64_T
|
#ifdef HAVE_UINT64_T
|
||||||
return (st_index_t)h;
|
return (st_index_t)h;
|
||||||
#else
|
#else
|
||||||
@ -1539,8 +1524,7 @@ Init_RandomSeedCore(void)
|
|||||||
fill_random_seed(initial_seed, DEFAULT_SEED_CNT);
|
fill_random_seed(initial_seed, DEFAULT_SEED_CNT);
|
||||||
init_by_array(&mt, initial_seed, DEFAULT_SEED_CNT);
|
init_by_array(&mt, initial_seed, DEFAULT_SEED_CNT);
|
||||||
|
|
||||||
init_hashseed(&mt);
|
init_seed(&mt);
|
||||||
init_siphash(&mt);
|
|
||||||
|
|
||||||
explicit_bzero(initial_seed, DEFAULT_SEED_LEN);
|
explicit_bzero(initial_seed, DEFAULT_SEED_LEN);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user