diff options
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 */ |
