diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-03-04 20:08:04 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2025-03-04 20:08:04 +0200 |
| commit | f03c2027c3ed7f385842b8583bb1953e04dd9386 (patch) | |
| tree | 5d5d42e0922fcad989361745778a00d529ff2e48 /include | |
| parent | 0464b7765aa4d1fc2178e443a3b37d19cfe541a0 (diff) | |
| download | gran-f03c2027c3ed7f385842b8583bb1953e04dd9386.tar.gz gran-f03c2027c3ed7f385842b8583bb1953e04dd9386.zip | |
add fat butterfly
Diffstat (limited to 'include')
| -rw-r--r-- | include/gran/bfly/fat_bfly.h | 20 | ||||
| -rw-r--r-- | include/gran/utils.h | 18 |
2 files changed, 38 insertions, 0 deletions
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 <gran/component.h> + +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 <stdbool.h> + +/* 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 */ |
