After years of working on parsers I write expressions like this mechanically: unsigned((ch | ‘ ‘) - ‘a’) < 26 ... and forget that this isn’t obvious.
-
-
Vastauksena käyttäjälle @zeuxcg
Whenever I see tricks like this, I just have to godbolt it. https://godbolt.org/z/ADn06R Looks like much better than a naive implementation with no optimizations, but in -O3 the naive one looks marginally better. Haven't checked gcc or msvc.
2 vastausta 0 uudelleentwiittausta 1 tykkäys -
Vastauksena käyttäjälle @tloch14
Typically the character will be sign-extended and the result will be branched upon, so you get or+sub+cmp+ja which is probably optimal. The codegen for naive version is highly dependent on the compiler - likely way worse for MSVC
1 vastaus 0 uudelleentwiittausta 1 tykkäys
> likely way worse for MSVC After doing enough godbolt compares between clang/gcc/msvc, I've found this to almost always be the case. (Just tested--with /O2, msvc has two jumps). I'm still trying to figure out what clang is doing with the naive one.
Lataaminen näyttää kestävän hetken.
Twitter saattaa olla ruuhkautunut tai ongelma on muuten hetkellinen. Yritä uudelleen tai käy Twitterin tilasivulla saadaksesi lisätietoja.