#define php_uint32 unsigned int//!!
#define php_int32 int//!!
#define PHPAPI
#define MT_N (624)
#define M (397) /* a period parameter */
#define N MT_N /* length of state vector */
#define BG(x) (x)
#define loBit(u) ((u) & 0x00000001U) /* mask all but lowest bit of u */
#define loBits(u) ((u) & 0x7FFFFFFFU) /* mask the highest bit of u */
#define hiBit(u) ((u) & 0x80000000U) /* mask all but highest bit of u */
#define mixBits(u, v) (hiBit(u)|loBits(v)) /* move hi bit of u to hi bit of v */
#define twist(m,u,v) (m ^ (mixBits(u,v)>>1) ^ ((php_uint32)(-(php_int32)(loBit(u))) & 0x9908b0dfU))
#define TSRMLS_D
php_uint32 gstate[MT_N+1] = {0}; /* state vector + 1 extra to not violate ANSI C */
php_uint32 *next = NULL; /* next random value is computed from here */
int left = 0; /* can *next++ this many times before reloading */
unsigned int asm_get_rndseed()
{
asm("rdtsc");
}
static inline void php_mt_initialize(php_uint32 seed, php_uint32 *state)
{
/* Initialize generator state with seed
See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier.
In previous versions, most significant bits (MSBs) of the seed affect
only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto. */
register php_uint32 *s = state;
register php_uint32 *r = state;
register int i = 1;
for (i = N - M; i--; ++p)
*p = twist(p[M], p[0], p[1]);
for (i = M; --i; ++p)
*p = twist(p[M-N], p[0], p[1]);
*p = twist(p[M-N], p[0], state[0]);
BG(left) = N;
BG(next) = state;
}
PHPAPI php_uint32 php_mt_rand()
{
/* Pull a 32-bit integer from the generator state
Every other access function simply transforms the numbers extracted here */
register php_uint32 s1;
if (BG(left) == 0) {
php_mt_reload();
}
--BG(left);