public
anonymous / laby-7.c
Created

Labyrinth generator

  • Download Gist
laby-7.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
// About 323MB/s on craptop
#include <unistd.h>
#include <stdlib.h>
unsigned int buf[8192];
unsigned int overflow[32];
int main() {
int n;
for(;;) {
for(n = 0; n < sizeof(buf) / sizeof(buf[0]); ) {
unsigned int r = rand();
buf[n++] = 0x2f2f2f2f + 0x2d * (r & 0x01010101); r >>= 1; // 1
buf[n++] = 0x2f2f2f2f + 0x2d * (r & 0x01010101); r >>= 1; // 2
buf[n++] = 0x2f2f2f2f + 0x2d * (r & 0x01010101); r >>= 1; // 3
buf[n++] = 0x2f2f2f2f + 0x2d * (r & 0x01010101); r >>= 1; // 4
buf[n++] = 0x2f2f2f2f + 0x2d * (r & 0x01010101); r >>= 1; // 5
buf[n++] = 0x2f2f2f2f + 0x2d * (r & 0x01010101); r >>= 1; // 6
buf[n++] = 0x2f2f2f2f + 0x2d * (r & 0x01010101); r >>= 1; // 7
}
ssize_t s = write(1, buf, sizeof(buf));
}
}
laby-ull-31-lut.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
// About 410MB/s on craptop
#include <unistd.h>
#include <stdlib.h>
unsigned long long lut[256];
unsigned long long buf[8192];
unsigned long long overflow[32];
int main() {
long long n, m, a,b,c;
char *p = (char *) lut;
for (n = 0; n < 256; ++n)
for (m = 0x80; m; m >>= 1)
*p++ = (n & m) ? 0x2f : 0x5c;
unsigned int r, q;
for(;;) {
for(n = 0; n < sizeof(buf) / sizeof(buf[0]); ) {
r = rand();
buf[n++] = lut[0xFF & r]; r >>= 8;
buf[n++] = lut[0xFF & r]; r >>= 8;
buf[n++] = lut[0xFF & r]; r >>= 8; // r has 7 random bits left
q = rand();
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8; // q has 7 random bits left
r |= q << 7;
buf[n++] = lut[0xFF & r]; r >>= 8; // r has 6 random bits left
q = rand();
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8; // q has 7 random bits left
r |= q << 6;
buf[n++] = lut[0xFF & r]; r >>= 8; // r has 5 random bits left
q = rand();
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8; // q has 7 random bits left
r |= q << 5;
buf[n++] = lut[0xFF & r]; r >>= 8; // r has 4 random bits left
q = rand();
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8; // q has 7 random bits left
r |= q << 4;
buf[n++] = lut[0xFF & r]; r >>= 8; // r has 3 random bits left
q = rand();
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8; // q has 7 random bits left
r |= q << 3;
buf[n++] = lut[0xFF & r]; r >>= 8; // r has 2 random bits left
q = rand();
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8; // q has 7 random bits left
r |= q << 2;
buf[n++] = lut[0xFF & r]; r >>= 8; // r has 1 random bits left
q = rand();
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8;
buf[n++] = lut[0xFF & q]; q >>= 8; // q has 7 random bits left
r |= q << 1;
buf[n++] = lut[0xFF & r]; r >>= 8; // r has 0 random bits left
}
ssize_t s = write(1, buf, sizeof(buf));
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.