diff options
author | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2024-05-21 13:50:28 +0200 |
---|---|---|
committer | Flavian Kaufmann <flavian@flaviankaufmann.ch> | 2024-05-21 13:50:28 +0200 |
commit | cb0be9e2039569ee7d18657e8f675d1f8369b407 (patch) | |
tree | 91fa71b3960d1ad5217759371143efbdd833d475 /gentestvec/gentestvec_register_file.c | |
parent | 98d0dd96611dc2c0e444eaf9410f8adf2924c6b5 (diff) | |
download | riscv_cpu-cb0be9e2039569ee7d18657e8f675d1f8369b407.tar.gz riscv_cpu-cb0be9e2039569ee7d18657e8f675d1f8369b407.zip |
restructured project
Diffstat (limited to 'gentestvec/gentestvec_register_file.c')
-rw-r--r-- | gentestvec/gentestvec_register_file.c | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/gentestvec/gentestvec_register_file.c b/gentestvec/gentestvec_register_file.c deleted file mode 100644 index 5a50d9b..0000000 --- a/gentestvec/gentestvec_register_file.c +++ /dev/null @@ -1,49 +0,0 @@ -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <time.h> - -uint32_t registers[32]; - -uint32_t read_reg(uint32_t addr) { return addr == 0 ? 0 : registers[addr]; } - -void write_reg(uint32_t addr, uint32_t data, bool we) { - if (addr != 0 && we) - registers[addr] = data; -} - -void test(uint32_t addr_rs0, uint32_t addr_rs1, uint32_t addr_rd2, - uint32_t data_rd2, bool we) { - - write_reg(addr_rd2, data_rd2, we); - uint32_t data_rs0 = read_reg(addr_rs0); - uint32_t data_rs1 = read_reg(addr_rs1); - printf("%08X_%08X__%08X_%08X__%08X_%08X_%01X\n", addr_rs0, data_rs0, addr_rs1, - data_rs1, addr_rd2, data_rd2, we); -} - -void tests(int num) { - for (int i = 0; i < num; ++i) { - uint32_t addr_rs0 = ((uint32_t)((rand() << 16) | rand())) % 32; - uint32_t addr_rs1 = ((uint32_t)((rand() << 16) | rand())) % 32; - uint32_t addr_rd2 = ((uint32_t)((rand() << 16) | rand())) % 32; - uint32_t data_rd2 = ((uint32_t)((rand() << 16) | rand())); - bool we = ((uint32_t)rand()) % 2; - test(addr_rs0, addr_rs1, addr_rd2, data_rd2, we); - } -} - -int main(int argc, const char *argv[]) { - srand(time(NULL)); - for (int i = 0; i < 32; ++i) - registers[0] = 0; - - for (int i = 0; i < 32; ++i) - test(i, i, 0, 0, false); - - for (int i = 0; i < 32; ++i) - test(i, i, i, 0xffffffff, true); - - tests(10000); - return 0; -} |