aboutsummaryrefslogtreecommitdiff
path: root/tests/simple_mesh2d
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-08-09 17:20:05 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2025-08-09 17:20:05 +0300
commit1853f5d6594bc371e4d8e631c24acd011a620915 (patch)
tree1bfaabd3685d4eacc6595ee6836adddcc37ba841 /tests/simple_mesh2d
parent3083284c797fc8fc267144b05c8a58395e4583e3 (diff)
downloadgran-1853f5d6594bc371e4d8e631c24acd011a620915.tar.gz
gran-1853f5d6594bc371e4d8e631c24acd011a620915.zip
refactor mesh3d to match 2d,1d
Diffstat (limited to 'tests/simple_mesh2d')
-rw-r--r--tests/simple_mesh2d/sim.c80
-rw-r--r--tests/simple_mesh2d/test.c2
2 files changed, 44 insertions, 38 deletions
diff --git a/tests/simple_mesh2d/sim.c b/tests/simple_mesh2d/sim.c
index 1a9ba32..5afb1a7 100644
--- a/tests/simple_mesh2d/sim.c
+++ b/tests/simple_mesh2d/sim.c
@@ -18,8 +18,8 @@ static size_t idx_1d(int x, int y, uint8_t xw, uint8_t yw)
}
static struct component *mesh_at(struct component **mesh,
- int x, int y,
- uint8_t xw, uint8_t yw)
+ int x, int y,
+ uint8_t xw, uint8_t yw)
{
if (x < 0)
return NULL;
@@ -37,13 +37,17 @@ static struct component *mesh_at(struct component **mesh,
}
static void connect_mesh(struct component **mesh, struct component *c,
- uint16_t x, uint16_t y,
- uint16_t xw, uint16_t yw)
+ uint16_t x, uint16_t y,
+ uint16_t xw, uint16_t yw)
{
- mesh_node2d_connect_north(mesh_at(mesh, x, y, xw, yw), mesh_at(mesh, x , y+1, xw, yw));
- mesh_node2d_connect_south(mesh_at(mesh, x, y, xw, yw), mesh_at(mesh, x , y-1, xw, yw));
- mesh_node2d_connect_east(mesh_at(mesh, x, y, xw, yw), mesh_at(mesh, x+1, y , xw, yw));
- mesh_node2d_connect_west(mesh_at(mesh, x, y, xw, yw), mesh_at(mesh, x-1, y , xw, yw));
+ mesh_node2d_connect_north(mesh_at(mesh, x, y, xw, yw),
+ mesh_at(mesh, x, y+1, xw, yw));
+ mesh_node2d_connect_south(mesh_at(mesh, x, y, xw, yw),
+ mesh_at(mesh, x, y-1, xw, yw));
+ mesh_node2d_connect_east(mesh_at(mesh, x, y, xw, yw),
+ mesh_at(mesh, x+1, y, xw, yw));
+ mesh_node2d_connect_west(mesh_at(mesh, x, y, xw, yw),
+ mesh_at(mesh, x-1, y, xw, yw));
mesh_node2d_connect(mesh_at(mesh, x, y, xw, yw), c, 0);
}
@@ -56,34 +60,36 @@ static stat build_mesh(struct clock_domain *clk, uint16_t x, uint16_t y)
assert(pes);
for (size_t i = 0; i < x; ++i)
- for (size_t j = 0; j < y; ++j) {
- struct component *node = create_mesh_node2d(i, j, 1);
- clock_domain_add(clk, node);
- mesh[idx_1d(i, j, x, y)] = node;
+ for (size_t j = 0; j < y; ++j) {
+ struct component *node = create_mesh_node2d(i, j, 1);
+ clock_domain_add(clk, node);
+ mesh[idx_1d(i, j, x, y)] = node;
- if (i == 0 && j == 0)
- continue;
+ if (i == 0 && j == 0)
+ continue;
- if (i == 0 && j == 1)
- continue;
+ if (i == 0 && j == 1)
+ continue;
- struct component *imem = create_simple_mem(4096);
- init_simple_mem(imem, 0,
- build_tests_simple_mesh2d_test_bin_len,
- build_tests_simple_mesh2d_test_bin);
+ struct component *imem = create_simple_mem(4096);
+ init_simple_mem(imem, 0,
+ build_tests_simple_mesh2d_test_bin_len,
+ build_tests_simple_mesh2d_test_bin);
- uint64_t rcv = mesh2d_addr(i, j, 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 */
- simple_riscv64_set_reg(rv64, 12, x); /* a3 */
- simple_riscv64_set_reg(rv64, 13, y); /* a4 */
+ uint64_t rcv = mesh2d_addr(i, j, 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 */
+ simple_riscv64_set_reg(rv64, 12, x); /* a3 */
+ simple_riscv64_set_reg(rv64, 13, y); /* a4 */
- 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, x, y)] = rv64;
- }
+ pes[idx_1d(i, j, x, y)] = rv64;
+ }
struct component *uart = create_simple_uart();
clock_domain_add(clk, uart);
@@ -94,15 +100,15 @@ static stat build_mesh(struct clock_domain *clk, uint16_t x, uint16_t y)
connect_mesh(mesh, dmem, 0, 1, x, y);
for (int i = 0; i < x; ++i)
- for (int j = 0; j < y; ++j) {
- if (i == 0 && j == 0)
- continue;
+ for (int j = 0; j < y; ++j) {
+ if (i == 0 && j == 0)
+ continue;
- if (i == 0 && j == 1)
- continue;
+ if (i == 0 && j == 1)
+ continue;
- connect_mesh(mesh, pes[idx_1d(i, j, x, y)], i, j, x, y);
- }
+ connect_mesh(mesh, pes[idx_1d(i, j, x, y)], i, j, x, y);
+ }
free(mesh);
free(pes);
diff --git a/tests/simple_mesh2d/test.c b/tests/simple_mesh2d/test.c
index d607a59..431245c 100644
--- a/tests/simple_mesh2d/test.c
+++ b/tests/simple_mesh2d/test.c
@@ -48,7 +48,7 @@ do_work:
*control = next_idx(x, y, X, Y);
if (x == X - 1 && y == Y - 1)
- asm("ebreak");
+ asm ("ebreak");
/* otherwise just loop */
while (1) {}