vbos/include/math.h
Michael Shaw 9222a373fc buddy: replace free-lists with binary tree
before this patch, the buddy allocator used a hybrid bitmap-freelist
approach where free would use the bitmap to determine size, but all
other operations we O(n) traversals of the free-list.

now, both alloc and free use the bitmap exclusively for allocation.
2023-04-29 00:15:50 -04:00

26 lines
538 B
C

/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _MATH_H_
#define _MATH_H_
#include <stdint.h>
#include <stddef.h>
size_t log2(size_t n);
size_t npow2(size_t n);
void bitmap_set(char *bitmap, size_t n, uint64_t b);
void bitmap_clear(char *bitmap, size_t n);
uint8_t bitmap_get(char *bitmap, size_t n);
#define MIN(a, b) ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
_a < _b ? _a : _b; \
})
#define MAX(a, b) ({ \
typeof(a) _a = (a); \
typeof(b) _b = (b); \
_a > _b ? _a : _b; \
})
#endif /* _MATH_H_ */