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 | |
| parent | 3083284c797fc8fc267144b05c8a58395e4583e3 (diff) | |
| download | gran-1853f5d6594bc371e4d8e631c24acd011a620915.tar.gz gran-1853f5d6594bc371e4d8e631c24acd011a620915.zip | |
refactor mesh3d to match 2d,1d
| -rw-r--r-- | include/gran/common.h | 24 | ||||
| -rw-r--r-- | include/gran/mesh/node1d.h | 14 | ||||
| -rw-r--r-- | include/gran/mesh/node2d.h | 17 | ||||
| -rw-r--r-- | include/gran/mesh/node3d.h | 39 | ||||
| -rw-r--r-- | src/common.c | 45 | ||||
| -rw-r--r-- | src/mesh/node.c | 0 | ||||
| -rw-r--r-- | src/mesh/node1d.c | 232 | ||||
| -rw-r--r-- | src/mesh/node2d.c | 87 | ||||
| -rw-r--r-- | src/mesh/node3d.c | 364 | ||||
| -rw-r--r-- | tests/simple_mesh1d/sim.c | 11 | ||||
| -rw-r--r-- | tests/simple_mesh1d/test.c | 13 | ||||
| -rw-r--r-- | tests/simple_mesh2d/sim.c | 80 | ||||
| -rw-r--r-- | tests/simple_mesh2d/test.c | 2 | ||||
| -rw-r--r-- | tests/simple_mesh3d/sim.c | 35 | ||||
| -rw-r--r-- | tests/simple_mesh3d/test.c | 14 |
15 files changed, 507 insertions, 470 deletions
diff --git a/include/gran/common.h b/include/gran/common.h index b71417d..43814cd 100644 --- a/include/gran/common.h +++ b/include/gran/common.h @@ -5,6 +5,10 @@ #define GRAN_COMMON_H #include <stdio.h> +#include <stdlib.h> +#include <stddef.h> +#include <stdbool.h> +#include "packet.h" typedef enum { OK = 0, @@ -34,4 +38,24 @@ typedef enum { #define debug(x, ...) #endif +struct reg { + struct packet pkt; + bool busy; +}; + +/* Places \p pkt into \p r if \r is not busy. Returns EBUSY if register was + * busy, otherwise OK. */ +stat place_reg(struct reg *r, struct packet pkt); + +/* If \p is free, copies packet from \p s to \p r, marking each correspondigly + * free/busy. Returns EBUSY if \r was busy, otherwise OK. */ +stat copy_reg(struct reg *r, struct reg *s); + +/* For each register in \p in, calls \p sel to check if packet in registers + * should be moved to \p out. If there are multiple available registers, oldest + * one is selected. NULL entries in \p in are tolerated. */ +void propagate(struct reg *out, + size_t count, struct reg *in[static count], + bool (*sel)(struct reg *r, void *data), void *data); + #endif /* GRAN_COMMON_H */ diff --git a/include/gran/mesh/node1d.h b/include/gran/mesh/node1d.h index 6c8151e..37702ba 100644 --- a/include/gran/mesh/node1d.h +++ b/include/gran/mesh/node1d.h @@ -5,18 +5,22 @@ #include <gran/component.h> struct component *create_mesh_node1d(uint16_t cluster, uint16_t elems); -stat mesh_node1d_connect(struct component *node1d, struct component *component, uint16_t elem); -stat mesh_node1d_connect_left(struct component *node1d, struct component *left); -stat mesh_node1d_connect_right(struct component *node1d, struct component *right); +stat mesh_node1d_connect(struct component *node1d, struct component *component, + uint16_t elem); -static inline void addr_mesh1d(uint64_t addr, uint16_t *cluster, uint16_t *elem, uint32_t *off) +stat mesh_node1d_connect_north(struct component *c, struct component *e); +stat mesh_node1d_connect_south(struct component *c, struct component *e); + +static inline void addr_mesh1d(uint64_t addr, uint16_t *cluster, uint16_t *elem, + uint32_t *off) { if (off) *off = addr & 0xffffffff; if (elem) *elem = (addr >> 32) & 0xffff; if (cluster) *cluster = (addr >> 48) & 0xffff; } -static inline uint64_t mesh1d_addr(uint16_t cluster, uint16_t elem, uint32_t off) +static inline uint64_t mesh1d_addr(uint16_t cluster, uint16_t elem, + uint32_t off) { return ((uint64_t)cluster << 48) | ((uint64_t)elem << 32) | off; } diff --git a/include/gran/mesh/node2d.h b/include/gran/mesh/node2d.h index fe43e59..bf096c3 100644 --- a/include/gran/mesh/node2d.h +++ b/include/gran/mesh/node2d.h @@ -6,22 +6,25 @@ struct component *create_mesh_node2d(uint8_t x, uint8_t y, uint16_t elems); -stat mesh_node2d_connect(struct component *c, struct component *e, uint16_t elem); +stat mesh_node2d_connect(struct component *c, struct component *e, + uint16_t elem); stat mesh_node2d_connect_north(struct component *c, struct component *e); stat mesh_node2d_connect_south(struct component *c, struct component *e); stat mesh_node2d_connect_east(struct component *c, struct component *e); stat mesh_node2d_connect_west(struct component *c, struct component *e); -static inline uint64_t mesh2d_addr(uint8_t x, uint8_t y, uint16_t elem, uint32_t off) +static inline uint64_t mesh2d_addr(uint8_t x, uint8_t y, uint16_t elem, + uint32_t off) { return off - | ((uint64_t)elem << 32) - | ((uint64_t)x << 48) - | ((uint64_t)y << 56) - ; + | ((uint64_t)elem << 32) + | ((uint64_t)x << 48) + | ((uint64_t)y << 56) + ; } -static inline void addr_mesh2d(uint64_t addr, uint8_t *x, uint8_t *y, uint16_t *elem, uint32_t *off) +static inline void addr_mesh2d(uint64_t addr, uint8_t *x, uint8_t *y, + uint16_t *elem, uint32_t *off) { if (off) *off = addr & 0xffffffff; if (elem) *elem = (addr >> 32) & 0xffff; diff --git a/include/gran/mesh/node3d.h b/include/gran/mesh/node3d.h index 4f1c2c7..5b1a2fd 100644 --- a/include/gran/mesh/node3d.h +++ b/include/gran/mesh/node3d.h @@ -4,33 +4,34 @@ #include <gran/component.h> #include <stdint.h> -struct component *create_mesh_node3d(uint8_t x, uint8_t y, uint8_t z); +struct component *create_mesh_node3d(uint8_t x, uint8_t y, uint8_t z, uint8_t elem); -stat mesh_node3d_connect(struct component *node, - struct component *n, - struct component *s, - struct component *e, - struct component *w, - struct component *u, - struct component *d, - struct component *l); +stat mesh_node3d_connect(struct component *c, struct component *e, uint8_t elem); +stat mesh_node3d_connect_north(struct component *c, struct component *e); +stat mesh_node3d_connect_south(struct component *c, struct component *e); +stat mesh_node3d_connect_east(struct component *c, struct component *e); +stat mesh_node3d_connect_west(struct component *c, struct component *e); +stat mesh_node3d_connect_down(struct component *c, struct component *e); +stat mesh_node3d_connect_up(struct component *c, struct component *e); -static inline uint64_t mesh3d_addr(uint8_t x, uint8_t y, uint8_t z, uint32_t off) +static inline uint64_t mesh3d_addr(uint8_t x, uint8_t y, uint8_t z, uint8_t elem, + uint32_t off) { return off - | ((uint64_t)x << 32) - | ((uint64_t)y << 40) - | ((uint64_t)z << 48) - ; + | ((uint64_t)elem << 32) + | ((uint64_t)x << 40) + | ((uint64_t)y << 48) + | ((uint64_t)z << 56) + ; } -static inline void addr_mesh3d(uint64_t addr, uint8_t *x, uint8_t *y, uint8_t *z, uint32_t *off) +static inline void addr_mesh3d(uint64_t addr, uint8_t *x, uint8_t *y, uint8_t *z, uint8_t *elem, uint32_t *off) { if (off) *off = addr & 0xffffffff; - if (x) *x = (addr >> 32) & 0xff; - if (y) *y = (addr >> 40) & 0xff; - if (z) *z = (addr >> 48) & 0xff; - assert(((addr >> 56) & 0xff) == 0); + if (elem) *elem = (addr >> 32) & 0xff; + if (x) *x = (addr >> 40) & 0xff; + if (y) *y = (addr >> 48) & 0xff; + if (z) *z = (addr >> 56) & 0xff; } #endif /* GRAN_GRID_NODE3D_H */ diff --git a/src/common.c b/src/common.c new file mode 100644 index 0000000..41bd145 --- /dev/null +++ b/src/common.c @@ -0,0 +1,45 @@ +#include <gran/common.h> + +stat place_reg(struct reg *r, struct packet pkt) +{ + if (r->busy) + return EBUSY; + + r->pkt = pkt; + r->busy = true; + return OK; +} + +stat copy_reg(struct reg *r, struct reg *s) +{ + assert(s->busy); + if (r->busy) + return EBUSY; + + r->pkt = s->pkt; + r->busy = true; + s->busy = false; + return OK; +} + +void propagate(struct reg *out, + size_t count, struct reg *in[static count], + bool (*sel)(struct reg *r, void *data), void *data) +{ + struct reg *r = NULL; + for (size_t i = 0; i < count; ++i) { + if (!in[i] || !in[i]->busy) + continue; + + if (!sel(in[i], data)) + continue; + + if (!r || r->pkt.timestamp > in[i]->pkt.timestamp) + r = in[i]; + } + + if (!r) + return; + + copy_reg(out, r); +} diff --git a/src/mesh/node.c b/src/mesh/node.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/mesh/node.c diff --git a/src/mesh/node1d.c b/src/mesh/node1d.c index 23ba2ca..5a3cb06 100644 --- a/src/mesh/node1d.c +++ b/src/mesh/node1d.c @@ -1,18 +1,13 @@ #include <gran/mesh/node1d.h> -#define left_port(n) (n)->ports[(n)->elems + 0] -#define right_port(n) (n)->ports[(n)->elems + 1] +#define north_port(n) (n)->ports[(n)->elems + 0] +#define south_port(n) (n)->ports[(n)->elems + 1] -#define left_in(n) (n)->in[(n)->elems + 0] -#define right_in(n) (n)->in[(n)->elems + 1] +#define north_in(n) (n)->in[(n)->elems + 0] +#define south_in(n) (n)->in[(n)->elems + 1] -#define left_out(n) (n)->out[(n)->elems + 0] -#define right_out(n) (n)->out[(n)->elems + 1] - -struct reg { - struct packet pkt; - bool busy; -}; +#define north_out(n) (n)->out[(n)->elems + 0] +#define south_out(n) (n)->out[(n)->elems + 1] struct node1d { struct component component; @@ -31,31 +26,11 @@ static void node1d_destroy(struct node1d *n) free(n->in); free(n->out); free(n->ports); + free(n); } -static stat reg_busy(struct reg *r, struct packet pkt) -{ - bool busy = r->busy; - if (!busy) { - r->pkt = pkt; - r->busy = true; - } - - return busy ? EBUSY : OK; -} - -static void copy_reg(struct reg *r, struct reg *s) -{ - assert(s->busy); - if (r->busy) - return; - - r->pkt = s->pkt; - r->busy = true; - s->busy = false; -} - -static stat node1d_receive(struct node1d *n, struct component *from, struct packet pkt) +static stat node1d_receive(struct node1d *n, struct component *from, + struct packet pkt) { for (int i = 0; i < n->elems + 2; ++i) { /* add timestamp to packets that originate with us */ @@ -63,7 +38,7 @@ static stat node1d_receive(struct node1d *n, struct component *from, struct pack pkt.timestamp = n->timestamp; if (from == n->ports[i]) - return reg_busy(&n->in[i], pkt); + return place_reg(&n->in[i], pkt); } /* shouldn't be possible */ @@ -85,139 +60,37 @@ static void clock_outputs(struct node1d *n) } } -static void propagate_left(struct node1d *n, struct reg *a, struct reg *b) -{ - struct reg *sel_a = NULL, *sel_b = NULL; - if (a && a->busy) { - uint16_t cluster = 0; - addr_mesh1d(a->pkt.to, &cluster, NULL, NULL); - - if (cluster > n->cluster) - sel_a = a; - } - - if (b && b->busy) { - uint16_t cluster = 0; - addr_mesh1d(b->pkt.to, &cluster, NULL, NULL); - - if (cluster > n->cluster) - sel_b = b; - } - - if (!sel_a && !sel_b) - return; - - if (sel_a && !sel_b) { - copy_reg(&left_out(n), sel_a); - return; - } - - if (!sel_a && sel_b) { - copy_reg(&left_out(n), sel_b); - return; - } +struct sel_helper { + uint16_t cluster, elem; +}; - /* both available, select older */ - if (sel_a->pkt.timestamp < sel_b->pkt.timestamp) - copy_reg(&left_out(n), sel_a); - else - copy_reg(&left_out(n), sel_b); +static bool north_sel(struct reg *r, void *data) +{ + uint16_t cluster = 0; + struct sel_helper *helper = data; + addr_mesh1d(r->pkt.to, &cluster, NULL, NULL); + return cluster > helper->cluster; } -static void propagate_right(struct node1d *n, struct reg *a, struct reg *b) +static bool south_sel(struct reg *r, void *data) { - struct reg *sel_a = NULL, *sel_b = NULL; - if (a && a->busy) { - uint16_t cluster = 0; - addr_mesh1d(a->pkt.to, &cluster, NULL, NULL); - - if (cluster < n->cluster) - sel_a = a; - } - - if (b && b->busy) { - uint16_t cluster = 0; - addr_mesh1d(b->pkt.to, &cluster, NULL, NULL); - - if (cluster < n->cluster) - sel_b = b; - } - - if (!sel_a && !sel_b) - return; - - if (sel_a && !sel_b) { - copy_reg(&right_out(n), sel_a); - return; - } - - if (!sel_a && sel_b) { - copy_reg(&right_out(n), sel_b); - return; - } - - /* both available, select older */ - if (sel_a->pkt.timestamp < sel_b->pkt.timestamp) - copy_reg(&right_out(n), sel_a); - else - copy_reg(&right_out(n), sel_b); + uint16_t cluster = 0; + struct sel_helper *helper = data; + addr_mesh1d(r->pkt.to, &cluster, NULL, NULL); + return cluster < helper->cluster; } -static void propagate(struct node1d *n, int elem, struct reg *a, struct reg *b, struct reg *c) +static bool elem_sel(struct reg *r, void *data) { - - struct reg *sel_a = NULL, *sel_b = NULL, *sel_c = NULL; - if (a && a->busy) { - uint16_t cluster = 0, element = 0; - addr_mesh1d(a->pkt.to, &cluster, &element, NULL); - - if (cluster == n->cluster && element == elem) - sel_a = a; - } - - if (b && b->busy) { - uint16_t cluster = 0, element = 0; - addr_mesh1d(b->pkt.to, &cluster, &element, NULL); - - if (cluster == n->cluster && element == elem) - sel_b = b; - } - - if (c && c->busy) { - uint16_t cluster = 0, element = 0; - addr_mesh1d(c->pkt.to, &cluster, &element, NULL); - - if (cluster == n->cluster && element == elem) - sel_c = c; - } - - struct reg *sel_0 = NULL, *sel_1 = NULL; - if (sel_a && sel_b) - sel_0 = sel_a->pkt.timestamp < sel_b->pkt.timestamp ? sel_a : sel_b; - else - sel_0 = sel_a ? sel_a : sel_b; - - if (sel_b && sel_c) - sel_1 = sel_b->pkt.timestamp < sel_c->pkt.timestamp ? sel_b : sel_c; - else - sel_1 = sel_b ? sel_b : sel_c; - - struct reg *sel = NULL; - if (sel_0 && sel_1) - sel = sel_0->pkt.timestamp < sel_1->pkt.timestamp ? sel_0 : sel_1; - else - sel = sel_0 ? sel_0 : sel_1; - - if (!sel) - return; - - copy_reg(&n->out[elem], sel); + uint16_t cluster = 0, elem = 0; + struct sel_helper *helper = data; + addr_mesh1d(r->pkt.to, &cluster, &elem, NULL); + return cluster == helper->cluster && elem == helper->elem; } static stat node1d_clock(struct node1d *n) { n->timestamp++; - clock_outputs(n); /* select oldest packet to process */ @@ -230,15 +103,28 @@ static stat node1d_clock(struct node1d *n) r = &n->in[i]; } - propagate_left(n, r, &right_in(n)); - propagate_right(n, r, &left_in(n)); - for (int i = 0; i < n->elems; ++i) - propagate(n, i, r, &right_in(n), &left_in(n)); + struct sel_helper helper = { + .cluster = n->cluster, + .elem = 0, + }; + + struct reg *north[] = {r, &south_in(n)}; + struct reg *south[] = {r, &north_in(n)}; + + propagate(&north_out(n), 2, north, north_sel, &helper); + propagate(&south_out(n), 2, south, south_sel, &helper); + + struct reg *all[] = {r, &north_in(n), &south_in(n)}; + for (int i = 0; i < n->elems; ++i) { + helper.elem = i; + propagate(&n->out[i], 3, all, elem_sel, &helper); + } return OK; } -stat mesh_node1d_connect(struct component *c, struct component *e, uint16_t elem) +stat mesh_node1d_connect(struct component *c, struct component *e, + uint16_t elem) { struct node1d *n = (struct node1d *)c; if (elem >= n->elems) @@ -251,23 +137,23 @@ stat mesh_node1d_connect(struct component *c, struct component *e, uint16_t elem return OK; } -stat mesh_node1d_connect_left(struct component *c, struct component *e) +stat mesh_node1d_connect_north(struct component *c, struct component *e) { struct node1d *n = (struct node1d *)c; - if (left_port(n)) + if (north_port(n)) return EEXISTS; - left_port(n) = e; + north_port(n) = e; return OK; } -stat mesh_node1d_connect_right(struct component *c, struct component *e) +stat mesh_node1d_connect_south(struct component *c, struct component *e) { struct node1d *n = (struct node1d *)c; - if (right_port(n)) + if (south_port(n)) return EEXISTS; - right_port(n) = e; + south_port(n) = e; return OK; } @@ -279,22 +165,20 @@ struct component *create_mesh_node1d(uint16_t cluster, uint16_t elems) n->in = (struct reg *)calloc(elems + 2, sizeof(struct reg)); if (!n->in) { - free(n); + node1d_destroy(n); return NULL; } n->out = (struct reg *)calloc(elems + 2, sizeof(struct reg)); if (!n->out) { - free(n->in); - free(n); + node1d_destroy(n); return NULL; } - n->ports = (struct component **)calloc(elems + 2, sizeof(struct component *)); + n->ports = (struct component **)calloc(elems + 2, + sizeof(struct component *)); if (!n->ports) { - free(n->out); - free(n->in); - free(n); + node1d_destroy(n); return NULL; } diff --git a/src/mesh/node2d.c b/src/mesh/node2d.c index 81ef8dc..569bd68 100644 --- a/src/mesh/node2d.c +++ b/src/mesh/node2d.c @@ -1,24 +1,19 @@ #include <gran/mesh/node2d.h> #define north_port(n) (n)->ports[(n)->elems + 0] -#define east_port(n) (n)->ports[(n)->elems + 1] +#define east_port(n) (n)->ports[(n)->elems + 1] #define south_port(n) (n)->ports[(n)->elems + 2] -#define west_port(n) (n)->ports[(n)->elems + 3] +#define west_port(n) (n)->ports[(n)->elems + 3] #define north_in(n) (n)->in[(n)->elems + 0] -#define east_in(n) (n)->in[(n)->elems + 1] +#define east_in(n) (n)->in[(n)->elems + 1] #define south_in(n) (n)->in[(n)->elems + 2] -#define west_in(n) (n)->in[(n)->elems + 3] +#define west_in(n) (n)->in[(n)->elems + 3] #define north_out(n) (n)->out[(n)->elems + 0] -#define east_out(n) (n)->out[(n)->elems + 1] +#define east_out(n) (n)->out[(n)->elems + 1] #define south_out(n) (n)->out[(n)->elems + 2] -#define west_out(n) (n)->out[(n)->elems + 3] - -struct reg { - struct packet pkt; - bool busy; -}; +#define west_out(n) (n)->out[(n)->elems + 3] struct node2d { struct component component; @@ -32,6 +27,14 @@ struct node2d { struct component **ports; /* countedby[elems + 4] */ }; +static void node2d_destroy(struct node2d *n) +{ + free(n->in); + free(n->out); + free(n->ports); + free(n); +} + static void clock_outputs(struct node2d *n) { for (int i = 0; i < n->elems + 4; ++i) { @@ -46,39 +49,6 @@ static void clock_outputs(struct node2d *n) } } -static void copy_reg(struct reg *r, struct reg *s) -{ - assert(s->busy); - if (r->busy) - return; - - r->pkt = s->pkt; - r->busy = true; - s->busy = false; -} - -static void propagate(struct reg *out, - size_t count, struct reg *in[static count], - bool (*sel)(struct reg *r, void *data), void *data) -{ - struct reg *r = NULL; - for (size_t i = 0; i < count; ++i) { - if (!in[i] || !in[i]->busy) - continue; - - if (!sel(in[i], data)) - continue; - - if (!r || r->pkt.timestamp > in[i]->pkt.timestamp) - r = in[i]; - } - - if (!r) - return; - - copy_reg(out, r); -} - struct sel_helper { uint8_t x, y; uint16_t elem; @@ -165,18 +135,8 @@ static stat node2d_clock(struct node2d *n) return OK; } -static stat reg_busy(struct reg *r, struct packet pkt) -{ - bool busy = r->busy; - if (!busy) { - r->pkt = pkt; - r->busy = true; - } - - return busy ? EBUSY : OK; -} - -static stat node2d_receive(struct node2d *n, struct component *from, struct packet pkt) +static stat node2d_receive(struct node2d *n, struct component *from, + struct packet pkt) { for (int i = 0; i < n->elems + 4; ++i) { if (from != n->ports[i]) @@ -185,7 +145,7 @@ static stat node2d_receive(struct node2d *n, struct component *from, struct pack if (i < n->elems) pkt.timestamp = n->timestamp; - return reg_busy(&n->in[i], pkt); + return place_reg(&n->in[i], pkt); } abort(); @@ -200,25 +160,23 @@ struct component *create_mesh_node2d(uint8_t x, uint8_t y, uint16_t elems) n->in = calloc(elems + 4, sizeof(struct reg)); if (!n->in) { - free(n); + node2d_destroy(n); return NULL; } n->out = calloc(elems + 4, sizeof(struct reg)); if (!n->out) { - free(n->in); - free(n); + node2d_destroy(n); return NULL; } n->ports = calloc(elems + 4, sizeof(struct component *)); if (!n->ports) { - free(n->out); - free(n->in); - free(n); + node2d_destroy(n); return NULL; } + n->component.destroy = (destroy_callback)node2d_destroy; n->component.receive = (receive_callback)node2d_receive; n->component.clock = (clock_callback)node2d_clock; n->elems = elems; @@ -227,7 +185,8 @@ struct component *create_mesh_node2d(uint8_t x, uint8_t y, uint16_t elems) return (struct component *)n; } -stat mesh_node2d_connect(struct component *c, struct component *e, uint16_t elem) +stat mesh_node2d_connect(struct component *c, struct component *e, + uint16_t elem) { struct node2d *n = (struct node2d *)c; if (elem >= n->elems) diff --git a/src/mesh/node3d.c b/src/mesh/node3d.c index d00f762..8c6d776 100644 --- a/src/mesh/node3d.c +++ b/src/mesh/node3d.c @@ -1,189 +1,299 @@ #include <gran/mesh/node3d.h> -struct reg { - struct packet pkt; - bool busy; -}; +#define north_port(n) (n)->ports[(n)->elems + 0] +#define east_port(n) (n)->ports[(n)->elems + 1] +#define south_port(n) (n)->ports[(n)->elems + 2] +#define west_port(n) (n)->ports[(n)->elems + 3] +#define up_port(n) (n)->ports[(n)->elems + 4] +#define down_port(n) (n)->ports[(n)->elems + 5] + +#define north_in(n) (n)->in[(n)->elems + 0] +#define east_in(n) (n)->in[(n)->elems + 1] +#define south_in(n) (n)->in[(n)->elems + 2] +#define west_in(n) (n)->in[(n)->elems + 3] +#define up_in(n) (n)->in[(n)->elems + 4] +#define down_in(n) (n)->in[(n)->elems + 5] + +#define north_out(n) (n)->out[(n)->elems + 0] +#define east_out(n) (n)->out[(n)->elems + 1] +#define south_out(n) (n)->out[(n)->elems + 2] +#define west_out(n) (n)->out[(n)->elems + 3] +#define up_out(n) (n)->out[(n)->elems + 4] +#define down_out(n) (n)->out[(n)->elems + 5] struct node3d { struct component component; uint8_t x, y, z; + uint8_t elems; uint64_t timestamp; - struct component *n, *s, *e, *w, *u, *d, *l; - - struct reg n_in, s_in, e_in, w_in, u_in, d_in, l_in; + struct reg *in; /* countedby[elems + 6] */ + struct reg *out; /* countedby[elems + 6] */ + struct component **ports; /* countedby[elems + 6] */ }; -enum order { - N, S, E, W, U, D, L -}; +static void node3d_destroy(struct node3d *n) +{ + free(n->in); + free(n->out); + free(n->ports); + free(n); +} -static inline void maybe_pick(struct reg *output[7], enum order d, struct reg *r) +static void clock_outputs(struct node3d *n) { - if (output[d] && output[d]->pkt.timestamp < r->pkt.timestamp) - return; + for (int i = 0; i < n->elems + 6; ++i) { + if (!n->out[i].busy) + continue; + + stat ret = SEND(n, n->ports[i], n->out[i].pkt); + if (ret == EBUSY) + continue; - output[d] = r; + n->out[i].busy = false; + } } -static stat node3d_clock(struct node3d *node3d) +struct sel_helper { + uint8_t x, y, z, elem; +}; + +static bool north_sel(struct reg *r, void *data) { - node3d->timestamp++; + uint8_t y = 0; + struct sel_helper *helper = data; + addr_mesh3d(r->pkt.to, NULL, &y, NULL, NULL, NULL); + return y > helper->y; +} - struct reg *output[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; - struct reg *input[7] = { - &node3d->n_in, - &node3d->s_in, - &node3d->e_in, - &node3d->w_in, - &node3d->u_in, - &node3d->d_in, - &node3d->l_in - }; +static bool south_sel(struct reg *r, void *data) +{ + uint8_t y = 0; + struct sel_helper *helper = data; + addr_mesh3d(r->pkt.to, NULL, &y, NULL, NULL, NULL); + return y < helper->y; +} - uint8_t X = node3d->x, Y = node3d->y, Z = node3d->z; - for (size_t i = 0; i < 7; ++i) { - struct reg *r = input[i]; - if (!r->busy) - continue; +static bool east_sel(struct reg *r, void *data) +{ + uint8_t x = 0, y = 0; + struct sel_helper *helper = data; + addr_mesh3d(r->pkt.to, &x, &y, NULL, NULL, NULL); + return y == helper->y && x > helper->x; +} - uint8_t x, y, z; - addr_mesh3d(r->pkt.to, &x, &y, &z, NULL); - if (x < X) { - maybe_pick(output, W, r); - continue; - } +static bool west_sel(struct reg *r, void *data) +{ + uint8_t x = 0, y = 0; + struct sel_helper *helper = data; + addr_mesh3d(r->pkt.to, &x, &y, NULL, NULL, NULL); + return y == helper->y && x < helper->x; +} - if (x > X) { - maybe_pick(output, E, r); - continue; - } +static bool up_sel(struct reg *r, void *data) +{ + uint8_t x = 0, y = 0, z = 0; + struct sel_helper *helper = data; + addr_mesh3d(r->pkt.to, &x, &y, &z, NULL, NULL); + return y == helper->y && x == helper->x && z > helper->z; +} - if (y < Y) { - maybe_pick(output, S, r); - continue; - } +static bool down_sel(struct reg *r, void *data) +{ + uint8_t x = 0, y = 0, z = 0; + struct sel_helper *helper = data; + addr_mesh3d(r->pkt.to, &x, &y, &z, NULL, NULL); + return y == helper->y && x == helper->x && z < helper->z; +} - if (y > Y) { - maybe_pick(output, N, r); - continue; - } +static bool elem_sel(struct reg *r, void *data) +{ + uint8_t x = 0, y = 0, z = 0, elem = 0; + struct sel_helper *helper = data; + addr_mesh3d(r->pkt.to, &x, &y, &z, &elem, NULL); + return x == helper->x && y == helper->y && z == helper->z && elem == helper->elem; +} - if (z < Z) { - maybe_pick(output, D, r); - continue; - } +static stat node3d_clock(struct node3d *n) +{ + n->timestamp++; + clock_outputs(n); - if (z > Z) { - maybe_pick(output, U, r); + /* select oldest packet to process */ + struct reg *r = NULL; + for (int i = 0; i < n->elems; ++i) { + if (!n->in[i].busy) continue; - } - maybe_pick(output, L, r); - } + if (!r || r->pkt.timestamp > n->in[i].pkt.timestamp) + r = &n->in[i]; + }; - struct component *target[7] = { - node3d->n, - node3d->s, - node3d->e, - node3d->w, - node3d->u, - node3d->d, - node3d->l + struct sel_helper helper = { + .elem = 0, + .x = n->x, + .y = n->y, + .z = n->z }; - for (size_t i = 0; i < 7; ++i) { - if (!output[i]) - continue; + struct reg *north[] = {r, &east_in(n), &south_in(n), + &west_in(n), &up_in(n), &down_in(n)}; - if (!target[i]) { - /* for now, should send packet back with an error or something */ - abort(); - } + struct reg *east[] = {r, &north_in(n), &south_in(n), + &west_in(n), &up_in(n), &down_in(n)}; - stat ret = SEND(node3d, target[i], output[i]->pkt); - if (ret == EBUSY) - continue; + struct reg *south[] = {r, &north_in(n), &east_in(n), + &west_in(n), &up_in(n), &down_in(n)}; + + struct reg *west[] = {r, &north_in(n), &east_in(n), + &south_in(n), &up_in(n), &down_in(n)}; - assert(ret == OK); - output[i]->busy = false; + struct reg *up[] = {r, &north_in(n), &east_in(n), + &west_in(n), &south_in(n), &down_in(n)}; + + struct reg *down[] = {r, &north_in(n), &east_in(n), + &west_in(n), &south_in(n), &up_in(n)}; + + propagate(&north_out(n), 6, north, north_sel, &helper); + propagate(&east_out(n), 6, east, east_sel, &helper); + propagate(&south_out(n), 6, south, south_sel, &helper); + propagate(&west_out(n), 6, west, west_sel, &helper); + propagate(&up_out(n), 6, up, up_sel, &helper); + propagate(&down_out(n), 6, down, down_sel, &helper); + + struct reg *all[] = {r, &north_in(n), &east_in(n), &south_in(n), + &west_in(n), &up_in(n), &down_in(n)}; + + for (int i = 0; i < n->elems; ++i) { + helper.elem = i; + propagate(&n->out[i], 7, all, elem_sel, &helper); } return OK; } -static stat reg_receive(struct reg *r, struct packet pkt) +static stat node3d_receive(struct node3d *n, struct component *from, + struct packet pkt) { - if (r->busy) - return EBUSY; + for (int i = 0; i < n->elems + 6; ++i) { + if (from != n->ports[i]) + continue; + + if (i < n->elems) + pkt.timestamp = n->timestamp; - r->pkt = pkt; - r->busy = true; + return place_reg(&n->in[i], pkt); + } + + abort(); return OK; } -static stat node3d_receive(struct node3d *node3d, struct component *from, struct packet pkt) +struct component *create_mesh_node3d(uint8_t x, uint8_t y, uint8_t z, uint8_t elems) { - if (from == node3d->l) { - /* add time when packet entered network */ - pkt.timestamp = node3d->timestamp; - return reg_receive(&node3d->l_in, pkt); + struct node3d *n = calloc(1, sizeof(struct node3d)); + if (!n) + return NULL; + + n->in = calloc(elems + 6, sizeof(struct reg)); + if (!n->in) { + node3d_destroy(n); + return NULL; } - if (from == node3d->n) - return reg_receive(&node3d->n_in, pkt); + n->out = calloc(elems + 6, sizeof(struct reg)); + if (!n->out) { + node3d_destroy(n); + return NULL; + } - if (from == node3d->s) - return reg_receive(&node3d->s_in, pkt); + n->ports = calloc(elems + 6, sizeof(struct component*)); + if (!n->ports) { + node3d_destroy(n); + return NULL; + } - if (from == node3d->e) - return reg_receive(&node3d->e_in, pkt); + n->component.destroy = (destroy_callback)node3d_destroy; + n->component.receive = (receive_callback)node3d_receive; + n->component.clock = (clock_callback)node3d_clock; + n->elems = elems; + n->x = x; + n->y = y; + n->z = z; + return (struct component *)n; +} - if (from == node3d->w) - return reg_receive(&node3d->w_in, pkt); +stat mesh_node3d_connect(struct component *c, struct component *e, + uint8_t elem) +{ + struct node3d *n = (struct node3d *)c; + if (elem >= n->elems) + return ENOSUCH; - if (from == node3d->u) - return reg_receive(&node3d->u_in, pkt); + if (n->ports[elem]) + return EEXISTS; - if (from == node3d->d) - return reg_receive(&node3d->d_in, pkt); + n->ports[elem] = e; + return OK; +} - abort(); +stat mesh_node3d_connect_north(struct component *c, struct component *e) +{ + struct node3d *n = (struct node3d *)c; + if (north_port(n)) + return EEXISTS; + + north_port(n) = e; return OK; } -struct component *create_mesh_node3d(uint8_t x, uint8_t y, uint8_t z) +stat mesh_node3d_connect_east(struct component *c, struct component *e) { - struct node3d *node = calloc(1, sizeof(struct node3d)); - if (!node) - return NULL; + struct node3d *n = (struct node3d *)c; + if (east_port(n)) + return EEXISTS; + + east_port(n) = e; + return OK; +} + +stat mesh_node3d_connect_south(struct component *c, struct component *e) +{ + struct node3d *n = (struct node3d *)c; + if (south_port(n)) + return EEXISTS; + + south_port(n) = e; + return OK; +} + +stat mesh_node3d_connect_west(struct component *c, struct component *e) +{ + struct node3d *n = (struct node3d *)c; + if (west_port(n)) + return EEXISTS; + + west_port(n) = e; + return OK; +} + +stat mesh_node3d_connect_up(struct component *c, struct component *e) +{ + struct node3d *n = (struct node3d *)c; + if (up_port(n)) + return EEXISTS; - node->component.receive = (receive_callback)node3d_receive; - node->component.clock = (clock_callback)node3d_clock; - node->x = x; - node->y = y; - node->z = z; - return (struct component *)node; + up_port(n) = e; + return OK; } -stat mesh_node3d_connect(struct component *node, - struct component *n, - struct component *s, - struct component *e, - struct component *w, - struct component *u, - struct component *d, - struct component *l) +stat mesh_node3d_connect_down(struct component *c, struct component *e) { - struct node3d *node3d = (struct node3d *)node; - node3d->n = n; - node3d->s = s; - node3d->e = e; - node3d->w = w; - node3d->u = u; - node3d->d = d; - node3d->l = l; + struct node3d *n = (struct node3d *)c; + if (down_port(n)) + return EEXISTS; + + down_port(n) = e; return OK; } diff --git a/tests/simple_mesh1d/sim.c b/tests/simple_mesh1d/sim.c index c5f7290..b419633 100644 --- a/tests/simple_mesh1d/sim.c +++ b/tests/simple_mesh1d/sim.c @@ -15,7 +15,6 @@ static stat build_node1d(struct clock_domain *clk, uint16_t x, uint16_t y) assert(mesh); for (int i = 1; i < x + 1; ++i) { - /* 4 CPUs + 1 mem = 5 elems in total */ struct component *node = create_mesh_node1d(i, y + 1); clock_domain_add(clk, node); mesh[i] = node; @@ -23,8 +22,8 @@ static stat build_node1d(struct clock_domain *clk, uint16_t x, uint16_t y) for (int j = 0; j < y; ++j) { struct component *imem = create_simple_mem(4096); init_simple_mem(imem, 0, - build_tests_simple_mesh1d_test_bin_len, - build_tests_simple_mesh1d_test_bin); + build_tests_simple_mesh1d_test_bin_len, + build_tests_simple_mesh1d_test_bin); uint64_t rcv = mesh1d_addr(i, j, 0); struct component *rv64 = create_simple_riscv64(rcv, 0, imem, node); @@ -44,7 +43,7 @@ static stat build_node1d(struct clock_domain *clk, uint16_t x, uint16_t y) mesh_node1d_connect(node, dmem, 4); } - /* extra I/O node (kind of?) */ + /* extra I/O node */ struct component *node = create_mesh_node1d(0, 2); clock_domain_add(clk, node); mesh[0] = node; @@ -59,10 +58,10 @@ static stat build_node1d(struct clock_domain *clk, uint16_t x, uint16_t y) for (int i = 0; i < x + 1; ++i) { if (i - 1 >= 0) - mesh_node1d_connect_right(mesh[i], mesh[i - 1]); + mesh_node1d_connect_south(mesh[i], mesh[i - 1]); if (i + 1 < x + 1) - mesh_node1d_connect_left(mesh[i], mesh[i + 1]); + mesh_node1d_connect_north(mesh[i], mesh[i + 1]); } free(mesh); diff --git a/tests/simple_mesh1d/test.c b/tests/simple_mesh1d/test.c index b3de347..293a91c 100644 --- a/tests/simple_mesh1d/test.c +++ b/tests/simple_mesh1d/test.c @@ -1,7 +1,8 @@ #include <stdint.h> __attribute__((always_inline)) -static inline uint64_t extreme_numa_addr(uint16_t cluster, uint16_t elem, uint32_t off) +static inline uint64_t mesh1d_addr(uint16_t cluster, uint16_t elem, + uint32_t off) { return ((uint64_t)cluster << 48) | ((uint64_t)elem << 32) | off; } @@ -40,18 +41,18 @@ static inline uint64_t next_idx(unsigned x, unsigned y, unsigned X, unsigned Y) unsigned yi = wrap(y, Y); unsigned xi = yi < y ? wrap(x, X) : x; - return extreme_numa_addr(xi, yi, 0); + return mesh1d_addr(xi, yi, 0); } void _start(unsigned x, unsigned y, unsigned X, unsigned Y) { - volatile char *uart = (char *)extreme_numa_addr(0, 0, 0); - volatile uint64_t *control = (uint64_t *)extreme_numa_addr(0, 1, 0); + volatile char *uart = (char *)mesh1d_addr(0, 0, 0); + volatile uint64_t *control = (uint64_t *)mesh1d_addr(0, 1, 0); if (x == 1 && y == 0) { goto do_work; } else { - while (*control != extreme_numa_addr(x, y, 0)) {} + while (*control != mesh1d_addr(x, y, 0)) {} } do_work: @@ -59,7 +60,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) {} 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) {} 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) {} |
