aboutsummaryrefslogtreecommitdiff
path: root/tests/simple_grid3d
diff options
context:
space:
mode:
Diffstat (limited to 'tests/simple_grid3d')
-rw-r--r--tests/simple_grid3d/sim.c142
-rw-r--r--tests/simple_grid3d/source.mk18
-rw-r--r--tests/simple_grid3d/test.c61
3 files changed, 0 insertions, 221 deletions
diff --git a/tests/simple_grid3d/sim.c b/tests/simple_grid3d/sim.c
deleted file mode 100644
index 6df29dd..0000000
--- a/tests/simple_grid3d/sim.c
+++ /dev/null
@@ -1,142 +0,0 @@
-#include <assert.h>
-
-#include <gran/root.h>
-#include <gran/mem/simple_mem.h>
-#include <gran/bus/simple_bus.h>
-#include <gran/uart/simple_uart.h>
-#include <gran/grid/node3d.h>
-#include <gran/cpu/riscv/simple_riscv64.h>
-
-#include "../build/tests/simple_grid3d/test.inc"
-
-static size_t idx_1d(int x, int y, int z, uint8_t xw, uint8_t yw, uint8_t zw)
-{
- (void)xw; /* maybe unused */
- assert(0 <= x && x < xw);
- assert(0 <= y && y < yw);
- assert(0 <= z && z < zw);
- return (x * yw * zw) + (y * zw) + z;
-}
-
-static struct component *grid_at(struct component **grid,
- int x, int y, int z,
- uint8_t xw, uint8_t yw, uint8_t zw)
-{
- if (x < 0)
- return NULL;
-
- if (y < 0)
- return NULL;
-
- if (z < 0)
- return NULL;
-
- if (x >= xw)
- return NULL;
-
- if (y >= yw)
- return NULL;
-
- if (z >= zw)
- return NULL;
-
- return grid[idx_1d(x, y, z, xw, yw, zw)];
-}
-
-static void connect_grid3d(struct component **grid, struct component *c,
- uint8_t x, uint8_t y, uint8_t z,
- uint8_t xw, uint8_t yw, uint8_t zw)
-{
- grid_node3d_connect(grid_at(grid, x, y, z, xw, yw, zw),
- grid_at(grid, x , y+1, z , xw, yw, zw),
- grid_at(grid, x , y-1, z , xw, yw, zw),
- grid_at(grid, x-1, y , z , xw, yw, zw),
- grid_at(grid, x+1, y , z , xw, yw, zw),
- grid_at(grid, x , y , z+1, xw, yw, zw),
- grid_at(grid, x , y , z-1, xw, yw, zw),
- c);
-}
-
-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);
-
- struct component **pes = calloc(x * y * z, sizeof(struct component *));
- 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_grid_node3d(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 == 1)
- continue;
-
- struct component *imem = create_simple_mem(4096);
- init_simple_mem(imem, 0,
- build_tests_simple_grid3d_test_bin_len,
- build_tests_simple_grid3d_test_bin);
-
- uint64_t rcv = grid3d_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);
-
- pes[idx_1d(i, j, k, x, y, z)] = rv64;
- }
-
- struct component *uart = create_simple_uart();
- clock_domain_add(clk, uart);
- connect_grid3d(grid, uart, 0, 0, 0, x, y, z);
-
- struct component *dmem = create_simple_mem(4096);
- clock_domain_add(clk, dmem);
- connect_grid3d(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;
-
- if (i == 0 && j == 0 && k == 1)
- continue;
-
- connect_grid3d(grid,
- pes[idx_1d(i, j, k, x, y, z)],
- i, j, k, x, y, z);
- }
-
- free(grid);
- free(pes);
- return OK;
-}
-
-int main()
-{
- struct clock_domain *clk = create_clock_domain(NS(1));
-
- stat r = build_torus3d(clk, 4, 4, 4);
- assert(r == OK);
-
- struct gran_root *root = create_root();
- root_add_clock(root, clk);
-
- r = root_run(root);
- assert(r == OK);
-
- destroy_root(root);
-}
diff --git a/tests/simple_grid3d/source.mk b/tests/simple_grid3d/source.mk
deleted file mode 100644
index 4c19568..0000000
--- a/tests/simple_grid3d/source.mk
+++ /dev/null
@@ -1,18 +0,0 @@
-GRID3D_TEST_OBJ != ./scripts/gen-deps --sources "tests/simple_grid3d/sim.c"
-TEST_PROGS += build/tests/simple_grid3d/sim
-
-build/tests/simple_grid3d/test.inc: tests/simple_grid3d/test.c
- riscv64-unknown-elf-gcc -O2 -Wall -Wextra -ffreestanding -nostdlib \
- -march=rv64i -mabi=lp64 \
- -o build/tests/simple_grid3d/test \
- tests/simple_grid3d/test.c
- riscv64-unknown-elf-objcopy -Obinary \
- build/tests/simple_grid3d/test \
- build/tests/simple_grid3d/test.bin
- xxd -i build/tests/simple_grid3d/test.bin \
- > build/tests/simple_grid3d/test.inc
-
-build/tests/simple_grid3d/sim.o: build/tests/simple_grid3d/test.inc
-
-build/tests/simple_grid3d/sim: $(GRID3D_TEST_OBJ) $(OBJS)
- $(COMPILE) $(GRID3D_TEST_OBJ) $(OBJS) -o $@
diff --git a/tests/simple_grid3d/test.c b/tests/simple_grid3d/test.c
deleted file mode 100644
index 2953d41..0000000
--- a/tests/simple_grid3d/test.c
+++ /dev/null
@@ -1,61 +0,0 @@
-__attribute__((always_inline))
-static inline void print_int8(volatile char *uart, unsigned x)
-{
- *uart = ((x >> 4) & 0xf) + '0';
- *uart = ((x >> 0) & 0xf) + '0';
-}
-
-__attribute__((always_inline))
-static inline void print_addr(volatile char *uart, unsigned x, unsigned y, unsigned z)
-{
- *uart = '(';
- print_int8(uart, x);
- *uart = ',';
- *uart = ' ';
- print_int8(uart, y);
- *uart = ',';
- *uart = ' ';
- print_int8(uart, z);
- *uart = ')';
- *uart = '\n';
-}
-
-__attribute__((always_inline))
-static inline unsigned wrap(unsigned x, unsigned X)
-{
- return x + 1 >= X ? 0 : x + 1;
-}
-
-__attribute__((always_inline))
-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;
- unsigned xi = yi < y ? wrap(x, X) : x;
-
- return (xi << 16) | (yi << 8) | zi;
-}
-
-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 */
- volatile unsigned *control = (unsigned *)(1ULL << 48);
-
-
- if (x == 0 && y == 0 && z == 2) {
- goto do_work;
- } else {
- while (*control != ((x << 16) | (y << 8) | z)) {}
- }
-
-do_work:
- print_addr(uart, x, y, z);
- *control = next_idx(x, y, z, X, Y, Z);
-
- if (x == X - 1 && y == Y - 1 && z == Z - 1)
- asm("ebreak");
-
- /* otherwise just loop */
- while (1) {}
-}