xform: now works with "arbitrary" memory sizes
Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
c18eea9c62
commit
7d2f99e899
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
1536
memtest/mem.init
1536
memtest/mem.init
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@ -11,7 +11,7 @@ module memtest (
|
||||
input clki
|
||||
);
|
||||
|
||||
reg [31:0] mem[0:2047];
|
||||
reg [31:0] mem[0:511];
|
||||
reg [10:0] memadr;
|
||||
assign random_rom_dat_r = mem[memadr];
|
||||
|
||||
|
1466
memtest/top.rpt
1466
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
BIN
xform
BIN
xform
Binary file not shown.
68
xform.c
68
xform.c
@ -1,25 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <strings.h>
|
||||
|
||||
/*
|
||||
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
|
||||
|
||||
For mem = 65536 bits:
|
||||
bit 0 <- 0
|
||||
bit 1 <- 8192
|
||||
bit 2 <- 16384
|
||||
@ -36,6 +21,24 @@ bit 12 <- 40961
|
||||
bit 13 <- 1281
|
||||
bit 14 <- 49153
|
||||
bit 15 <- 57345
|
||||
|
||||
For mem = 32768 bits:
|
||||
bit 0 <- 0
|
||||
bit 1 <- 8192
|
||||
bit 2 <- 16384
|
||||
bit 3 <- 24576
|
||||
bit 4 <- 1
|
||||
bit 5 <- 8193
|
||||
bit 6 <- 16385
|
||||
bit 7 <- 24577
|
||||
bit 8 <- 2
|
||||
bit 9 <- 8194
|
||||
bit 10 <- 16386
|
||||
bit 11 <- 24578
|
||||
bit 12 <- 3
|
||||
bit 13 <- 8195
|
||||
bit 14 <- 16387
|
||||
bit 15 <- 24579
|
||||
*/
|
||||
|
||||
uint32_t xorshift32(uint32_t x)
|
||||
@ -95,16 +98,15 @@ static uint16_t reverse_u16(uint16_t nonreversed)
|
||||
return reversed;
|
||||
}
|
||||
|
||||
static uint32_t get_bit_offset(int bit) {
|
||||
return (8192 * (bit & 7)) + (bit >> 3);
|
||||
static uint32_t get_bit_offset(int x, int total_bits) {
|
||||
// return (8192 * (x & 7)) + (x >> 3);
|
||||
int bitshift = ffs(total_bits)-1;
|
||||
return ((x * 8192) % total_bits) + ((x*8192) >> bitshift);
|
||||
}
|
||||
|
||||
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};
|
||||
@ -127,23 +129,35 @@ int main(int argc, char **argv)
|
||||
// printf("test_4: bit %d set\n", i);
|
||||
// }
|
||||
|
||||
uint32_t input[2048] = {};
|
||||
uint32_t output[2048] = {};
|
||||
uint32_t input[512] = {};
|
||||
uint32_t output[512] = {};
|
||||
|
||||
for (i = 0; i < 32; i++) {
|
||||
printf("bit %d: %d\n", i, get_bit_offset(i, sizeof(input)*8));
|
||||
}
|
||||
|
||||
uint32_t init = 1;
|
||||
for (i = 0; i < sizeof(input) / 4; i++)
|
||||
{
|
||||
init = get_rand(init);
|
||||
input[i] = init;
|
||||
// input[i] = 0;
|
||||
}
|
||||
/*
|
||||
input[0] = 0xf0000000;
|
||||
input[256] = 0xf0000000;
|
||||
input[512] = 0xc0000000;
|
||||
input[768] = 0xc0000000;
|
||||
input[1024] = 0xc0000000;*/
|
||||
// print_hex(input, sizeof(input), 0);
|
||||
// return;
|
||||
// memset(input, 0xff, sizeof(input));
|
||||
|
||||
for (i = 0; i < sizeof(input) * 8; i++)
|
||||
{
|
||||
int bit;
|
||||
assert(get_bit_offset(i) < sizeof(output) * 8);
|
||||
bit = get_bit(input, get_bit_offset(i));
|
||||
assert(get_bit_offset(i, sizeof(output)*8) < sizeof(output) * 8);
|
||||
bit = get_bit(input, get_bit_offset(i, sizeof(input)*8));
|
||||
// bit = get_bit(input, i);
|
||||
// if (bit)
|
||||
// printf("bit %d is set\n", i);
|
||||
@ -189,7 +203,7 @@ int main(int argc, char **argv)
|
||||
// o16[i] = reverse_u16(o16[i]);
|
||||
|
||||
// print_hex(output, sizeof(output), 0);
|
||||
FILE *infile = fopen("infile.txt", "w");
|
||||
FILE *infile = fopen("memtest/mem.init", "w");
|
||||
FILE *outfile = fopen("outfile.txt", "w");
|
||||
for (i = 0; i < sizeof(input)/4; i++) {
|
||||
fprintf(infile, "%08x\n", input[i]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user