From f03c2027c3ed7f385842b8583bb1953e04dd9386 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Tue, 4 Mar 2025 20:08:04 +0200 Subject: add fat butterfly --- include/gran/bfly/fat_bfly.h | 20 ++++++++++++++++++++ include/gran/utils.h | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 include/gran/bfly/fat_bfly.h create mode 100644 include/gran/utils.h (limited to 'include') diff --git a/include/gran/bfly/fat_bfly.h b/include/gran/bfly/fat_bfly.h new file mode 100644 index 0000000..c3025aa --- /dev/null +++ b/include/gran/bfly/fat_bfly.h @@ -0,0 +1,20 @@ +#ifndef GRAN_FAT_BFLY_H +#define GRAN_FAT_BFLY_H + +#include + +struct component *create_fat_bfly(uint32_t elems); +stat fat_bfly_connect(struct component *bfly, struct component *component, uint32_t elem); + +static inline void addr_fat_bfly(uint64_t addr, uint32_t *elem, uint32_t *off) +{ + if (off) *off = addr & 0xffffffff; + if (elem) *elem = (addr >> 32) & 0xffffffff; +} + +static inline uint64_t fat_bfly_addr(uint32_t elem, uint32_t off) +{ + return ((uint64_t)elem << 32) | off; +} + +#endif /* GRAN_FAT_BFLY_H */ diff --git a/include/gran/utils.h b/include/gran/utils.h new file mode 100644 index 0000000..eb76bf5 --- /dev/null +++ b/include/gran/utils.h @@ -0,0 +1,18 @@ +#ifndef GRAN_UTILS_H +#define GRAN_UTILS_H + +#include + +/* assumes x != 0 */ +static inline bool is_powerof2(unsigned long long x) +{ + return __builtin_popcountll(x) == 1; +} + +/* assumes x != 0 */ +static inline unsigned long long log2ull(unsigned long long x) +{ + return __builtin_ffsll(x) - 1; +} + +#endif /* GRAN_UTILS_H */ -- cgit v1.3