working commit
this commit works Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
418a26a060
commit
c18eea9c62
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
4096
memtest/mem.init
4096
memtest/mem.init
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -23,7 +23,7 @@ module memtest (
|
||||
assign clk = clkosc;
|
||||
|
||||
initial begin
|
||||
$readmemh("empty.init", mem);
|
||||
$readmemh("mem.init", mem);
|
||||
end
|
||||
|
||||
always @(posedge clk) begin
|
||||
|
1548
memtest/top.rpt
1548
memtest/top.rpt
File diff suppressed because it is too large
Load Diff
1920
output.txt
1920
output.txt
File diff suppressed because it is too large
Load Diff
32
samerand.c
32
samerand.c
@ -1,24 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
uint32_t polynomial = 0x04C11DB7;
|
||||
static uint32_t rand_step(uint32_t input) {
|
||||
int i;
|
||||
uint32_t output = input + 1;
|
||||
for (i = 0; i < 32; i++) {
|
||||
if (output & 0x80000000)
|
||||
output ^= polynomial;
|
||||
output = output << 1;
|
||||
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;
|
||||
}
|
||||
return output;
|
||||
|
||||
uint32_t get_rand(uint32_t x) {
|
||||
uint32_t out = 0;
|
||||
int i;
|
||||
for (i = 0; i < 32; i++) {
|
||||
x = xorshift32(x);
|
||||
if ((x & 1) == 1)
|
||||
out = out | (1<< i);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int i;
|
||||
|
||||
uint32_t init = 0;
|
||||
for (i = 0; i < 256; i++) {
|
||||
init = rand_step(init);
|
||||
uint32_t init = 1;
|
||||
for (i = 0; i < 2048; i++) {
|
||||
init = get_rand(init);
|
||||
printf("%08x\n", init);
|
||||
}
|
||||
|
||||
|
26
samerand.py
26
samerand.py
@ -1,19 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# World's worst random number generator
|
||||
def rand_step(inp):
|
||||
polynomial = 0x04C11DB7
|
||||
output = inp + 1
|
||||
def xorshift32(x):
|
||||
x = x ^ (x << 13) & 0xffffffff
|
||||
x = x ^ (x >> 17) & 0xffffffff
|
||||
x = x ^ (x << 5) & 0xffffffff
|
||||
return x & 0xffffffff
|
||||
|
||||
def get_rand(x):
|
||||
out = 0
|
||||
for i in range(32):
|
||||
if output & 0x80000000:
|
||||
output ^= polynomial
|
||||
output = (output << 1) & 0xffffffff
|
||||
return output & 0xffffffff
|
||||
x = xorshift32(x)
|
||||
if (x & 1) == 1:
|
||||
out = out | (1 << i)
|
||||
return out & 0xffffffff
|
||||
|
||||
def get_bit(x):
|
||||
return (256 * (x & 7)) + (x >> 3)
|
||||
|
||||
def main():
|
||||
init = 0
|
||||
init = 1
|
||||
for i in range(20):
|
||||
init = rand_step(init)
|
||||
init = get_rand(init)
|
||||
print("{:08x}".format(init))
|
||||
|
||||
main()
|
171
xform.c
171
xform.c
@ -1,35 +1,61 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
|
||||
// bit 0 = input[1792] & (1 << 31)
|
||||
// bit 1 = input[1792] & (1 << 30)
|
||||
// bit 2 = input[1536] & (1 << 31)
|
||||
// bit 3 = input[1536] & (1 << 30)
|
||||
// bit 4 = input[1280] & (1 << 31)
|
||||
// bit 5 = input[1280] & (1 << 30)
|
||||
// bit 6 = input[1024] & (1 << 31)
|
||||
// bit 7 = input[1024] & (1 << 30)
|
||||
// bit 8 = input[768] & (1 << 31)
|
||||
// bit 9 = input[768] & (1 << 30)
|
||||
// bit 10 = input[512] & (1 << 31)
|
||||
// bit 11 = input[512] & (1 << 30)
|
||||
// bit 12 = input[256] & (1 << 31)
|
||||
// bit 13 = input[256] & (1 << 30)
|
||||
// bit 14 = input[0] & (1 << 31)
|
||||
// bit 15 = input[0] & (1 << 30)
|
||||
/*
|
||||
bit 0 -> bit 7
|
||||
bit 1 -> bit 15
|
||||
bit 8192 -> bit 6
|
||||
bit 8193 -> bit 14
|
||||
bit 16384 -> bit 5
|
||||
bit 16385 -> Bit 13
|
||||
bit 24576 -> bit 4
|
||||
bit 24577 -> bit 12
|
||||
bit 32768 -> bit 3
|
||||
bit 32769 -> bit 11
|
||||
bit 40960 -> bit 2
|
||||
bit 40961 -> bit 10
|
||||
bit 49152 -> bit 1
|
||||
bit 49153 -> Bit 9
|
||||
bit 57344 -> bit 0
|
||||
bit 57345 -> bit 8
|
||||
|
||||
uint32_t polynomial = 0x04C11DB7;
|
||||
static uint32_t rand_step(uint32_t input)
|
||||
bit 0 <- 0
|
||||
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)
|
||||
{
|
||||
int i;
|
||||
uint32_t output = input + 1;
|
||||
for (i = 0; i < 32; i++)
|
||||
{
|
||||
if (output & 0x80000000)
|
||||
output ^= polynomial;
|
||||
output = output << 1;
|
||||
/* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
|
||||
x = x ^ (x << 13);
|
||||
x = x ^ (x >> 17);
|
||||
x = x ^ (x << 5);
|
||||
return x;
|
||||
}
|
||||
return output;
|
||||
|
||||
uint32_t get_rand(uint32_t x) {
|
||||
uint32_t out = 0;
|
||||
int i;
|
||||
for (i = 0; i < 32; i++) {
|
||||
x = xorshift32(x);
|
||||
if ((x & 1) == 1)
|
||||
out = out | (1<< i);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static uint8_t get_bit(uint32_t *field, int offset)
|
||||
@ -69,9 +95,16 @@ static uint16_t reverse_u16(uint16_t nonreversed)
|
||||
return reversed;
|
||||
}
|
||||
|
||||
static uint32_t get_bit_offset(int bit) {
|
||||
return (8192 * (bit & 7)) + (bit >> 3);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
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_2[] = {0, 1};
|
||||
// uint32_t test_3[] = {2, 0};
|
||||
@ -94,48 +127,58 @@ int main(int argc, char **argv)
|
||||
// printf("test_4: bit %d set\n", i);
|
||||
// }
|
||||
|
||||
uint32_t input[256];
|
||||
uint32_t output[256] = {};
|
||||
uint32_t input[2048] = {};
|
||||
uint32_t output[2048] = {};
|
||||
|
||||
uint32_t init = 0;
|
||||
uint32_t init = 1;
|
||||
for (i = 0; i < sizeof(input) / 4; i++)
|
||||
{
|
||||
init = rand_step(init);
|
||||
init = get_rand(init);
|
||||
input[i] = init;
|
||||
}
|
||||
// print_hex(input, sizeof(input), 0);
|
||||
// return;
|
||||
|
||||
uint16_t *o16 = (uint16_t *)output;
|
||||
uint8_t *i8 = (uint8_t *)input;
|
||||
for (i = 0; i < sizeof(input) / 2; i++)
|
||||
for (i = 0; i < sizeof(input) * 8; i++)
|
||||
{
|
||||
int j;
|
||||
for (j = 0; j < 16; j++)
|
||||
{
|
||||
// printf("o16[%d] |= (!!(i8[1792+%d] & (1 << %d)) << 0;\n", i, i, 2*(15-j)+1);
|
||||
o16[i] |= (!!(i8[1792+i] & (1 << 2*(15-j)+1))) << 0;
|
||||
o16[i] |= (!!(i8[1792+i] & (1 << 2*(15-j)+0))) << 1;
|
||||
o16[i] |= (!!(i8[1536+i] & (1 << 2*(15-j)+1))) << 2;
|
||||
o16[i] |= (!!(i8[1536+i] & (1 << 2*(15-j)+0))) << 3;
|
||||
o16[i] |= (!!(i8[1280+i] & (1 << 2*(15-j)+1))) << 4;
|
||||
o16[i] |= (!!(i8[1280+i] & (1 << 2*(15-j)+0))) << 5;
|
||||
o16[i] |= (!!(i8[1024+i] & (1 << 2*(15-j)+1))) << 6;
|
||||
o16[i] |= (!!(i8[1024+i] & (1 << 2*(15-j)+0))) << 7;
|
||||
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);
|
||||
}
|
||||
int bit;
|
||||
assert(get_bit_offset(i) < sizeof(output) * 8);
|
||||
bit = get_bit(input, get_bit_offset(i));
|
||||
// bit = get_bit(input, i);
|
||||
// if (bit)
|
||||
// printf("bit %d is set\n", i);
|
||||
// int xform = ((i * 2048) + ((i * 2048) >> 16)) & 0xffff;
|
||||
// printf("%d\n", xform);
|
||||
// assert(xform < sizeof(output) * 8);
|
||||
if (bit)
|
||||
set_bit(output, i);
|
||||
// set_bit(output, get_bit_offset(i));
|
||||
// int j;
|
||||
// for (j = 0; j < 16; j++)
|
||||
// {
|
||||
// // printf("o16[%d] |= (!!(i8[1792+%d] & (1 << %d)) << 0;\n", i, i, 2*(15-j)+1);
|
||||
// o16[i] |= (!!(i8[1792+i] & (1 << 2*(15-j)+1))) << 0;
|
||||
// o16[i] |= (!!(i8[1792+i] & (1 << 2*(15-j)+0))) << 1;
|
||||
// o16[i] |= (!!(i8[1536+i] & (1 << 2*(15-j)+1))) << 2;
|
||||
// o16[i] |= (!!(i8[1536+i] & (1 << 2*(15-j)+0))) << 3;
|
||||
// o16[i] |= (!!(i8[1280+i] & (1 << 2*(15-j)+1))) << 4;
|
||||
// o16[i] |= (!!(i8[1280+i] & (1 << 2*(15-j)+0))) << 5;
|
||||
// o16[i] |= (!!(i8[1024+i] & (1 << 2*(15-j)+1))) << 6;
|
||||
// o16[i] |= (!!(i8[1024+i] & (1 << 2*(15-j)+0))) << 7;
|
||||
// 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;
|
||||
@ -145,9 +188,13 @@ int main(int argc, char **argv)
|
||||
// for (i = 0; i < sizeof(output)/4; i++)
|
||||
// o16[i] = reverse_u16(o16[i]);
|
||||
|
||||
print_hex(output, sizeof(output), 0);
|
||||
// for (i = 0; i < 2047; i++)
|
||||
// printf("00000000\n");
|
||||
// print_hex(output, sizeof(output), 0);
|
||||
FILE *infile = fopen("infile.txt", "w");
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user