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

View File

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