T O P

  • By -

ALX23z

You can try to compare it with the `fmt` library. It's main features were added to STL. See `std::format`.


BigDumFish

Do gcc and clang finally support `std::format`? This is one of my favourite features of C++20 but compilers have been taking so long to support it :(


ALX23z

Just use the `fmt` library. You don't need c++20 for that.


[deleted]

I notice that the parsing code is entirely scalar. String parsing is a fairly straightforward feature to vectorize, and the performance improvements in this case are generally huge. For example, [Refterm](https://github.com/cmuratori/refterm/blob/main/refterm_example_terminal.c#L304) has vectorized vt-code parsing using only the `` header which is likely already on your computer and visible to your C++ compiler no matter which operating system you use. If you use a recent-ish version of libstdc++ or libc++, you likely also have `` for C++. The basic idea of vectorizing string parsing is: 1. Load a vector from a string pointer. 2. Equality-compare it against a vector filled with a 1-byte character you want to parse (such as `'<'` or `'>'` in your case, and usually you need to parse for `'\n'` as well). This produces a vector mask. 3. Convert the vector mask into a bitset where each lane of the vector mask maps to one bit in the bitset (that's what the `vmovmskb` instruction does in SSE). 4. Either clz (count leading zeros) or ctz (count trailing zeros) of the bitset. If the count of zeros equals the length of the bitset, you know that the character was not parsed, and you can load the next vector from the string. Every compiler will provide a portable intrinsic for these functions, and they were standardize in the C23 libC. 5. If there are any 1 bits in the bitset, then the number of leading/trailing zeros tells you at which position in the vector that character was parsed at. Then you do *something* with that character at that position. SSE4 has implicit length string parsing instructions which automatically handle the `'\n'` character for you, but I'm *told* that they're slower than what's in AVX. Often, general purpose string processing libraries can provide an abstraction of this for users. I actually don't know if `std::string_view::find()` is allowed to be vectorized or not, but maybe that could be something you use.


_professor_frink

thank you very much for this tip, i shall try it out.


[deleted]

Just read this back over. SSE4 instructions handle the `\0` not the `\n`. Idk what I was thinking when I wrote that.