-
Notifications
You must be signed in to change notification settings - Fork 8k
Use alignment builtins for ZEND_MM_ALIGNED macros #21913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -175,12 +175,25 @@ static size_t _real_page_size = ZEND_MM_PAGE_SIZE; | |
| typedef uint32_t zend_mm_page_info; /* 4-byte integer */ | ||
| typedef zend_ulong zend_mm_bitset; /* 4-byte or 8-byte integer */ | ||
|
|
||
| #define ZEND_MM_ALIGNED_OFFSET(size, alignment) \ | ||
| (((size_t)(size)) & ((alignment) - 1)) | ||
| #define ZEND_MM_ALIGNED_BASE(size, alignment) \ | ||
| (((size_t)(size)) & ~((alignment) - 1)) | ||
| #define ZEND_MM_SIZE_TO_NUM(size, alignment) \ | ||
| #ifdef PHP_HAVE_BUILTIN_ALIGN_DOWN | ||
| # define ZEND_MM_ALIGNED_BASE(ptr, alignment) \ | ||
| __builtin_align_down((ptr), (alignment)) | ||
| # define ZEND_MM_ALIGNED_OFFSET(ptr, alignment) \ | ||
| (((size_t)(ptr)) - (size_t)ZEND_MM_ALIGNED_BASE(ptr, alignment)) | ||
| #else | ||
| # define ZEND_MM_ALIGNED_BASE(ptr, alignment) \ | ||
| (((uintptr_t)(ptr)) & ~((alignment) - 1)) | ||
| # define ZEND_MM_ALIGNED_OFFSET(ptr, alignment) \ | ||
| (((size_t)(ptr)) & ((alignment) - 1)) | ||
| #endif | ||
|
|
||
| #ifdef PHP_HAVE_BUILTIN_ALIGN_UP | ||
| # define ZEND_MM_SIZE_TO_NUM(size, alignment) \ | ||
| (__builtin_align_up((size), (alignment)) / (alignment)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this usage of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, this one actually only works with |
||
| #else | ||
| # define ZEND_MM_SIZE_TO_NUM(size, alignment) \ | ||
| (((size_t)(size) + ((alignment) - 1)) / (alignment)) | ||
| #endif | ||
|
|
||
| #define ZEND_MM_BITSET_LEN (sizeof(zend_mm_bitset) * 8) /* 32 or 64 */ | ||
| #define ZEND_MM_PAGE_MAP_LEN (ZEND_MM_PAGES / ZEND_MM_BITSET_LEN) /* 16 or 8 */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this a bit more, I'm not sure we want the result of
ZEND_MM_ALIGNED_BASEto be of the type ofptr, as the base has a different type in every case. I guess we could cast tovoid*before passing to__builtin_align_down? Then the result isvoid*, which would force coercion to an appropriate type. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there would be benefit in
ZEND_MM_ALIGNED_BASEmapping directly to the builtin.That being said, currently the two implementations return different types (
uintptr_tvsT*). I guess it might be more consistent to ensure the result for both isvoid*.