Compare commits
No commits in common. "a6f0bf93d913b6f096afaa88cd6fd3bec40b2abb" and "f4afa5d7eacba243f5b551b6a74e4dedbfd9d0d3" have entirely different histories.
a6f0bf93d9
...
f4afa5d7ea
8
compile
8
compile
@ -6,12 +6,4 @@ CFLAGS="-g -Wall -Werror "
|
|||||||
XORSHIFT_SRC="xorshift.c ppm.c"
|
XORSHIFT_SRC="xorshift.c ppm.c"
|
||||||
XORSHIFT_OUT=xorshift
|
XORSHIFT_OUT=xorshift
|
||||||
|
|
||||||
echo "Clean outputs dir..."
|
|
||||||
rm -rf "./outputs/*"
|
|
||||||
|
|
||||||
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 "\nTest xorshift generators..."
|
|
||||||
./xorshift
|
|
||||||
echo "Generated"
|
|
||||||
|
47
xorshift.c
47
xorshift.c
@ -5,11 +5,18 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u64 x;
|
u64 x;
|
||||||
u64 y;
|
u64 y;
|
||||||
u64 z;
|
u64 z;
|
||||||
u64 w;
|
u64 w;
|
||||||
} XOR256State;
|
} XORShift256;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u64 x;
|
||||||
|
u64 y;
|
||||||
|
u64 z;
|
||||||
|
u64 w;
|
||||||
|
} XOShiRo256SS;
|
||||||
|
|
||||||
typedef u64(RandGenFunc)(void *s);
|
typedef u64(RandGenFunc)(void *s);
|
||||||
|
|
||||||
@ -18,7 +25,6 @@ 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);
|
||||||
u64 rol64(u64 x, u64 bits);
|
u64 rol64(u64 x, u64 bits);
|
||||||
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);
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
@ -48,12 +54,18 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void test_xorshift_256(Image *img) {
|
void test_xorshift_256(Image *img) {
|
||||||
XOR256State state = init_xor_256_state();
|
XORShift256 state = {
|
||||||
|
.x = lrand48(),
|
||||||
|
.y = lrand48(),
|
||||||
|
.z = lrand48(),
|
||||||
|
.w = lrand48(),
|
||||||
|
};
|
||||||
|
|
||||||
write_image_data(img, xorshift_256_generate, (void *)&state);
|
write_image_data(img, xorshift_256_generate, (void *)&state);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 xorshift_256_generate(void *s) {
|
u64 xorshift_256_generate(void *s) {
|
||||||
XOR256State *state = (XOR256State *)s;
|
XORShift256 *state = (XORShift256 *)s;
|
||||||
|
|
||||||
u64 t = state->x ^ (state->x << 11);
|
u64 t = state->x ^ (state->x << 11);
|
||||||
|
|
||||||
@ -66,12 +78,18 @@ u64 xorshift_256_generate(void *s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void test_xoshiro_256ss(Image *img) {
|
void test_xoshiro_256ss(Image *img) {
|
||||||
XOR256State state = init_xor_256_state();
|
XOShiRo256SS state = {
|
||||||
|
.x = lrand48(),
|
||||||
|
.y = lrand48(),
|
||||||
|
.z = lrand48(),
|
||||||
|
.w = lrand48(),
|
||||||
|
};
|
||||||
|
|
||||||
write_image_data(img, xoshiro_256ss_generate, (void *)&state);
|
write_image_data(img, xoshiro_256ss_generate, (void *)&state);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 xoshiro_256ss_generate(void *s) {
|
u64 xoshiro_256ss_generate(void *s) {
|
||||||
XOR256State *state = (XOR256State *)s;
|
XOShiRo256SS *state = (XOShiRo256SS *)s;
|
||||||
|
|
||||||
const u64 result = rol64(state->z * 5, 7) * 9;
|
const u64 result = rol64(state->z * 5, 7) * 9;
|
||||||
const u64 t = state->z << 17;
|
const u64 t = state->z << 17;
|
||||||
@ -89,15 +107,6 @@ u64 xoshiro_256ss_generate(void *s) {
|
|||||||
|
|
||||||
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() {
|
|
||||||
return (XOR256State){
|
|
||||||
.x = lrand48(),
|
|
||||||
.y = lrand48(),
|
|
||||||
.z = lrand48(),
|
|
||||||
.w = lrand48(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
void write_image_data(Image *img, RandGenFunc *gen_rand, void *s) {
|
void write_image_data(Image *img, RandGenFunc *gen_rand, void *s) {
|
||||||
for (u64 y = 0; y < img->height; ++y) {
|
for (u64 y = 0; y < img->height; ++y) {
|
||||||
for (u64 x = 0; x < img->width; ++x) {
|
for (u64 x = 0; x < img->width; ++x) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user