Avatar
omochimetaru 3/11/2020 7:35 AM
Notes on Approach The key idea here is using the bytes of a UInt64 in a way similarly to SIMD. When doing ASCII operations the new UTF-8 backing of Strings makes them perfectly suited for this technique. Aside from integer parsing, for example also ASCII case manipulation sees many-X speed-ups when using this approach. Example (details below): let str = 0x3132_3030_3633_3739 // ASCII "12006379" let digits = str &- 0x3030_3030_3030_3030 // Subtract "0" from every lane // … (underflow check omitted for clarity) let c = (0x7f - 9) &* 0x0101_0101_0101_0101 // Constant to check value > 9 let isAnyAbove9 = (digits &+ c) & 0x8080_8080_8080_8080 != 0
7:36 AM
文字列バッファを1文字ずつ読むんじゃなくて、8バイト分のビットバッファとみなして、ビット演算使ってまとめて8文字ずつ処理していくと。