Simdutf is now constexpr!

I have spent the christmas holidays implementing constexpr support in simdutf. It is now possible to validate and convert text between different encodings such as UTF-8/16/32 at compile time.

Never heard of simdutf? It is an open source C++ library which is used under the hood by Chrome, Safari and other projects.

The cool thing is that the API is the same. It all hinges on the C++23 consteval feature. Here is what the usage may look like:

Article content
Example usage, this could be a unit test.

This makes writing unit tests so nice - instant feedback in the IDE and if it compiles, it means the unit test passed, you don't even have to run it.

Here is a simplified version of what the implementation looks like:

Article content
A simplified version of the implementation.

The function declared on row 430 is the existing pointer based api which internally dispatches to the best supported SIMD backend. If using the span api on row 433, different things happen if the function is evaluated at compile time or runtime. There is no runtime penalty for this dispatch between compile and runtime, it all happens during compilation.

So, what about compile times, since more of the implementation now has to be included in the header file? Not so bad, this costs around 3%.

Ja, när man får till något hyggligt komplicerat med consteval så är det läge att känna sig nöjd! Gott nytt!

Hoppas att det var givande Paul! Gott Nytt År!

Like
Reply

To view or add a comment, sign in

More articles by Paul Dreik

  • Encrypted communication should be protected by law!

    There is an absurd proposal from the Swedish government about forcing messaging services to provide access to…

  • Watch me talk about code quality

    I recently held a 10 minute talk at the SwedenCpp::Stockholm C++ meetup. It is an overview about how to improve and…

    1 Comment
  • Meeting c++ 2016 trip report

    This was my first time to meeting c++! I really enjoyed the atmosphere and talking to other enthusiasts. Here are some…

  • Latest features added to c++17

    The last meeting to add new features to c++17 was finished last week! There is a lot added on this meeting which is…

  • Playing FizzBuzz at compile time

    Heard of the game fizzbuzz? It is a great way to check for basic programming skills. Along came c++11 with variadic…

  • Cppcon 2015 trip report

    After watching most of the material from cppcon 2014 on youtube, I just had to go to cppcon 2015! And so I did. Here is…

    3 Comments
  • What did I do the last three years?

    Finally, I can share some details of what I have been doing for the past three years! Welcome to contact me for new…

    1 Comment
  • Gcc 5.1 is out!

    There are lots of exciting news in gcc 5. Some particularly interesting items are new flag -Wsuggest-final-types new…

Explore content categories