optimize fast allocation path

This commit is contained in:
dzaima 2021-07-05 02:52:42 +03:00
parent d063e83a8d
commit cd60db1c89
2 changed files with 12 additions and 6 deletions

View File

@ -15,7 +15,7 @@ AllocInfo* al;
u64 alCap;
u64 alSize;
NOINLINE EmptyValue* BN(makeEmpty)(u8 bucket) { // result->next is garbage
static void BN(guaranteeEmpty)(u8 bucket) {
u8 cb = bucket;
EmptyValue* c;
while (true) {
@ -56,8 +56,14 @@ NOINLINE EmptyValue* BN(makeEmpty)(u8 bucket) { // result->next is garbage
b->next = buckets[cb];
buckets[cb] = b;
}
return c;
c->next = buckets[cb];
buckets[cb] = c;
}
NOINLINE void* BN(allocS)(i64 bucket, u8 type) {
BN(guaranteeEmpty)(bucket);
return BN(allocL)(bucket, type);
}
void BN(forHeap)(V2v f) {
for (u64 i = 0; i < alSize; i++) {
AllocInfo ci = al[i];

View File

@ -12,7 +12,6 @@ extern AllocInfo* al;
extern u64 alCap;
extern u64 alSize;
extern NOINLINE EmptyValue* BN(makeEmpty)(u8 bucket); // result->next is garbage
static void BN(free)(Value* x) {
onFree(x);
@ -32,10 +31,11 @@ static void BN(free)(Value* x) {
x->type = t_empty;
}
static void* BN(allocL)(u8 bucket, u8 type) {
NOINLINE void* BN(allocS)(i64 bucket, u8 type);
static void* BN(allocL)(i64 bucket, u8 type) {
EmptyValue* x = buckets[bucket];
if (RARE(x==NULL)) x = BN(makeEmpty)(bucket);
else buckets[bucket] = x->next;
if (RARE(x==NULL)) return BN(allocS)(bucket, type);
buckets[bucket] = x->next;
#ifdef USE_VALGRIND
VALGRIND_MAKE_MEM_UNDEFINED(x, BSZ(bucket));
VALGRIND_MAKE_MEM_DEFINED(&x->mmInfo, 1);