-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Use __builtin_ctz and __builtin_clz in dlmalloc #18186
Conversation
This operation maps to the WebAssembly instruction `i32.ctz`. Without this, the `compute_bit2idx` macro falls back to a C implementation which does not seem to be detected as a ctz operation by clang at `-O3`.
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.
Nice!
Could the emscripten/system/lib/dlmalloc.c Lines 2920 to 2932 in 39a7a63
Otherwise, it falls back on this variant: emscripten/system/lib/dlmalloc.c Lines 2964 to 2980 in 39a7a63
(though, perhaps the compiler might already optimize this, untested) |
@kleisauke ah, good catch! I'll add that in to this commit |
Head branch was pushed to by a user without write access
Head branch was pushed to by a user without write access
@@ -1 +1 @@ | |||
4525 | |||
4224 |
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.
Wow, nice improvements!
@@ -3020,7 +3020,7 @@ I = (K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1));\ | |||
|
|||
/* index corresponding to given bit. Use x86 asm if possible */ | |||
|
|||
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) | |||
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__) || defined(__EMSCRIPTEN__)) |
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 wonder this doesn't use #if __has_builtin(__builtin_ctz)
.. I guess maybe dlmalloc was written before such a macro existed?
I also wonder if we should use __wasm__
here instead of __EMSCRIPTEN__
? I guess it doesn't matter much since if there is almost no chance of upstreaming these chagnes.
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.
Yeah, __wasm__
probably is a better choice; I used __EMSCRIPTEN__
since that was used by other modifications in that file.
These operations map to the WebAssembly instructions
i32.ctz
andi32.clz
. Without this, the various macros fall back to a C implementation which does not seem to be detected asctz
orclz
operations by clang at-O3
.