diff options
| author | 2026-11-10 05:58:05 +0000 | |
|---|---|---|
| committer | 2026-11-10 06:07:10 +0000 | |
| commit | 46ca10dd122b52374272f636d09ca0831c3378e7 (patch) | |
| tree | 9f5763193b6011deaf49016b004d946906fa4698 /src/utils.h | |
| download | lab-04-46ca10dd122b52374272f636d09ca0831c3378e7.tar.gz | |
Diffstat (limited to 'src/utils.h')
| -rw-r--r-- | src/utils.h | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..4adf482 --- /dev/null +++ b/src/utils.h | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #ifndef INCLUDED_UTILS_H | ||
| 2 | #define INCLUDED_UTILS_H | ||
| 3 | |||
| 4 | #include <assert.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <stdio.h> | ||
| 7 | |||
| 8 | #define CTZ __builtin_ctz | ||
| 9 | #define CLZ __builtin_clz | ||
| 10 | #define FIRST_LEADING_ZERO __builtin_stdc_first_leading_zero | ||
| 11 | #define FIRST_LEADING_ONE __builtin_stdc_first_leading_one | ||
| 12 | |||
| 13 | #define STRINGIFY(ARG) #ARG | ||
| 14 | #define TO_STRING(ARG) STRINGIFY (ARG) | ||
| 15 | #define LOG(MSG, ...) \ | ||
| 16 | fprintf (stderr, __FILE__ ":" TO_STRING (__LINE__) ": " MSG "\n", __VA_ARGS__) | ||
| 17 | #define INFO(MSG, ...) LOG("info: " MSG __VA_OPT__(,) __VA_ARGS__) | ||
| 18 | #define ERROR(MSG, ...) LOG("error: " MSG __VA_OPT__(,) __VA_ARGS__) | ||
| 19 | #define DIE(CODE, MSG, ...) do { \ | ||
| 20 | ERROR (MSG __VA_OPT__(,) __VA_ARGS__); \ | ||
| 21 | exit (CODE); \ | ||
| 22 | } while (0) | ||
| 23 | |||
| 24 | #define UNUSED(X) ((void) (X)) | ||
| 25 | #define UNREACHABLE() ASSERT (!"reached the unreachable...") | ||
| 26 | #define TODO(STR) fprintf (stderr, "%s:%d: warning: TODO "STR"\n", __FILE__, __LINE__) | ||
| 27 | // #define TODO(...) | ||
| 28 | #define REACHED(FMT, ...) fprintf (stderr, "%s:%d: info: %s: reached: "FMT"\n", __FILE__, __LINE__, __func__ __VA_OPT__(,) __VA_ARGS__) | ||
| 29 | |||
| 30 | #define MALLOC malloc | ||
| 31 | #define REALLOC realloc | ||
| 32 | #define FREE free | ||
| 33 | #define ASSERT assert | ||
| 34 | |||
| 35 | #define PRINT_EXP(FMT, EXP) printf (#EXP" = "FMT"\n", EXP) | ||
| 36 | |||
| 37 | #define MAX(A, B) ((A) >= (B) ? (A) : (B)) | ||
| 38 | #define MIN(A, B) ((A) <= (B) ? (A) : (B)) | ||
| 39 | |||
| 40 | inline float | ||
| 41 | interpolate (float min, float max, float alpha) | ||
| 42 | { | ||
| 43 | return min + (max - min)*alpha; | ||
| 44 | } | ||
| 45 | |||
| 46 | #endif | ||
