Skip to content

Commit 15881fc

Browse files
committed
move code
1 parent 6f083a5 commit 15881fc

File tree

2 files changed

+65
-75
lines changed

2 files changed

+65
-75
lines changed

src/pool/pool_disjoint.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,71 @@ umf_disjoint_pool_params_t *AllocImpl_getParams(AllocImpl *ai) {
701701
return &ai->params;
702702
}
703703

704+
size_t AllocImpl_sizeToIdx(AllocImpl *ai, size_t size) {
705+
assert(size <= CutOff && "Unexpected size");
706+
assert(size > 0 && "Unexpected size");
707+
708+
size_t MinBucketSize = (size_t)1 << ai->MinBucketSizeExp;
709+
if (size < MinBucketSize) {
710+
return 0;
711+
}
712+
713+
// Get the position of the leftmost set bit.
714+
size_t position = getLeftmostSetBitPos(size);
715+
716+
bool isPowerOf2 = 0 == (size & (size - 1));
717+
bool largerThanHalfwayBetweenPowersOf2 =
718+
!isPowerOf2 && (bool)((size - 1) & ((uint64_t)(1) << (position - 1)));
719+
size_t index = (position - ai->MinBucketSizeExp) * 2 + (int)(!isPowerOf2) +
720+
(int)largerThanHalfwayBetweenPowersOf2;
721+
722+
return index;
723+
}
724+
725+
umf_disjoint_pool_shared_limits_t *AllocImpl_getLimits(AllocImpl *ai) {
726+
if (ai->params.SharedLimits) {
727+
return ai->params.SharedLimits;
728+
} else {
729+
return ai->DefaultSharedLimits;
730+
}
731+
}
732+
733+
bucket_t *AllocImpl_findBucket(AllocImpl *ai, size_t Size) {
734+
size_t calculatedIdx = AllocImpl_sizeToIdx(ai, Size);
735+
bucket_t *bucket = ai->buckets[calculatedIdx];
736+
assert(bucket_get_size(bucket) >= Size);
737+
(void)bucket;
738+
739+
if (calculatedIdx > 0) {
740+
bucket_t *bucket_prev = ai->buckets[calculatedIdx - 1];
741+
assert(bucket_get_size(bucket_prev) < Size);
742+
(void)bucket_prev;
743+
}
744+
745+
return ai->buckets[calculatedIdx];
746+
}
747+
748+
void AllocImpl_printStats(AllocImpl *ai, bool *TitlePrinted,
749+
size_t *HighBucketSize, size_t *HighPeakSlabsInUse,
750+
const char *MTName) {
751+
(void)TitlePrinted; // TODO
752+
(void)MTName; // TODO
753+
754+
*HighBucketSize = 0;
755+
*HighPeakSlabsInUse = 0;
756+
for (size_t i = 0; i < ai->buckets_num; i++) {
757+
// TODO
758+
//(*B).printStats(TitlePrinted, MTName);
759+
bucket_t *bucket = ai->buckets[i];
760+
*HighPeakSlabsInUse =
761+
utils_max(bucket->maxSlabsInUse, *HighPeakSlabsInUse);
762+
if (bucket->allocCount) {
763+
*HighBucketSize =
764+
utils_max(bucket_slab_alloc_size(bucket), *HighBucketSize);
765+
}
766+
}
767+
}
768+
704769
#ifdef __cplusplus
705770
}
706771
#endif

src/pool/pool_disjoint.cpp

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -271,50 +271,6 @@ void *AllocImpl_allocate_align(AllocImpl *ai, size_t Size, size_t Alignment,
271271
return (void *)ALIGN_UP((size_t)Ptr, Alignment);
272272
}
273273

274-
size_t AllocImpl_sizeToIdx(AllocImpl *ai, size_t Size) {
275-
assert(Size <= CutOff && "Unexpected size");
276-
assert(Size > 0 && "Unexpected size");
277-
278-
size_t MinBucketSize = (size_t)1 << ai->MinBucketSizeExp;
279-
if (Size < MinBucketSize) {
280-
return 0;
281-
}
282-
283-
// Get the position of the leftmost set bit.
284-
size_t position = getLeftmostSetBitPos(Size);
285-
286-
auto isPowerOf2 = 0 == (Size & (Size - 1));
287-
auto largerThanHalfwayBetweenPowersOf2 =
288-
!isPowerOf2 && bool((Size - 1) & (uint64_t(1) << (position - 1)));
289-
auto index = (position - ai->MinBucketSizeExp) * 2 + (int)(!isPowerOf2) +
290-
(int)largerThanHalfwayBetweenPowersOf2;
291-
292-
return index;
293-
}
294-
295-
umf_disjoint_pool_shared_limits_t *AllocImpl_getLimits(AllocImpl *ai) {
296-
if (ai->params.SharedLimits) {
297-
return ai->params.SharedLimits;
298-
} else {
299-
return ai->DefaultSharedLimits;
300-
}
301-
};
302-
303-
bucket_t *AllocImpl_findBucket(AllocImpl *ai, size_t Size) {
304-
auto calculatedIdx = AllocImpl_sizeToIdx(ai, Size);
305-
bucket_t *bucket = ai->buckets[calculatedIdx];
306-
assert(bucket_get_size(bucket) >= Size);
307-
(void)bucket;
308-
309-
if (calculatedIdx > 0) {
310-
bucket_t *bucket_prev = ai->buckets[calculatedIdx - 1];
311-
assert(bucket_get_size(bucket_prev) < Size);
312-
(void)bucket_prev;
313-
}
314-
315-
return ai->buckets[calculatedIdx];
316-
}
317-
318274
umf_result_t AllocImpl_deallocate(AllocImpl *ai, void *Ptr, bool *ToPool) {
319275
if (Ptr == nullptr) {
320276
return UMF_RESULT_SUCCESS;
@@ -370,27 +326,6 @@ umf_result_t AllocImpl_deallocate(AllocImpl *ai, void *Ptr, bool *ToPool) {
370326
return UMF_RESULT_SUCCESS;
371327
}
372328

373-
void AllocImpl_printStats(AllocImpl *ai, bool &TitlePrinted,
374-
size_t &HighBucketSize, size_t &HighPeakSlabsInUse,
375-
const std::string &MTName) {
376-
(void)TitlePrinted; // TODO
377-
(void)MTName; // TODO
378-
379-
HighBucketSize = 0;
380-
HighPeakSlabsInUse = 0;
381-
for (size_t i = 0; i < ai->buckets_num; i++) {
382-
// TODO
383-
//(*B).printStats(TitlePrinted, MTName);
384-
bucket_t *bucket = ai->buckets[i];
385-
HighPeakSlabsInUse =
386-
utils_max(bucket->maxSlabsInUse, HighPeakSlabsInUse);
387-
if (bucket->allocCount) {
388-
HighBucketSize =
389-
utils_max(bucket_slab_alloc_size(bucket), HighBucketSize);
390-
}
391-
}
392-
}
393-
394329
umf_result_t DisjointPool::initialize(umf_memory_provider_handle_t provider,
395330
umf_disjoint_pool_params_t *parameters) {
396331
if (!provider) {
@@ -509,13 +444,3 @@ static umf_memory_pool_ops_t UMF_DISJOINT_POOL_OPS =
509444
umf_memory_pool_ops_t *umfDisjointPoolOps(void) {
510445
return &UMF_DISJOINT_POOL_OPS;
511446
}
512-
513-
// TODO remove
514-
#ifdef __cplusplus
515-
extern "C" {
516-
#endif
517-
518-
#ifdef __cplusplus
519-
}
520-
#endif
521-
// end TODO remove

0 commit comments

Comments
 (0)