Converting binary integers to variable-length decimal strings is a fundamental operation in computing. Conventional fast approaches rely on recursive division and small lookup tables. We propose a SIMD-based algorithm that leverages integer multiply-add instructions available on recent AMD and Intel processors. Our method eliminates lookup tables entirely and computes multiple quotients and remainders in parallel. Additionally, we introduce a dual-variant design with dynamic selection that adapts to input characteristics: a branch-heavy variant optimized for homogeneous digit-length distributions and a branch-light variant for heterogeneous datasets. Our single-core algorithm consistently outperforms all competing methods across the full range of integer sizes, running 1.4-2x faster than the closest competitor and 2-4x faster than the C++ standard library function std::to_chars across tested workloads.
翻译:将二进制整数转换为可变长度的十进制字符串是计算中的基本操作。传统快速方法依赖于递归除法和小型查找表。我们提出一种基于SIMD的算法,利用近期AMD和Intel处理器上可用的整数乘加指令。我们的方法完全消除了查找表,并并行计算多个商和余数。此外,我们引入了一种具有动态选择的双变体设计,可根据输入特征自适应调整:针对同质数字长度分布优化的一种重分支变体,以及针对异质数据集的一种轻分支变体。我们的单核算法在全部整数大小范围内始终优于所有竞争方法,在测试工作负载中运行速度比最接近的竞争者快1.4-2倍,比C++标准库函数std::to_chars快2-4倍。