在两纳秒内将整数转换为十进制字符串
Converting an Integer to a Decimal String in Under Two Nanoseconds
AI总结:
本文提出了一种基于SIMD的算法,利用现代AMD和Intel处理器的整数乘加指令,高效地将二进制整数转换为可变长度的十进制字符串,同时引入双变体设计以适应不同输入特性。
摘要:
将二进制整数转换为可变长度的十进制字符串是计算中的基本操作。传统快速方法依赖于递归除法和小查找表。我们提出了一种基于SIMD的算法,利用现代AMD和Intel处理器上的整数乘加指令。我们的方法完全消除了查找表,并通过并行计算多个商和余数。此外,我们引入了一种双变体设计,具有动态选择机制,以适应输入特性:一种分支密集型变体优化于同质数字长度分布,另一种分支稀疏型变体适用于异质数据集。我们的单核算法在整数大小的整个范围内均优于所有竞争方法,在测试工作负载中比最接近的竞争对手快1.4-2倍,比C++标准库函数std::to_chars快2-4倍。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。