kernel: add header files

This commit is contained in:
2026-02-19 19:13:44 +00:00
parent f2e128c57e
commit 85006411bd
42 changed files with 3335 additions and 0 deletions

70
include/kernel/util.h Normal file
View File

@@ -0,0 +1,70 @@
#ifndef KERNEL_UTIL_H_
#define KERNEL_UTIL_H_
#include <mango/types.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define CLAMP(x, lo, hi) (MIN(MAX(x, lo), hi))
extern uint64_t hash_string(const char *s);
extern void data_size_to_string(size_t value, char *out, size_t outsz);
static inline bool power_of_2(size_t x)
{
return (x > 0 && (x & (x - 1)) == 0);
}
static inline unsigned long long div64_pow2(
unsigned long long x,
unsigned long long y)
{
return x >> (__builtin_ctz(y));
}
static inline unsigned long long absdiff64(
unsigned long long x,
unsigned long long y)
{
return x < y ? y - x : x - y;
}
extern int16_t host_to_big_i16(int16_t v);
extern int16_t host_to_little_i16(int16_t v);
extern int16_t big_to_host_i16(int16_t v);
extern int16_t little_to_host_i16(int16_t v);
extern uint16_t host_to_big_u16(uint16_t v);
extern uint16_t host_to_little_u16(uint16_t v);
extern uint16_t big_to_host_u16(uint16_t v);
extern uint16_t little_to_host_u16(uint16_t v);
extern int32_t host_to_big_i32(int32_t v);
extern int32_t host_to_little_i32(int32_t v);
extern int32_t big_to_host_i32(int32_t v);
extern int32_t little_to_host_i32(int32_t v);
extern uint32_t host_to_big_u32(uint32_t v);
extern uint32_t host_to_little_u32(uint32_t v);
extern uint32_t big_to_host_u32(uint32_t v);
extern uint32_t little_to_host_u32(uint32_t v);
extern int64_t host_to_big_i64(int64_t v);
extern int64_t host_to_little_i64(int64_t v);
extern int64_t big_to_host_i64(int64_t v);
extern int64_t little_to_host_i64(int64_t v);
extern uint64_t host_to_big_u64(uint64_t v);
extern uint64_t host_to_little_u64(uint64_t v);
extern uint64_t big_to_host_u64(uint64_t v);
extern uint64_t little_to_host_u64(uint64_t v);
extern bool fill_random(void *buffer, unsigned int size);
#ifdef __cplusplus
}
#endif
#endif