/* * Copyright (C) 2025 dwlr * * BSD 3-Clause License (BSD-3-Clause) * See LICENSE for details */ typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; typedef unsigned long long u64; /* XXX: GCC extension */ typedef signed char s8; typedef signed short s16; typedef signed int s32; typedef signed long long s64; /* XXX: GCC extension */ typedef s8 bool; typedef u64 usize; typedef s64 ssize; typedef float f32; typedef double f64; #define min_s8 ((s8) (0x80)) #define min_s16 ((s16)(0x8000)) #define min_s32 ((s32)(0x80000000L)) #define min_s64 ((s64)(0x8000000000000000LL)) #define min_ssize min_s64 #define max_s8 ((s8) (0x7F)) #define max_s16 ((s16)(0x7FFF)) #define max_s32 ((s32)(0x7FFFFFFFL)) #define max_s64 ((s64)(0x7FFFFFFFFFFFFFFFLL)) #define max_ssize max_s64 #define max_u8 ((u8) (0xFF)) #define max_u16 ((u16)(0xFFFF)) #define max_u32 ((u32)(0xFFFFFFFFUL)) #define max_u64 ((u64)(0xFFFFFFFFFFFFFFFFULL)) #define max_usize max_u64 #ifndef true #define true 1 #endif #ifndef false #define false 0 #endif #define iota __COUNTER__ #define nil {0} #define KB bit(10LL) #define MB bit(20LL) #define GB bit(30LL) #define TB bit(40LL) #define packed __attribute__((packed)) #define bit(n) (1LL << (n)) #define align(what, to) (((what) + ((to) - 1)) & ~((to) - 1)) /* NOTE: `to` *must* be pow. of 2 */ #define lengthof(arr) (sizeof(arr) / sizeof(arr[0])) #ifndef offsetof #define offsetof(strct, memb) ((ssize)(&((strct*)(0)->memb))) #endif #define min(a, b) (((a) <= (b)) ? (a) : (b)) #define max(a, b) (((a) >= (b)) ? (a) : (b)) #define clamp(x, mn, mx) (min((mn), max((x), (mx)))) #define unused(expr) ((void)(expr))