Skip to main content
QUICK REVIEW

[论文解读] A Fast x86 Implementation of Select

Prashant Pandey, Michael A. Bender|arXiv (Cornell University)|Jun 3, 2017
Algorithms and Data Compression参考文献 10被引用 4
一句话总结

本文提出 PTSelect,一种基于 Intel Haswell 指令集的 x86 高度优化实现,用于在 64 位字上执行 select 操作,仅使用四条指令——其中两条为 Intel Haswell 特有指令(pdep 和 tzcnt)。该实现相较以往最先进的机器字 select 实现,性能提升达 2× 至 4×,并通过提升指令级并行性和内存访问效率,在完整位向量 select 操作中实现 20% 至 68% 的性能增益,尽管每个位向量 select 仅调用一次机器字 select。

ABSTRACT

Rank and select are fundamental operations in succinct data structures, that is, data structures whose space consumption approaches the information-theoretic optimal. The performance of these primitives is central to the overall performance of succinct data structures. Traditionally, the select operation is the harder to implement efficiently, and most prior implementations of select on machine words use 50--80 machine instructions. (In contrast, rank on machine words can be implemented in only a handful of instructions on machines that support POPCOUNT.) However, recently Pandey et al. gave a new implementation of machine-word select that uses only four x86 machine instructions; two of which were introduced in Intel's Haswell CPUs. In this paper, we investigate the impact of this new implementation of machine-word select on the performance of general bit-vector-select. We first compare Pandey et al.'s machine-word select to the state-of-the-art implementations of Zhou et al. (which is not specific to Haswell) and Gog et al. (which uses some Haswell-specific instructions). We exhibit a speedup of 2X to 4X. We then study the impact of plugging Pandey et al.'s machine-word select into two state-of-the-art bit-vector-select implementations. Both Zhou et al.'s and Gog et al.'s select implementations perform a single machine-word select operation for each bit-vector select. We replaced the machine-word select with the new implementation and compared performance. Even though there is only a single machine- word select operation, we still obtained speedups of 20% to 68%. We found that the new select not only reduced the number of instructions required for each bit-vector select, but also improved CPU instruction cache performance and memory-access parallelism.

研究动机与目标

  • 提升简洁数据结构中 select 操作的性能,因其对实际效率至关重要。
  • 解决由传统慢速机器字 select 实现(通常需 50–80 条指令)导致的性能瓶颈。
  • 评估一种新型高度优化的机器字 select 实现(PTSelect)对端到端位向量 select 性能的影响。
  • 探究指令数量与内存级并行性在大规模位向量操作中对性能的影响。

提出的方法

  • 仅使用四条 x86 指令实现机器字 select:pdep(并行位投放)和 tzcnt(尾随零计数),二者均于 Intel Haswell 中引入。
  • 在两个最先进的位向量 select 库(CS-Poppy 和 SDSL)中,用 PTSelect 替代传统的 broadword 或 SSE 基 select 实现。
  • 通过测量不同位向量大小下的性能,分离分析指令数量、缓存未命中与内存级并行性的影响。
  • 分析 CPU 指令窗口利用率与并发内存访问模式,以解释性能差异。
  • 使用基于 Zhou 等人 CS-Poppy 的自定义基准测试套件,比较不同实现的执行时间与内存并行性。
  • 同时评估机器字 select 与完整位向量 select 的性能,以隔离优化原 primitive 的贡献。

实验结果

研究问题

  • RQ1PTSelect 在原始性能与指令数量方面与现有机器字 select 实现相比如何?
  • RQ2为何 PTSelect 即使在内存延迟主导大规模位向量时仍表现更优?
  • RQ3减少机器字 select 中的指令数量在多大程度上提升了整体位向量 select 性能?
  • RQ4指令级并行性与内存级并行性如何影响大规模数据结构中 select 操作的性能?
  • RQ5在低级别 primitive(如机器字 select)中极简的指令数量是否能为更高层级的简洁数据结构带来显著性能提升?

主要发现

  • 在机器字 select 基准测试中,PTSelect 相较 CS-Poppy 和 SDSL 实现 2× 至 4× 的性能提升,尽管其仅使用 12 条指令,而后者分别使用 80 和 49 条。
  • 当用 PTSelect 替代 CS-Poppy 中的默认机器字 select 时,完整位向量 select 的性能提升达 20% 至 68%。
  • 尽管每个位向量 select 仅调用一次机器字 select,但随着位向量增大,性能显著提升,原因在于内存级并行性提高。
  • PTSelect 平均可支持 8 次并发内存访问,而 CS-Poppy 为 3 次,SDSL 为 4 次,这是由于其更短的指令序列能容纳更多操作于 CPU 的指令窗口中。
  • PTSelect 的性能优势不仅源于更少的指令,还源于更高的内存级并行性,从而在现代 CPU 上提升吞吐量。
  • 结果表明,即使内存延迟是主要成本,指令数量与并行性仍是低级别 primitive 中的关键因素。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。