News for hackers. Stuff that matters.
Re:Six times faster than C by LegionMammal978 on Friday July 07, 2023 @08:32AM (#36630720)
In practice, GCC and Clang don't seem to have any issues inlining the necessary part of strlen at -O1 or higher (https://godbolt.org/z/rM198aYea). But MSVC inlines the empty-string case, while still calling out for nonempty strings, probably since it doesn't realize that the returned length will be nonzero.
Re:Six times faster than C by stkdump on Saturday July 08, 2023 @02:17AM (#36641830)
I guess since strlen uses an unsigned size, which has specified overflow behavior the compiler not only has to proof the initial iteration, but also all the ULLONG_MAX+1 multiples, which of course refer to the same memory address. But maybe its harder for the optimizer to see.