correct 3×2^n boundary check
This commit is contained in:
parent
9e1eae8e58
commit
ccd7669fc3
@ -41,7 +41,7 @@ void* mm_allocN(usz sz, u8 type) {
|
|||||||
assert(sz>12);
|
assert(sz>12);
|
||||||
onAlloc(sz, type);
|
onAlloc(sz, type);
|
||||||
u8 b1 = 64-__builtin_clzl(sz-1ull);
|
u8 b1 = 64-__builtin_clzl(sz-1ull);
|
||||||
if (sz*3 <= 1ull<<(b1+1)) return b3_allocL(b1-2, type);
|
if (sz <= (1ull<<(b1-2)) * 3) return b3_allocL(b1-2, type);
|
||||||
return b1_allocL(b1, type);
|
return b1_allocL(b1, type);
|
||||||
}
|
}
|
||||||
void mm_free(Value* x) {
|
void mm_free(Value* x) {
|
||||||
@ -51,6 +51,7 @@ void mm_free(Value* x) {
|
|||||||
|
|
||||||
u64 mm_round(usz sz) {
|
u64 mm_round(usz sz) {
|
||||||
u8 b1 = 64-__builtin_clzl(sz-1ull);
|
u8 b1 = 64-__builtin_clzl(sz-1ull);
|
||||||
if (sz*3 <= 1ull<<(b1+1)) return (1ull<<(b1-2)) * 3;
|
u64 s3 = (1ull<<(b1-2)) * 3;
|
||||||
|
if (sz<=s3) return s3;
|
||||||
return 1ull<<b1;
|
return 1ull<<b1;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user