summaryrefslogtreecommitdiff
path: root/include/mimalloc-internal.h
diff options
context:
space:
mode:
authordaan <daanl@outlook.com>2019-07-22 20:51:12 -0700
committerdaan <daanl@outlook.com>2019-07-23 15:00:13 -0700
commit189ad0f81dc3b029c05a3b7cf19d8ba78c4e0429 (patch)
tree34365bd1bde718b1aa643117a2b81dc745a225d5 /include/mimalloc-internal.h
parent66b8c37ab396553ad43f332ebf6d1abc55c98ef3 (diff)
small optimizations, use bitwise aligne
Diffstat (limited to 'include/mimalloc-internal.h')
-rw-r--r--include/mimalloc-internal.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h
index cbed590..e261dba 100644
--- a/include/mimalloc-internal.h
+++ b/include/mimalloc-internal.h
@@ -39,7 +39,6 @@ bool _mi_preloading(); // true while the C runtime is not ready
// os.c
size_t _mi_os_page_size(void);
-uintptr_t _mi_align_up(uintptr_t sz, size_t alignment);
void _mi_os_init(void); // called from process init
void* _mi_os_alloc(size_t size, mi_stats_t* stats); // to allocate thread local data
void _mi_os_free(void* p, size_t size, mi_stats_t* stats); // to free thread local data
@@ -165,6 +164,20 @@ static inline bool mi_mul_overflow(size_t size, size_t count, size_t* total) {
#endif
}
+// Align upwards
+static inline uintptr_t _mi_is_power_of_two(uintptr_t x) {
+ return ((x & (x - 1)) == 0);
+}
+static inline uintptr_t _mi_align_up(uintptr_t sz, size_t alignment) {
+ uintptr_t mask = alignment - 1;
+ if ((alignment & mask) == 0) { // power of two?
+ return ((sz + mask) & ~mask);
+ }
+ else {
+ return (((sz + mask)/alignment)*alignment);
+ }
+}
+
// Align a byte size to a size in _machine words_,
// i.e. byte size == `wsize*sizeof(void*)`.
static inline size_t _mi_wsize_from_size(size_t size) {
@@ -324,12 +337,23 @@ static inline void mi_block_set_nextx(uintptr_t cookie, mi_block_t* block, mi_bl
}
static inline mi_block_t* mi_block_next(mi_page_t* page, mi_block_t* block) {
+ #if MI_SECURE
return mi_block_nextx(page->cookie,block);
+ #else
+ UNUSED(page);
+ return mi_block_nextx(0, block);
+ #endif
}
static inline void mi_block_set_next(mi_page_t* page, mi_block_t* block, mi_block_t* next) {
+ #if MI_SECURE
mi_block_set_nextx(page->cookie,block,next);
+ #else
+ UNUSED(page);
+ mi_block_set_nextx(0, block, next);
+ #endif
}
+
// -------------------------------------------------------------------
// Getting the thread id should be performant
// as it is called in the fast path of `_mi_free`,