diff options
| author | 2023-11-25 18:59:53 +0000 | |
|---|---|---|
| committer | 2026-11-07 02:12:54 +0000 | |
| commit | 055f35e74601bea2223a1555c15b029ee90a9117 (patch) | |
| tree | c2bc92f254ad85b9fc545ab30a700757d72902fc /src/utils.h | |
| download | lab-02-master.tar.gz | |
Diffstat (limited to 'src/utils.h')
| -rw-r--r-- | src/utils.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..8cdbe46 --- /dev/null +++ b/src/utils.h | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | #ifndef UTILS_H | ||
| 2 | #define UTILS_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #define MAX(a, b) ({ \ | ||
| 7 | __typeof__ (a) _a = (a); \ | ||
| 8 | __typeof__ (b) _b = (b); \ | ||
| 9 | _a > _b ? _a : _b; \ | ||
| 10 | }) | ||
| 11 | |||
| 12 | #define MIN(a, b) ({ \ | ||
| 13 | __typeof__ (a) _a = (a); \ | ||
| 14 | __typeof__ (b) _b = (b); \ | ||
| 15 | _a < _b ? _a : _b; \ | ||
| 16 | }) | ||
| 17 | |||
| 18 | #define CLZ(X) __builtin_clz (X) | ||
| 19 | #define CTZ(X) __builtin_ctz (X) | ||
| 20 | #define FFS(X) __builtin_ffs (X) | ||
| 21 | #define POPCOUNT(X) __builtin_popcount (X) | ||
| 22 | |||
| 23 | #define PAGEBREAK() puts ("\n") | ||
| 24 | #define NEWLINE() putchar ('\n') | ||
| 25 | |||
| 26 | typedef unsigned int uint; | ||
| 27 | typedef uint8_t u8; | ||
| 28 | typedef uint16_t u16; | ||
| 29 | typedef uint64_t u64; | ||
| 30 | |||
| 31 | int | ||
| 32 | input (const char *message, const char *regex, const char *template, ...); | ||
| 33 | |||
| 34 | uint | ||
| 35 | log10ui (uint ui); | ||
| 36 | |||
| 37 | u16 | ||
| 38 | rev16 (u16 b); | ||
| 39 | |||
| 40 | #endif | ||
