_jr_st_resolv() now takes pointer to the xsub union instead of the whole state.

Fortune for cpprng's current commit: Future blessing − 末吉
lib
Avril 3 years ago
parent b35c0f705d
commit 595fd74a97
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -33,17 +33,17 @@ _Static_assert( sizeof(uint48_t) == (sizeof(uint16_t) * 3), "bad uint48 (ushort[
_Static_assert( sizeof(((struct jr_state*)NULL)->st) == sizeof(uint64_t), "bad uint64 (union st)");
__attribute__((nonnull, returns_nonnull))
static unsigned short* IFUNC_IMPL(_jr_st_resolv, low) (struct jr_state* restrict state)
static unsigned short* IFUNC_IMPL(_jr_st_resolv, low) (jr_xsub_t* restrict state)
{
return state->st.xsubi;
return state->xsubi;
}
__attribute__((nonnull, returns_nonnull))
static unsigned short* IFUNC_IMPL(_jr_st_resolv, high) (struct jr_state* restrict state)
static unsigned short* IFUNC_IMPL(_jr_st_resolv, high) (jr_xsub_t* restrict state)
{
return state->st.xsubi+1;
return state->xsubi+1;
}
__attribute__((returns_nonnull))
static unsigned short* IFUNC_RESOLVER(_jr_st_resolv) (struct jr_state* restrict state)
static unsigned short* IFUNC_RESOLVER(_jr_st_resolv) (jr_xsub_t* restrict state)
{
struct jr_state chk = {0};
chk.st.xsubh = JR_MAX;
@ -51,23 +51,23 @@ static unsigned short* IFUNC_RESOLVER(_jr_st_resolv) (struct jr_state* restrict
? & IFUNC_IMPL(_jr_st_resolv, high)
: & IFUNC_IMPL(_jr_st_resolv, low);
}
static unsigned short* IFUNC_DEF(_jr_st_resolv, (struct jr_state* restrict state) __attribute__((nonnull, returns_nonnull)));
static unsigned short* IFUNC_DEF(_jr_st_resolv, (jr_xsub_t* restrict state) __attribute__((nonnull, returns_nonnull)));
internal void _jr_seed(struct jr_state* restrict state, unsigned long with)
{
state->st.xsubh = with;
seed48_r(_jr_st_resolv(state), &state->data);
seed48_r(_jr_st_resolv(&state->st), &state->data);
}
internal long _jr_proc(struct jr_state* restrict state)
{
jrand48_r(_jr_st_resolv(state), &state->data, &state->result);
jrand48_r(_jr_st_resolv(&state->st), &state->data, &state->result);
return state->result;
}
internal double _jr_procf(struct jr_state* restrict state)
{
erand48_r(_jr_st_resolv(state), &state->data, &state->fresult);
erand48_r(_jr_st_resolv(&state->st), &state->data, &state->fresult);
return state->fresult;
}
@ -96,7 +96,7 @@ void __TEST__jr_test()
struct jr_state* st = _jr_alloc();
assert(!st->st._xsub);
_jr_seed(st, ~0UL);
const volatile unsigned short* res_state = _jr_st_resolv(st);
const volatile unsigned short* res_state = _jr_st_resolv(&st->st);
printf("seeded: %lu (full %lu, spill %u). xsubi = [%04x, %04x, %04x) %04x], resolv = [%04x, %04x, %04x) %04x]\n", (uint64_t)st->st.xsubh, st->st.xsubl, st->st._xsub,
st->st.xsubi[0],
st->st.xsubi[1],
@ -112,7 +112,7 @@ void __TEST__jr_test()
{
printf("res: %ld\n", _jr_proc(st));
printf("state: %lu (full %lu, spill %u). xsubi = %p, resolv = %p\n", (uint64_t)st->st.xsubh, st->st.xsubl, st->st._xsub,
(const void*)st->st.xsubi, (const void*)_jr_st_resolv(st));
(const void*)st->st.xsubi, (const void*)_jr_st_resolv(&st->st));
}
printf("ended: %lu (full %lu, spill %u). xsubi = [%04x, %04x, %04x) %04x], resolv = [%04x, %04x, %04x) %04x]\n", (uint64_t)st->st.xsubh, st->st.xsubl, st->st._xsub,
st->st.xsubi[0],

Loading…
Cancel
Save