We don't have a uint128_t yet, but we can access rdx:rax.
static uint64_t Q[R] = {}, c=1;
uint64_t mwc64() {
uint64_t a = A;
static int i = ~0;
i = (i + 1) % R;
asm(
"mulq %%rdx\n\taddq %%rcx,%%rax\n\tadcq $0,%%rdx"
: /*out*/ "=a" (Q[i]), "=d" (c)
: /*in*/ "a" (Q[i]), "c" (c), "d" (a) );
return Q[i];
}
and some values for A and R:
A | R | period (approx) |
---|---|---|
18446744073709550874 | 1 | 2127 |
18446744073709547559 | 2 | 2191 |
18446744073709530150 | 4 | 2319 |
18446744073709525530 | 8 | 2575 |
18446744073709398669 | 16 | 21087 |
18446744073709219500 | 32 | 22111 |
18446744073707195115 | 64 | 24159 |
18446744073709214688 | 128 | 28255 |
18446744073688074570 | 256 | 216447 |
No comments:
Post a Comment