[libc-commits] [libc] [libc] Add wcscasecmp and wcsncasecmp implementations. (PR #222154)
Alex Strelnikov via libc-commits
libc-commits at lists.llvm.org
Wed Sep 9 06:52:03 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));
+}
+
----------------
strel-12 wrote:
Thanks for remembering to check, I've updated the threeway compare.
After our conversation yesterday, I decided not to mail out the PR with the version treating invalid UTF-32 as undefined. I remembered to compare the codegen between the version I mailed out and one using the `(a > 0) - (a < 0)` pattern, but I forgot to recheck against the `if` version.
https://github.com/llvm/llvm-project/pull/222154
More information about the libc-commits
mailing list