Paste: xoshiro256starstar.c with debug
Author: | erg |
Mode: | c |
Date: | Sat, 29 Dec 2018 18:34:54 |
Plain Text |
% cat xoshiro.c
#include <stdint.h>
#include <stdio.h>
static inline uint64_t rotl(const uint64_t x, int k) {
return (x << k) | (x >> (64 - k));
}
static uint64_t s[4];
uint64_t next(void) {
const uint64_t result_starstar = rotl(s[1] * 5, 7) * 9;
const uint64_t t = s[1] << 17;
s[2] ^= s[0];
s[3] ^= s[1];
s[1] ^= s[2];
s[0] ^= s[3];
s[2] ^= t;
s[3] = rotl(s[3], 45);
return result_starstar;
}
void jump(void) {
static const uint64_t JUMP[] = { 0x180ec6d33cfd0aba, 0xd5a61266f0c9392c, 0xa9582618e03fc9aa, 0x39abdc4529b1661c };
uint64_t s0 = 0;
uint64_t s1 = 0;
uint64_t s2 = 0;
uint64_t s3 = 0;
for(int i = 0; i < sizeof JUMP / sizeof *JUMP; i++) {
printf("i: %i\n", i);
for(int b = 0; b < 64; b++) {
if (JUMP[i] & UINT64_C(1) << b) {
s0 ^= s[0];
s1 ^= s[1];
s2 ^= s[2];
s3 ^= s[3];
}
next();
}
}
s[0] = s0;
s[1] = s1;
s[2] = s2;
s[3] = s3;
}
void long_jump(void) {
static const uint64_t LONG_JUMP[] = { 0x76e15d3efefdcbbf, 0xc5004e441c522fb3, 0x77710069854ee241, 0x39109bb02acbe635 };
uint64_t s0 = 0;
uint64_t s1 = 0;
uint64_t s2 = 0;
uint64_t s3 = 0;
for(int i = 0; i < sizeof LONG_JUMP / sizeof *LONG_JUMP; i++) {
printf("i: %i\n", i);
for(int b = 0; b < 64; b++) {
if (LONG_JUMP[i] & UINT64_C(1) << b) {
s0 ^= s[0];
s1 ^= s[1];
s2 ^= s[2];
s3 ^= s[3];
}
next();
}
}
s[0] = s0;
s[1] = s1;
s[2] = s2;
s[3] = s3;
}
int main() {
s[0] = 0;
s[1] = 1;
s[2] = 2;
s[3] = 3;
printf("before jump: s0 s1 s2 s3: %llu %llu %llu %llu\n", s[0], s[1], s[2], s[3]);
jump();
printf("jump: s0 s1 s2 s3: %llu %llu %llu %llu\n", s[0], s[1], s[2], s[3]);
printf("\n\n");
s[0] = 0;
s[1] = 1;
s[2] = 2;
s[3] = 3;
printf("before long_jump: s0 s1 s2 s3: %llu %llu %llu %llu\n", s[0], s[1], s[2], s[3]);
long_jump();
printf("long_jump: s0 s1 s2 s3: %llu %llu %llu %llu\n", s[0], s[1], s[2], s[3]);
printf("\n\n");
s[0] = 0;
s[1] = 1;
s[2] = 2;
s[3] = 3;
printf("before next: s0 s1 s2 s3: %llu %llu %llu %llu\n", s[0], s[1], s[2], s[3]);
for(int i = 0; i < 1; i++) {
next();
}
printf("next: s0 s1 s2 s3: %llu %llu %llu %llu\n", s[0], s[1], s[2], s[3]);
return 0;
}
New Annotation