diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-08-09 17:20:05 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-08-09 17:20:05 +0300 |
| commit | 1853f5d6594bc371e4d8e631c24acd011a620915 (patch) | |
| tree | 1bfaabd3685d4eacc6595ee6836adddcc37ba841 /tests/simple_mesh3d | |
| parent | 3083284c797fc8fc267144b05c8a58395e4583e3 (diff) | |
| download | gran-1853f5d6594bc371e4d8e631c24acd011a620915.tar.gz gran-1853f5d6594bc371e4d8e631c24acd011a620915.zip | |
refactor mesh3d to match 2d,1d
Diffstat (limited to 'tests/simple_mesh3d')
| -rw-r--r-- | tests/simple_mesh3d/sim.c | 35 | ||||
| -rw-r--r-- | tests/simple_mesh3d/test.c | 14 |
2 files changed, 25 insertions, 24 deletions
diff --git a/tests/simple_mesh3d/sim.c b/tests/simple_mesh3d/sim.c index 9557d83..f5d6244 100644 --- a/tests/simple_mesh3d/sim.c +++ b/tests/simple_mesh3d/sim.c @@ -19,8 +19,8 @@ static size_t idx_1d(int x, int y, int z, uint8_t xw, uint8_t yw, uint8_t zw) } static struct component *mesh_at(struct component **mesh, - int x, int y, int z, - uint8_t xw, uint8_t yw, uint8_t zw) + int x, int y, int z, + uint8_t xw, uint8_t yw, uint8_t zw) { if (x < 0) return NULL; @@ -44,20 +44,21 @@ static struct component *mesh_at(struct component **mesh, } static void connect_mesh3d(struct component **mesh, 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) { - mesh_node3d_connect(mesh_at(mesh, x, y, z, xw, yw, zw), - mesh_at(mesh, x , y+1, z , xw, yw, zw), - mesh_at(mesh, x , y-1, z , xw, yw, zw), - mesh_at(mesh, x+1, y , z , xw, yw, zw), - mesh_at(mesh, x-1, y , z , xw, yw, zw), - mesh_at(mesh, x , y , z+1, xw, yw, zw), - mesh_at(mesh, x , y , z-1, xw, yw, zw), - c); + struct component *n = mesh_at(mesh, x, y, z, xw, yw, zw); + mesh_node3d_connect(n, c, 0); + mesh_node3d_connect_north(n, mesh_at(mesh, x, y+1, z, xw, yw, zw)); + mesh_node3d_connect_south(n, mesh_at(mesh, x, y-1, z, xw, yw, zw)); + mesh_node3d_connect_east(n, mesh_at(mesh, x+1, y, z, xw, yw, zw)); + mesh_node3d_connect_west(n, mesh_at(mesh, x-1, y, z, xw, yw, zw)); + mesh_node3d_connect_down(n, mesh_at(mesh, x, y, z-1, xw, yw, zw)); + mesh_node3d_connect_up(n, mesh_at(mesh, x, y, z+1, xw, yw, zw)); } -static stat build_mesh3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_t z) +static stat build_mesh3d(struct clock_domain *clk, uint8_t x, uint8_t y, + uint8_t z) { struct component **mesh = calloc(x * y * z, sizeof(struct component *)); assert(mesh); @@ -68,7 +69,7 @@ static stat build_mesh3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_t 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_mesh_node3d(i, j, k); + struct component *node = create_mesh_node3d(i, j, k, 1); clock_domain_add(clk, node); mesh[idx_1d(i, j, k, x, y, z)] = node; @@ -83,7 +84,7 @@ static stat build_mesh3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_t build_tests_simple_mesh3d_test_bin_len, build_tests_simple_mesh3d_test_bin); - uint64_t rcv = mesh3d_addr(i, j, k, 0); + uint64_t rcv = mesh3d_addr(i, j, k, 0, 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 */ @@ -115,9 +116,7 @@ static stat build_mesh3d(struct clock_domain *clk, uint8_t x, uint8_t y, uint8_t if (i == 0 && j == 0 && k == 1) continue; - connect_mesh3d(mesh, - pes[idx_1d(i, j, k, x, y, z)], - i, j, k, x, y, z); + connect_mesh3d(mesh, pes[idx_1d(i, j, k, x, y, z)], i, j, k, x, y, z); } free(mesh); diff --git a/tests/simple_mesh3d/test.c b/tests/simple_mesh3d/test.c index 2953d41..e00e717 100644 --- a/tests/simple_mesh3d/test.c +++ b/tests/simple_mesh3d/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,11 +38,11 @@ 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 */ - volatile unsigned *control = (unsigned *)(1ULL << 48); + volatile unsigned *control = (unsigned *)(1ULL << 56); if (x == 0 && y == 0 && z == 2) { @@ -54,7 +56,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) {} |
