I was reading a C++ paper on if consteval (§3.2), and saw a code showing a constexpr
strlen
implementation:
constexpr size_t strlen(char const* s) {
if constexpr (std::is_constant_evaluated()) {
for (const char *p = s; ; ++p) {
if (*p == '\0') {
return static_cast<std::size_t>(p - s);
}
}
} else {
__asm__("SSE 4.2 insanity");
}
}
I'm here to ask about the __asm__
statement in the else branch.
I know that's humour and not meant to be taken seriously, but I still decided to do some researches in case someone already explained it. When I googled the quoted message I had less than 10 results, all about this piece of code. I then researched what is SSE 4.2 and found that it's a CPU instruction set, so I really have no clue about what it appears in a C++ paper, does someone have an explanation? Thanks to those who'll read my post.