Compare commits

..

No commits in common. "05b9a221748938b832acd509257ebd931049cab0" and "a6f0bf93d913b6f096afaa88cd6fd3bec40b2abb" have entirely different histories.

2 changed files with 12 additions and 37 deletions

View File

@ -6,12 +6,12 @@ CFLAGS="-g -Wall -Werror "
XORSHIFT_SRC="xorshift.c ppm.c" XORSHIFT_SRC="xorshift.c ppm.c"
XORSHIFT_OUT=xorshift XORSHIFT_OUT=xorshift
echo "Cleaning outputs dir..." echo "Clean outputs dir..."
rm -rf "./outputs/*" rm -rf "./outputs/*"
echo -e "\nBuilding xorshift generators..." echo -e "\nBuild xorshift generators..."
(set -x ; $CC $CFLAGS $XORSHIFT_SRC -o $XORSHIFT_OUT) (set -x ; $CC $CFLAGS $XORSHIFT_SRC -o $XORSHIFT_OUT)
echo -e "\nTesting xorshift generators..." echo -e "\nTest xorshift generators..."
./xorshift ./xorshift
echo "Generated" echo "Generated"

View File

@ -17,8 +17,6 @@ void test_xorshift_256(Image *img);
u64 xorshift_256_generate(void *s); u64 xorshift_256_generate(void *s);
void test_xoshiro_256ss(Image *img); void test_xoshiro_256ss(Image *img);
u64 xoshiro_256ss_generate(void *s); u64 xoshiro_256ss_generate(void *s);
void test_xoshiro_256p(Image *img);
u64 xoshiro_256p_generate(void *s);
u64 rol64(u64 x, u64 bits); u64 rol64(u64 x, u64 bits);
XOR256State init_xor_256_state(); XOR256State init_xor_256_state();
void write_image_data(Image *img, RandGenFunc *gen_rand, void *s); void write_image_data(Image *img, RandGenFunc *gen_rand, void *s);
@ -41,8 +39,10 @@ int main(int argc, char *argv[]) {
}; };
test_xorshift_256(&img); test_xorshift_256(&img);
write_p6_ppm("./outputs/xorshift256.ppm", &img);
test_xoshiro_256ss(&img); test_xoshiro_256ss(&img);
test_xoshiro_256p(&img); write_p6_ppm("./outputs/xoshiro256ss.ppm", &img);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
@ -50,7 +50,6 @@ int main(int argc, char *argv[]) {
void test_xorshift_256(Image *img) { void test_xorshift_256(Image *img) {
XOR256State state = init_xor_256_state(); XOR256State state = init_xor_256_state();
write_image_data(img, xorshift_256_generate, (void *)&state); write_image_data(img, xorshift_256_generate, (void *)&state);
write_p6_ppm("./outputs/xorshift256.ppm", img);
} }
u64 xorshift_256_generate(void *s) { u64 xorshift_256_generate(void *s) {
@ -69,7 +68,6 @@ u64 xorshift_256_generate(void *s) {
void test_xoshiro_256ss(Image *img) { void test_xoshiro_256ss(Image *img) {
XOR256State state = init_xor_256_state(); XOR256State state = init_xor_256_state();
write_image_data(img, xoshiro_256ss_generate, (void *)&state); write_image_data(img, xoshiro_256ss_generate, (void *)&state);
write_p6_ppm("./outputs/xoshiro256ss.ppm", img);
} }
u64 xoshiro_256ss_generate(void *s) { u64 xoshiro_256ss_generate(void *s) {
@ -89,29 +87,6 @@ u64 xoshiro_256ss_generate(void *s) {
return result; return result;
} }
void test_xoshiro_256p(Image *img) {
XOR256State state = init_xor_256_state();
write_image_data(img, xoshiro_256p_generate, (void *)&state);
write_p6_ppm("./outputs/xoshiro256p.ppm", img);
}
u64 xoshiro_256p_generate(void *s) {
XOR256State *state = (XOR256State *)s;
const u64 result = state->w + state->x;
const u64 t = state->z << 17;
state->y ^= state->w;
state->x ^= state->z;
state->z ^= state->y;
state->w ^= state->x;
state->y ^= t;
state->x = rol64(state->x, 45);
return result;
}
u64 rol64(u64 x, u64 bits) { return (x << bits) | (x >> (64 - bits)); } u64 rol64(u64 x, u64 bits) { return (x << bits) | (x >> (64 - bits)); }
XOR256State init_xor_256_state() { XOR256State init_xor_256_state() {