From 3083284c797fc8fc267144b05c8a58395e4583e3 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Sat, 9 Aug 2025 16:06:43 +0300 Subject: 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 --- tests/simple_mesh1d/test.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 tests/simple_mesh1d/test.c (limited to 'tests/simple_mesh1d/test.c') diff --git a/tests/simple_mesh1d/test.c b/tests/simple_mesh1d/test.c new file mode 100644 index 0000000..b3de347 --- /dev/null +++ b/tests/simple_mesh1d/test.c @@ -0,0 +1,66 @@ +#include + +__attribute__((always_inline)) +static inline uint64_t extreme_numa_addr(uint16_t cluster, uint16_t elem, uint32_t off) +{ + return ((uint64_t)cluster << 48) | ((uint64_t)elem << 32) | off; +} + +__attribute__((always_inline)) +static inline void print_int8(volatile char *uart, unsigned x) +{ + char lo_nibble = (x >> 0) & 0xf; + char hi_nibble = (x >> 4) & 0xf; + + *uart = hi_nibble < 10 ? hi_nibble + '0' : (hi_nibble - 10) + 'a'; + *uart = lo_nibble < 10 ? lo_nibble + '0' : (lo_nibble - 10) + 'a'; +} + +__attribute__((always_inline)) +static inline void print_addr(volatile char *uart, unsigned x, unsigned y) +{ + *uart = '('; + print_int8(uart, x); + *uart = ','; + *uart = ' '; + print_int8(uart, y); + *uart = ')'; + *uart = '\n'; +} + +__attribute__((always_inline)) +static inline uint64_t wrap(unsigned x, unsigned X) +{ + return x + 1 >= X ? 0 : x + 1; +} + +__attribute__((always_inline)) +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); +} + +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); + + if (x == 1 && y == 0) { + goto do_work; + } else { + while (*control != extreme_numa_addr(x, y, 0)) {} + } + +do_work: + print_addr(uart, x, y); + *control = next_idx(x, y, X, Y); + + if (x == X - 1 && y == Y - 1) + asm("ebreak"); + + /* otherwise just loop */ + while (1) {} +} -- cgit v1.3