diff options
Diffstat (limited to 'tests/simple_torus3d')
| -rw-r--r-- | tests/simple_torus3d/sim.c | 96 | ||||
| -rw-r--r-- | tests/simple_torus3d/test.c | 11 |
2 files changed, 59 insertions, 48 deletions
diff --git a/tests/simple_torus3d/sim.c b/tests/simple_torus3d/sim.c index b3ff41b..c996c42 100644 --- a/tests/simple_torus3d/sim.c +++ b/tests/simple_torus3d/sim.c @@ -18,20 +18,21 @@ static size_t idx_1d(int x, int y, int z, uint8_t xw, uint8_t yw, uint8_t zw) } static void torus3d_connect_grid(struct component **grid, struct component *c, - uint8_t x, uint8_t y, uint8_t z, - uint8_t xw, uint8_t yw, uint8_t zw) + uint8_t x, uint8_t y, uint8_t z, + uint8_t xw, uint8_t yw, uint8_t zw) { torus3d_node_connect(grid[idx_1d(x, y, z, xw, yw, zw)], - grid[idx_1d(x-1, y , z , xw, yw, zw)], - grid[idx_1d(x , y-1, z , xw, yw, zw)], - grid[idx_1d(x , y , z-1, xw, yw, zw)], - c, - grid[idx_1d(x+1, y , z , xw, yw, zw)], - grid[idx_1d(x , y+1, z , xw, yw, zw)], - grid[idx_1d(x , y , z+1, xw, yw, zw)]); + grid[idx_1d(x-1, y, z, xw, yw, zw)], + grid[idx_1d(x, y-1, z, xw, yw, zw)], + grid[idx_1d(x, y, z-1, xw, yw, zw)], + c, + grid[idx_1d(x+1, y, z, xw, yw, zw)], + grid[idx_1d(x, y+1, z, xw, yw, zw)], + grid[idx_1d(x, y, z+1, xw, yw, zw)]); } -static stat build_torus3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_t z) +static stat build_torus3d(struct clock_domain *clk, uint8_t x, uint8_t y, + uint8_t z) { struct component **grid = calloc(x * y * z, sizeof(struct component *)); assert(grid); @@ -40,37 +41,42 @@ static stat build_torus3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_ assert(pes); for (size_t i = 0; i < x; ++i) - for (size_t j = 0; j < y; ++j) - for (size_t k = 0; k < z; ++k) { - struct component *node = create_torus3d_node(i, j, k); - clock_domain_add(clk, node); - grid[idx_1d(i, j, k, x, y, z)] = node; + for (size_t j = 0; j < y; ++j) + for (size_t k = 0; k < z; ++k) { + struct component *node = create_torus3d_node(i, + j, + k); + clock_domain_add(clk, node); + grid[idx_1d(i, j, k, x, y, z)] = node; - if (i == 0 && j == 0 && k == 0) - continue; + if (i == 0 && j == 0 && k == 0) + continue; - if (i == 0 && j == 0 && k == 1) - continue; + if (i == 0 && j == 0 && k == 1) + continue; - struct component *imem = create_simple_mem(4096); - init_simple_mem(imem, 0, - build_tests_simple_torus3d_test_bin_len, - build_tests_simple_torus3d_test_bin); + struct component *imem = + create_simple_mem(4096); + init_simple_mem(imem, 0, + build_tests_simple_torus3d_test_bin_len, + build_tests_simple_torus3d_test_bin); - uint64_t rcv = torus3d_addr(i, j, k, 0); - struct component *rv64 = create_simple_riscv64(rcv, 0, imem, node); - simple_riscv64_set_reg(rv64, 10, i); /* a0 */ - simple_riscv64_set_reg(rv64, 11, j); /* a1 */ - simple_riscv64_set_reg(rv64, 12, k); /* a2 */ - simple_riscv64_set_reg(rv64, 13, x); /* a3 */ - simple_riscv64_set_reg(rv64, 14, y); /* a4 */ - simple_riscv64_set_reg(rv64, 15, z); /* a5 */ + uint64_t rcv = torus3d_addr(i, j, k, 0); + struct component *rv64 = + create_simple_riscv64(rcv, 0, imem, + node); + simple_riscv64_set_reg(rv64, 10, i); /* a0 */ + simple_riscv64_set_reg(rv64, 11, j); /* a1 */ + simple_riscv64_set_reg(rv64, 12, k); /* a2 */ + simple_riscv64_set_reg(rv64, 13, x); /* a3 */ + simple_riscv64_set_reg(rv64, 14, y); /* a4 */ + simple_riscv64_set_reg(rv64, 15, z); /* a5 */ - clock_domain_add(clk, rv64); - clock_domain_add(clk, imem); + clock_domain_add(clk, rv64); + clock_domain_add(clk, imem); - pes[idx_1d(i, j, k, x, y, z)] = rv64; - } + pes[idx_1d(i, j, k, x, y, z)] = rv64; + } struct component *uart = create_simple_uart(); clock_domain_add(clk, uart); @@ -81,17 +87,19 @@ static stat build_torus3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_ torus3d_connect_grid(grid, dmem, 0, 0, 1, x, y, z); for (int i = 0; i < x; ++i) - for (int j = 0; j < y; ++j) - for (int k = 0; k < z; ++k) { - if (i == 0 && j == 0 && k == 0) - continue; + for (int j = 0; j < y; ++j) + for (int k = 0; k < z; ++k) { + if (i == 0 && j == 0 && k == 0) + continue; - if (i == 0 && j == 0 && k == 1) - continue; + if (i == 0 && j == 0 && k == 1) + continue; - torus3d_connect_grid(grid, pes[idx_1d(i, j, k, x, y, z)], - i, j, k, x, y, z); - } + torus3d_connect_grid(grid, + pes[idx_1d(i, j, k, x, y, + z)], + i, j, k, x, y, z); + } free(grid); free(pes); diff --git a/tests/simple_torus3d/test.c b/tests/simple_torus3d/test.c index 2953d41..646b387 100644 --- a/tests/simple_torus3d/test.c +++ b/tests/simple_torus3d/test.c @@ -6,7 +6,8 @@ static inline void print_int8(volatile char *uart, unsigned x) } __attribute__((always_inline)) -static inline void print_addr(volatile char *uart, unsigned x, unsigned y, unsigned z) +static inline void print_addr(volatile char *uart, unsigned x, unsigned y, + unsigned z) { *uart = '('; print_int8(uart, x); @@ -27,7 +28,8 @@ static inline unsigned wrap(unsigned x, unsigned X) } __attribute__((always_inline)) -static inline unsigned next_idx(unsigned x, unsigned y, unsigned z, unsigned X, unsigned Y, unsigned Z) +static inline unsigned next_idx(unsigned x, unsigned y, unsigned z, unsigned X, + unsigned Y, unsigned Z) { unsigned zi = wrap(z, Z); unsigned yi = zi < z ? wrap(y, Y) : y; @@ -36,7 +38,8 @@ static inline unsigned next_idx(unsigned x, unsigned y, unsigned z, unsigned X, return (xi << 16) | (yi << 8) | zi; } -void _start(unsigned x, unsigned y, unsigned z, unsigned X, unsigned Y, unsigned Z) +void _start(unsigned x, unsigned y, unsigned z, unsigned X, unsigned Y, + unsigned Z) { volatile char *uart = (char *)4096; /* x = 1ULL << 32, y = 1ULL << 40, z = 1ULL << 48 I guess */ @@ -54,7 +57,7 @@ do_work: *control = next_idx(x, y, z, X, Y, Z); if (x == X - 1 && y == Y - 1 && z == Z - 1) - asm("ebreak"); + asm ("ebreak"); /* otherwise just loop */ while (1) {} |
