首页›Travis Downs›文章

A Note on Mask Registers

Travis Downs · 2019年12月5日

AI 摘要 AI 生成,可能有误

本文采用缓存未命中探测技术,测量了此前未见报道的 Skylake-X 上 AVX-512 掩码寄存器物理寄存器堆(PRF)的大小,发现大约有 142 个物理掩码寄存器(134 个可用于推测状态,另有 8 个用于体系结构状态)。将掩码寄存器写入与通用或 SIMD 指令混合的测试表明,掩码寄存器堆并不与这些寄存器堆共享,但当混合使用时会出现一个约 212 条在途指令的无法解释的限制。文章还指出,与通用寄存器和 SIMD 寄存器不同,掩码寄存器无法受益于移动消除,并讨论了打破依赖的清零惯用法。

AVX-512 introduced eight so-called mask registers1, k02 through k7, which apply to most ALU operations and allow you to apply a zero-masking or merging3 operation on a per-element basis, speeding up code that would otherwise require extra blending operations in AVX2 and earlier.

If that single sentence doesn’t immediately indoctrinate you into the mask register religion, here’s a copy and paste from Wikipedia that should fill in the gaps and close the deal:

Most AVX-512 instructions may indicate one of 8 opmask registers (k0–k7). For instructions which use a mask register as an opmask, register k0 is special: a hardcoded constant used to indicate unmasked operations. For other operations, such as those that write to an opmask register or perform arithmetic or logical operations, k0 is a functioning, valid register. In most instructions, the opmask is used to control which values are written to the destination. A flag controls the opmask behavior, which can either be “zero”, which zeros everything not selected by the mask, or “merge”, which leaves everything not selected untouched. The merge behavior is identical to the blend instructions.

继续阅读全文

为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。

更多来自 Travis Downs

Your CPU May Have Slowed Down on Wednesday

AI 摘要The author observed that zero-filling memory on Skylake and Ice Lake CPUs became substantially slower starting Wednesday, June 9th, and traced the cause to a new Intel microcode update (delivered via Ubuntu's intel-microcode package) that disabled the hardware zero store optimization to mitigate the CVE-2020-24512 side-channel vulnerability. This serves as a reminder that raw CPU performance can silently change due to microcode updates, so reproducible benchmarks should re-run entire suites even on identical hardware. The author also argues that stripping out optimizations vulnerable to timing side channels is an unsustainable path, and calls for a measured approach to classifying and mitigating such attacks rather than trying to eliminate every possible leak.

Ice Lake AVX-512 Downclocking

AI 摘要This article investigates license-based AVX-512 downclocking on Intel's new Ice Lake and Rocket Lake client chips using the avx-turbo benchmarking tool. It finds that the Ice Lake i5-1035G4 shows only a 100 MHz penalty for 512-bit instructions with one active core and no license-based downclocking in any other scenario, while the Rocket Lake i9-11900K shows none at all even with heavy AVX-512 on all eight cores. Unlike Skylake-SP, these chips no longer distinguish between light and heavy instructions, so AVX-512's frequency penalty is essentially eliminated on client parts.

A Concurrency Cost Hierarchy

AI 摘要The article introduces a taxonomy of six performance levels for concurrent operations, each roughly an order of magnitude slower than the previous, illustrated through benchmarks of safely incrementing a shared integer counter across threads on Intel and Graviton hardware. Starting at level 2 (contended atomics such as mutexes, atomic increments, and CAS), the author shows that contended access to shared cache lines sets a baseline cost of around 125 nanoseconds, while fair locks that trigger system calls on nearly every operation (level 3) are an order of magnitude slower. The article then moves on to level 4, where lock implementations force costly context switches between threads.

AVX-512 Mask Registers, Again

AI 摘要While examining a high-resolution die shot of Intel's Skylake-X CPU, the author tried to visually locate the physical register files for AVX-512 mask registers and legacy x87/MMX registers, and found that a single mystery block appeared to serve both purposes. Software microbenchmarks using the robsize tool confirmed this theory: mixing MMX and mask register instructions hit the same 128-entry resource limit as testing each alone, while mixing with SIMD or scalar instructions showed a much higher limit, proving mask and x87/MMX registers share one physical register file. This sharing saves die area and power with little practical performance impact, since obsolete x87/MMX code is unlikely to be used alongside AVX-512 mask registers.

Ice Lake Store Elimination

AI 摘要This article analyzes zero-store elimination on Intel's Ice Lake architecture, finding that 256-bit stores achieve roughly 96% elimination of redundant zero stores in L3 and memory writebacks—a large improvement over both 512-bit stores (~56%) and Skylake—yielding speedups of up to ~45% in the L3 region. The author also documents a bimodal performance artifact caused by AVX-512 voltage/frequency management, where switching voltage levels temporarily reduces dispatch throughput during benchmarks. Why 256-bit stores outperform 512-bit stores in the L2 and L3 regions remains an unexplained puzzle, though the author suspects the difference in elimination rates largely accounts for it.