libcute 0.1
Loading...
Searching...
No Matches
utility.h
1#pragma once
2
4#include <stddef.h>
5#include "macro.h"
6static inline size_t cu_next_pow2(size_t x) {
7 if (x <= 1) {
8 return 1;
9 }
10 x--;
11 x |= x >> 1;
12 x |= x >> 2;
13 x |= x >> 4;
14 x |= x >> 8;
15 x |= x >> 16;
16#if SIZE_MAX > UINT32_MAX
17 x |= x >> 32;
18#endif
19 return x + 1;
20}
21
22typedef struct {
23 size_t elem_size;
24 size_t alignment;
25} cu_Layout;
26
27static inline cu_Layout cu_Layout_create(size_t elem_size, size_t alignment) {
28 cu_Layout layout = {0, 0};
29 if (elem_size == 0 || alignment == 0) {
30 return layout;
31 }
32
33 layout.elem_size = elem_size;
34 layout.alignment = alignment;
35 return layout;
36}
37
38#define CU_LAYOUT(T) cu_Layout_create(sizeof(T), _Alignof(T))
39#define CU_LAYOUT_CHECK(layout) \
40 if ((layout).elem_size == 0 || (layout).alignment == 0)
41
42#define CU_TIME_NS_PER_SEC 1000000000ULL
43#if CU_PLAT_WINDOWS
44#define CU_TIME_WINDOWS_TICKS_PER_SEC 10000000ULL
45#define CU_TIME_WINDOWS_EPOCH_DIFF 116444736000000000ULL
46#define CU_TIME_WINDOWS_TICK_NS 100ULL
47#include <windows.h>
48long long cu_Time_filetime_to_unix(FILETIME ft);
49FILETIME cu_Time_unix_to_filetime(long long ns);
50#endif
51
Definition utility.h:22