Login
You're viewing the code4lib.social public feed.
  • Dec 1, 2026, 9:11 AM

    @nothings @pervognsen "Write down the position of every \n in the file" SIMDs up nicely and the speed you can run it at is certainly in the same ballpark as your L2$ bandwidth (details would depend on the exact impl and output format).

    One-byte-at-a-time branchy lexing certainly is not, especially when you take branches to count lines.

    💬 3🔄 0⭐ 0

Replies

  • 💬 0🔄 0⭐ 0
  • 💬 1🔄 0⭐ 0
  • Dec 1, 2026, 5:00 PM

    @rygorous Yep, my current fastest non-SIMD lexer approach is already multipass in two passes, the first pass uses a state machine to divide the stream into tokens of known types (1 mispredict at end of each token), and the second pass isn't actually a continuous pass, it iterates over each type of token (or really, each state machine final state) and does type-specific processing in a series of tight loops per type (avoids branch mispredict switching on token type). Def inspired by Oodle SIMD.

    💬 0🔄 0⭐ 0
  • Dec 1, 2026, 9:21 AM

    @rygorous @nothings Typically there's only a few places in a branch-based PL lexer where \n needs to be explicitly handled: the main lexer switch and inside quoted strings and comments; those few places can update the start-of-line pointer or add to a newline table or whatever. I do use the separate SIMD newline indexer if I have a separate fast indexing pass for top-level declarations.

    💬 0🔄 0⭐ 0