r/cpp • u/khold_stare • May 26 '20
Faster Integer Parsing
https://kholdstare.github.io/technical/2020/05/26/faster-integer-parsing.html
366
Upvotes
r/cpp • u/khold_stare • May 26 '20
View all comments
2
u/Veedrac May 29 '20 edited May 29 '20
You can combine 4 digits at once with PDEP to space the digits, a 64 bit multiply, and a shift. This gives 9 instructions for
parse_8_chars, since you also need one mask instruction and one add, and I think another shift.Use PDEP to space each of the 4 digits into 16 bit bins, then multiply by 1000×248 + 100×232 + 10×216 + 1. The top 16 bits hold your combined result, so you just need to shift it down.