aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-08-09 16:06:43 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2025-08-09 16:06:43 +0300
commit3083284c797fc8fc267144b05c8a58395e4583e3 (patch)
treed0413af85d65cf895aa85fdaaf3a9f090f41dac1 /include
parentaba90a3a6f6c1caee28aaf3dadebb4daba5b5761 (diff)
downloadgran-3083284c797fc8fc267144b05c8a58395e4583e3.tar.gz
gran-3083284c797fc8fc267144b05c8a58395e4583e3.zip
add 1d mesh node and refactor 2d mesh node
+ Seems to decrease performance a little bit, presumably due to extra register copy, but simplifies code a lot and opens up more genericism so I'll consider it an upgrade for now. Copying packets around is rather slow though, might in the future move to some kind of pointer based packet handling
Diffstat (limited to 'include')
-rw-r--r--include/gran/mesh/node.h31
-rw-r--r--include/gran/mesh/node1d.h24
-rw-r--r--include/gran/mesh/node2d.h32
3 files changed, 56 insertions, 31 deletions
diff --git a/include/gran/mesh/node.h b/include/gran/mesh/node.h
deleted file mode 100644
index 53ee08b..0000000
--- a/include/gran/mesh/node.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef GRAN_GRID_NODE_H
-#define GRAN_GRID_NODE_H
-
-#include <gran/component.h>
-#include <stdint.h>
-
-struct component *create_mesh_node(uint16_t x, uint16_t y);
-
-stat mesh_node_connect(struct component *node,
- struct component *n,
- struct component *s,
- struct component *e,
- struct component *w,
- struct component *l);
-
-static inline uint64_t mesh_addr(uint16_t x, uint16_t y, uint32_t off)
-{
- return off
- | ((uint64_t)x << 32)
- | ((uint64_t)y << 48)
- ;
-}
-
-static inline void addr_mesh(uint64_t addr, uint16_t *x, uint16_t *y, uint32_t *off)
-{
- if (off) *off = addr & 0xffffffff;
- if (x) *x = (addr >> 32) & 0xffff;
- if (y) *y = (addr >> 48) & 0xffff;
-}
-
-#endif /* GRAN_GRID_NODE_H */
diff --git a/include/gran/mesh/node1d.h b/include/gran/mesh/node1d.h
new file mode 100644
index 0000000..6c8151e
--- /dev/null
+++ b/include/gran/mesh/node1d.h
@@ -0,0 +1,24 @@
+#ifndef MESH_NODE1D_H
+#define MESH_NODE1D_H
+
+#include <stdint.h>
+#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);
+
+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)
+{
+ return ((uint64_t)cluster << 48) | ((uint64_t)elem << 32) | off;
+}
+
+#endif /* MESH_NODE1D_H */
diff --git a/include/gran/mesh/node2d.h b/include/gran/mesh/node2d.h
new file mode 100644
index 0000000..fe43e59
--- /dev/null
+++ b/include/gran/mesh/node2d.h
@@ -0,0 +1,32 @@
+#ifndef GRAN_MESH_NODE2D_H
+#define GRAN_MESH_NODE2D_H
+
+#include <gran/component.h>
+#include <stdint.h>
+
+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_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)
+{
+ return off
+ | ((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)
+{
+ if (off) *off = addr & 0xffffffff;
+ if (elem) *elem = (addr >> 32) & 0xffff;
+ if (x) *x = (addr >> 48) & 0xff;
+ if (y) *y = (addr >> 56) & 0xff;
+}
+
+#endif /* GRAN_MESH_NODE_H */