Standard C++ provides a few functions to convert a double or float value to string, namely, sprintf, stringstream::operator<<, snprintf, to_string, to_chars and format. This talk concerns what goes on behind the scenes, i.e, the algorithms which these functions might use to do their job. Curiously, many of these algorithms have dragon-related names like Dragon, Grisu, Errol, Ryu and Dragonbox. Here mythology meets technology and we shall introduce the new dragon that has just arrived in the den. (Please leave your bows and arrows at home, they won't be necessary here.)
This talk concerns calendar algorithms which I implemented in the Linux Kernel and in libstdc++ (<chrono>). One of them has been ported to C# and released in .NET 7. I show some optimisation results that explain why these algorithms are so suited for modern CPUs. These optimisations might be useful elsewhere since benchmark results show that our algorithms perform considerably faster than counterparts in libc++, boost, OpenJDK, Android phones and other popular open source libraries. Most results are strength reduction techniques not used by any optimising compiler. Another technique breaks a data-dependency that commonly appears in division/modulus calculations and by […]