Day 22 of Advent of Compiler Optimisations!

Comparing a string_view against "ABCDEFG" should call memcmp, right? Watch what Clang actually generates — no function call at all, just a handful of inline instructions using some rather cunning tricks. How does it compare 7 bytes so efficiently when they don't fit in a single register?

Read more: https://xania.org/202512/22-memory-cunningness
Watch: https://youtu.be/kXmqwJoaapg

#AoCO2025

Clever memory tricks — Matt Godbolt’s blog

We learn that compilers have tricks to access memory efficiently

@mattgodbolt WTF. I'm really disappointed that Clang is not smart enough to do

t1:
cmp rdi, 1 ; is length 1?
jne .LBB0_1 ; if not 1, goto "return false"
cmp byte ptr [rsi], 65 ; is the byte 65 ('A')?
.LBB0_1:
sete al ; set result to 0 or 1 accordingly
ret ; return
@riley these kinds of things are always worth asking the clang Devs and/or filing bugs to report :). Even if we don't know how to improve the compiler ourselves, a respectful issue request can help them help us!
@mattgodbolt Yeah, that would seem like good idea, but I'm afraid I'm probably juggling too many rabbit-holes for my dwindling spoon collection already.