Use __builtin_ctz and __builtin_clz in dlmalloc#18186
Use __builtin_ctz and __builtin_clz in dlmalloc#18186kripken merged 3 commits intoemscripten-core:mainfrom
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`.
|
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 | |||
| /* 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.
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.
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.ctzandi32.clz. Without this, the various macros fall back to a C implementation which does not seem to be detected asctzorclzoperations by clang at-O3.