[libc-commits] [libc] [libc] Add wcscasecmp and wcsncasecmp implementations. (PR #222154)
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Tue Sep 8 16:54:35 PDT 2026
================
@@ -796,6 +797,15 @@ is_char_or_wchar(wchar_t ch, [[maybe_unused]] char, wchar_t wc_value) {
return (ch == wc_value);
}
+// Returns a three-way comparison between two wide character code points.
+LIBC_INLINE int threeway_cmp_single(wchar_t left, wchar_t right) {
+ // Valid UTF-32 code points are in [0, 0x10FFFF]. If invalid code points were
+ // treated as UB, the comparison below could instead be done in 32 bits.
+ uint64_t diff = static_cast<uint64_t>(left) - static_cast<uint64_t>(right);
+ return cpp::bit_cast<int32_t>(static_cast<uint32_t>(diff >> 32) |
+ static_cast<uint32_t>(diff & 0xFFFF));
+}
+
----------------
michaelrj-google wrote:
I was looking into if this optimization was effective on godbolt: https://godbolt.org/z/6exE3qnsj
It looks like the naive approach gets pretty much optimized away by the compiler. Given that I think the naive approach is probably a better option.
https://github.com/llvm/llvm-project/pull/222154
More information about the libc-commits
mailing list