[clang] [Clang][Lexer] Reland "Detect SSE4.2 availability at runtime in fastParseASCIIIdentifier" (PR #175452)

Martin Storsjö via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 12 03:41:16 PST 2026


================
@@ -1919,10 +1921,21 @@ bool Lexer::LexUnicodeIdentifierStart(Token &Result, uint32_t C,
   return true;
 }
 
-static const char *
-fastParseASCIIIdentifier(const char *CurPtr,
-                         [[maybe_unused]] const char *BufferEnd) {
-#ifdef __SSE4_2__
+static const char *fastParseASCIIIdentifierScalar(const char *CurPtr) {
+  unsigned char C = *CurPtr;
+  while (isAsciiIdentifierContinue(C))
+    C = *++CurPtr;
+  return CurPtr;
+}
+
+// Fast path for lexing ASCII identifiers using SSE4.2 instructions.
+// Only enabled on x86/x86_64 when building with a compiler that supports
+// the 'target' attribute, which is used for runtime dispatch. Otherwise, we
+// fall back to the scalar implementation.
+#if (defined(__i386__) || defined(__x86_64__)) && defined(__has_attribute) &&  \
+    __has_attribute(target) && !defined(_WIN32)
----------------
mstorsjo wrote:

The target attribute should work just fine, I would expect.

Function multiversioning isn't supported by GCC on Windows. With Clang it is, at least for windows-aarch64; it was implemented somewhat recently (within the last 1-2 years), but I don't remember if it was done specifically only for aarch64 or generally for all architectures.

If you produce minimal test snippets for each of those cases, it should be easy to try; I can try locally, or we can try on Godbolt. (For clang, you can choose any clang setup there and just add `-target x86_64-windows-gnu` or `-target x86_64-windows-msvc`.)

https://github.com/llvm/llvm-project/pull/175452


More information about the cfe-commits mailing list