working commit

this commit works

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2019-02-22 11:43:39 +08:00
parent 418a26a060
commit c18eea9c62
12 changed files with 7939 additions and 7371 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@ -23,7 +23,7 @@ module memtest (
assign clk = clkosc; assign clk = clkosc;
initial begin initial begin
$readmemh("empty.init", mem); $readmemh("mem.init", mem);
end end
always @(posedge clk) begin always @(posedge clk) begin

File diff suppressed because it is too large Load Diff

1920
output.txt

File diff suppressed because it is too large Load Diff

BIN
samerand

Binary file not shown.

View File

@ -1,24 +1,32 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
uint32_t polynomial = 0x04C11DB7; uint32_t xorshift32(uint32_t x)
static uint32_t rand_step(uint32_t input) { {
/* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
x = x ^ (x << 13);
x = x ^ (x >> 17);
x = x ^ (x << 5);
return x;
}
uint32_t get_rand(uint32_t x) {
uint32_t out = 0;
int i; int i;
uint32_t output = input + 1;
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
if (output & 0x80000000) x = xorshift32(x);
output ^= polynomial; if ((x & 1) == 1)
output = output << 1; out = out | (1<< i);
} }
return output; return out;
} }
int main(int argc, char **argv) { int main(int argc, char **argv) {
int i; int i;
uint32_t init = 0; uint32_t init = 1;
for (i = 0; i < 256; i++) { for (i = 0; i < 2048; i++) {
init = rand_step(init); init = get_rand(init);
printf("%08x\n", init); printf("%08x\n", init);
} }

View File

@ -1,19 +1,27 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# World's worst random number generator # World's worst random number generator
def rand_step(inp): def xorshift32(x):
polynomial = 0x04C11DB7 x = x ^ (x << 13) & 0xffffffff
output = inp + 1 x = x ^ (x >> 17) & 0xffffffff
x = x ^ (x << 5) & 0xffffffff
return x & 0xffffffff
def get_rand(x):
out = 0
for i in range(32): for i in range(32):
if output & 0x80000000: x = xorshift32(x)
output ^= polynomial if (x & 1) == 1:
output = (output << 1) & 0xffffffff out = out | (1 << i)
return output & 0xffffffff return out & 0xffffffff
def get_bit(x):
return (256 * (x & 7)) + (x >> 3)
def main(): def main():
init = 0 init = 1
for i in range(20): for i in range(20):
init = rand_step(init) init = get_rand(init)
print("{:08x}".format(init)) print("{:08x}".format(init))
main() main()

BIN
xform

Binary file not shown.

169
xform.c
View File

@ -1,35 +1,61 @@
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>
#include <assert.h>
// bit 0 = input[1792] & (1 << 31) /*
// bit 1 = input[1792] & (1 << 30) bit 0 -> bit 7
// bit 2 = input[1536] & (1 << 31) bit 1 -> bit 15
// bit 3 = input[1536] & (1 << 30) bit 8192 -> bit 6
// bit 4 = input[1280] & (1 << 31) bit 8193 -> bit 14
// bit 5 = input[1280] & (1 << 30) bit 16384 -> bit 5
// bit 6 = input[1024] & (1 << 31) bit 16385 -> Bit 13
// bit 7 = input[1024] & (1 << 30) bit 24576 -> bit 4
// bit 8 = input[768] & (1 << 31) bit 24577 -> bit 12
// bit 9 = input[768] & (1 << 30) bit 32768 -> bit 3
// bit 10 = input[512] & (1 << 31) bit 32769 -> bit 11
// bit 11 = input[512] & (1 << 30) bit 40960 -> bit 2
// bit 12 = input[256] & (1 << 31) bit 40961 -> bit 10
// bit 13 = input[256] & (1 << 30) bit 49152 -> bit 1
// bit 14 = input[0] & (1 << 31) bit 49153 -> Bit 9
// bit 15 = input[0] & (1 << 30) bit 57344 -> bit 0
bit 57345 -> bit 8
uint32_t polynomial = 0x04C11DB7; bit 0 <- 0
static uint32_t rand_step(uint32_t input) bit 1 <- 8192
bit 2 <- 16384
bit 3 <- 24576
bit 4 <- 32768
bit 5 <- 40960
bit 6 <- 49152
bit 7 <- 57344
bit 8 <- 8193
bit 9 <- 16385
bit 10 <- 24577
bit 11 <- 32769
bit 12 <- 40961
bit 13 <- 1281
bit 14 <- 49153
bit 15 <- 57345
*/
uint32_t xorshift32(uint32_t x)
{ {
/* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
x = x ^ (x << 13);
x = x ^ (x >> 17);
x = x ^ (x << 5);
return x;
}
uint32_t get_rand(uint32_t x) {
uint32_t out = 0;
int i; int i;
uint32_t output = input + 1; for (i = 0; i < 32; i++) {
for (i = 0; i < 32; i++) x = xorshift32(x);
{ if ((x & 1) == 1)
if (output & 0x80000000) out = out | (1<< i);
output ^= polynomial;
output = output << 1;
} }
return output; return out;
} }
static uint8_t get_bit(uint32_t *field, int offset) static uint8_t get_bit(uint32_t *field, int offset)
@ -69,9 +95,16 @@ static uint16_t reverse_u16(uint16_t nonreversed)
return reversed; return reversed;
} }
static uint32_t get_bit_offset(int bit) {
return (8192 * (bit & 7)) + (bit >> 3);
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int i; int i;
for (i = 0; i < 32; i++) {
printf("bit offset %d: %d\n", i, get_bit_offset(i));
}
// uint32_t test_1[] = {1}; // uint32_t test_1[] = {1};
// uint32_t test_2[] = {0, 1}; // uint32_t test_2[] = {0, 1};
// uint32_t test_3[] = {2, 0}; // uint32_t test_3[] = {2, 0};
@ -94,48 +127,58 @@ int main(int argc, char **argv)
// printf("test_4: bit %d set\n", i); // printf("test_4: bit %d set\n", i);
// } // }
uint32_t input[256]; uint32_t input[2048] = {};
uint32_t output[256] = {}; uint32_t output[2048] = {};
uint32_t init = 0; uint32_t init = 1;
for (i = 0; i < sizeof(input) / 4; i++) for (i = 0; i < sizeof(input) / 4; i++)
{ {
init = rand_step(init); init = get_rand(init);
input[i] = init; input[i] = init;
} }
// print_hex(input, sizeof(input), 0); // print_hex(input, sizeof(input), 0);
// return; // return;
uint16_t *o16 = (uint16_t *)output; for (i = 0; i < sizeof(input) * 8; i++)
uint8_t *i8 = (uint8_t *)input;
for (i = 0; i < sizeof(input) / 2; i++)
{ {
int j; int bit;
for (j = 0; j < 16; j++) assert(get_bit_offset(i) < sizeof(output) * 8);
{ bit = get_bit(input, get_bit_offset(i));
// printf("o16[%d] |= (!!(i8[1792+%d] & (1 << %d)) << 0;\n", i, i, 2*(15-j)+1); // bit = get_bit(input, i);
o16[i] |= (!!(i8[1792+i] & (1 << 2*(15-j)+1))) << 0; // if (bit)
o16[i] |= (!!(i8[1792+i] & (1 << 2*(15-j)+0))) << 1; // printf("bit %d is set\n", i);
o16[i] |= (!!(i8[1536+i] & (1 << 2*(15-j)+1))) << 2; // int xform = ((i * 2048) + ((i * 2048) >> 16)) & 0xffff;
o16[i] |= (!!(i8[1536+i] & (1 << 2*(15-j)+0))) << 3; // printf("%d\n", xform);
o16[i] |= (!!(i8[1280+i] & (1 << 2*(15-j)+1))) << 4; // assert(xform < sizeof(output) * 8);
o16[i] |= (!!(i8[1280+i] & (1 << 2*(15-j)+0))) << 5; if (bit)
o16[i] |= (!!(i8[1024+i] & (1 << 2*(15-j)+1))) << 6; set_bit(output, i);
o16[i] |= (!!(i8[1024+i] & (1 << 2*(15-j)+0))) << 7; // set_bit(output, get_bit_offset(i));
o16[i] |= (!!(i8[768+i] & (1 << 2*(15-j)+1))) << 8; // int j;
o16[i] |= (!!(i8[768+i] & (1 << 2*(15-j)+0))) << 9; // for (j = 0; j < 16; j++)
o16[i] |= (!!(i8[512+i] & (1 << 2*(15-j)+1))) << 10; // {
o16[i] |= (!!(i8[512+i] & (1 << 2*(15-j)+0))) << 11; // // printf("o16[%d] |= (!!(i8[1792+%d] & (1 << %d)) << 0;\n", i, i, 2*(15-j)+1);
o16[i] |= (!!(i8[256+i] & (1 << 2*(15-j)+1))) << 12; // o16[i] |= (!!(i8[1792+i] & (1 << 2*(15-j)+1))) << 0;
o16[i] |= (!!(i8[256+i] & (1 << 2*(15-j)+0))) << 13; // o16[i] |= (!!(i8[1792+i] & (1 << 2*(15-j)+0))) << 1;
o16[i] |= (!!(i8[0+i] & (1 << 2*(15-j)+1))) << 14; // o16[i] |= (!!(i8[1536+i] & (1 << 2*(15-j)+1))) << 2;
o16[i] |= (!!(i8[0+i] & (1 << 2*(15-j)+0))) << 15; // o16[i] |= (!!(i8[1536+i] & (1 << 2*(15-j)+0))) << 3;
// o16[0] = i // o16[i] |= (!!(i8[1280+i] & (1 << 2*(15-j)+1))) << 4;
// if (get_bit(input, i * 16 + j)) // o16[i] |= (!!(i8[1280+i] & (1 << 2*(15-j)+0))) << 5;
// set_bit(output, j * 256 + i); // o16[i] |= (!!(i8[1024+i] & (1 << 2*(15-j)+1))) << 6;
// else // o16[i] |= (!!(i8[1024+i] & (1 << 2*(15-j)+0))) << 7;
// clear_bit(output, j * 256 + i); // o16[i] |= (!!(i8[768+i] & (1 << 2*(15-j)+1))) << 8;
} // o16[i] |= (!!(i8[768+i] & (1 << 2*(15-j)+0))) << 9;
// o16[i] |= (!!(i8[512+i] & (1 << 2*(15-j)+1))) << 10;
// o16[i] |= (!!(i8[512+i] & (1 << 2*(15-j)+0))) << 11;
// o16[i] |= (!!(i8[256+i] & (1 << 2*(15-j)+1))) << 12;
// o16[i] |= (!!(i8[256+i] & (1 << 2*(15-j)+0))) << 13;
// o16[i] |= (!!(i8[0+i] & (1 << 2*(15-j)+1))) << 14;
// o16[i] |= (!!(i8[0+i] & (1 << 2*(15-j)+0))) << 15;
// // o16[0] = i
// // if (get_bit(input, i * 16 + j))
// // set_bit(output, j * 256 + i);
// // else
// // clear_bit(output, j * 256 + i);
// }
} }
// uint8_t *o8 = (uint8_t *)output; // uint8_t *o8 = (uint8_t *)output;
@ -145,9 +188,13 @@ int main(int argc, char **argv)
// for (i = 0; i < sizeof(output)/4; i++) // for (i = 0; i < sizeof(output)/4; i++)
// o16[i] = reverse_u16(o16[i]); // o16[i] = reverse_u16(o16[i]);
print_hex(output, sizeof(output), 0); // print_hex(output, sizeof(output), 0);
// for (i = 0; i < 2047; i++) FILE *infile = fopen("infile.txt", "w");
// printf("00000000\n"); FILE *outfile = fopen("outfile.txt", "w");
for (i = 0; i < sizeof(input)/4; i++) {
fprintf(infile, "%08x\n", input[i]);
fprintf(outfile, "%08x\n", output[i]);
}
return 0; return 0;
} }