clz macro

This commit is contained in:
dzaima 2021-09-05 21:05:19 +03:00
parent e5338e931f
commit 4299fef6b6
5 changed files with 5 additions and 8 deletions

View File

@ -63,10 +63,6 @@ SOFTWARE.
#define MIN(x,y) (((x) < (y) ? (x) : (y)))
#endif
#ifndef CLZ
#define CLZ __builtin_clzll
#endif
static inline int compute_minrun(const uint64_t size) {
const int top_bit = 64 - CLZ(size);
const int shift = MAX(top_bit, 6) - 6;

View File

@ -114,6 +114,7 @@
#define FORCE_INLINE __attribute__((always_inline)) static inline
#define NORETURN __attribute__((noreturn))
#define AUTO __auto_type
#define CLZ(X) __builtin_clzll(X)
#define LIKELY(X) __builtin_expect(X,1)
#define RARE(X) __builtin_expect(X,0)
#define fsizeof(T,F,E,N) (offsetof(T, F) + sizeof(E)*(N)) // type, flexible array member name, flexible array member type, item amount

View File

@ -18,7 +18,7 @@
EmptyValue* mmX_buckets[64];
u64 mmX_ctrs[64];
#define BSZ(X) (1ull<<(X))
#define BSZI(X) ((u8)(64-__builtin_clzl((X)-1ull)))
#define BSZI(X) ((u8)(64-CLZ((X)-1ull)))
#define MMI(X) X
#define BN(X) mmX_##X
#include "../opt/mm_buddyTemplate.h"
@ -27,7 +27,7 @@ u64 mmX_ctrs[64];
#define PROT PROT_READ|PROT_WRITE|PROT_EXEC
#define FLAGS MAP_NORESERVE|MAP_PRIVATE|MAP_ANON|MAP_32BIT
#include "../opt/mm_buddyTemplate.c"
static void* mmX_allocN(usz sz, u8 type) { assert(sz>=16); return mmX_allocL(64-__builtin_clzl(sz-1ull), type); }
static void* mmX_allocN(usz sz, u8 type) { assert(sz>=16); return mmX_allocL(64-CLZ(sz-1ull), type); }
#undef BN
#undef BSZ

View File

@ -19,7 +19,7 @@ extern EmptyValue* mm_buckets[128];
#include "mm_buddyTemplate.h"
#define LOG2(X) ((u8)(64-__builtin_clzl((X)-1ull)))
#define LOG2(X) ((u8)(64-CLZ((X)-1ull)))
static void* mm_alloc(usz sz, u8 type) {
assert(sz>=16);
u32 log = LOG2(sz);

View File

@ -19,7 +19,7 @@ extern EmptyValue* mm_buckets[64];
#include "mm_buddyTemplate.h"
#define LOG2(X) ((u8)(64-__builtin_clzl((X)-1ull)))
#define LOG2(X) ((u8)(64-CLZ((X)-1ull)))
static void* mm_alloc(usz sz, u8 type) {
assert(sz>=16);
onAlloc(sz, type);