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 /include | |
| parent | 3083284c797fc8fc267144b05c8a58395e4583e3 (diff) | |
| download | gran-1853f5d6594bc371e4d8e631c24acd011a620915.tar.gz gran-1853f5d6594bc371e4d8e631c24acd011a620915.zip | |
refactor mesh3d to match 2d,1d
Diffstat (limited to 'include')
| -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 |
4 files changed, 63 insertions, 31 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 */ |
