| 1 |
// BLOCKALIGN and BLOCKALIGN_LONG place the 128-byte block loop that |
| 2 |
// follows them at byte 18, respectively 27, of a 32-byte code window: |
| 3 |
// PCALIGN pads to the window, then two (or three) nine-byte NOPs — the |
| 4 |
// canonical 66 0F 1F 84 00 00 00 00 00 form — shift the loop head. The |
| 5 |
// NOPs sit before the label, so they run once per call that enters the |
| 6 |
// block loop, never per iteration. |
| 7 |
// |
| 8 |
// The offset matters because of the Intel JCC erratum: on Skylake-derived |
| 9 |
// cores (Skylake, Cascade Lake, Coffee Lake and their siblings) the |
| 10 |
// microcode mitigation refuses to keep a jump — or a macro-fused |
| 11 |
// compare-and-jump pair — in the decoded-uop cache when it crosses a |
| 12 |
// 32-byte boundary or ends exactly on one. A block loop whose TEST/JNZ, |
| 13 |
// DEC/JZ or CMP/JBE lands on such a boundary then runs from the legacy |
| 14 |
// decoder every iteration, which measured ~10% slower on the pair kernel |
| 15 |
// at 4KiB, and whether that happened used to depend on where the linker |
| 16 |
// placed each kernel. Which offsets keep every pair of a loop inside one |
| 17 |
// window depends on the loop's exact byte layout: 18 does for the six |
| 18 |
// loops that use BLOCKALIGN, 27 for the three that use BLOCKALIGN_LONG. |
| 19 |
// block_align_amd64_test.go checks the property against the linked test |
| 20 |
// binary and logs each pair's position relative to its loop head, so a |
| 21 |
// kernel edit that moves a branch onto a boundary fails the test (and |
| 22 |
// the log shows which offset to pick) instead of silently costing |
| 23 |
// throughput. |
| 24 |
#define BLOCKALIGN \ |
| 25 |
PCALIGN $32; \ |
| 26 |
BYTE $0x66; BYTE $0x0F; BYTE $0x1F; BYTE $0x84; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x00; \ |
| 27 |
BYTE $0x66; BYTE $0x0F; BYTE $0x1F; BYTE $0x84; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x00 |
| 28 |
|
| 29 |
#define BLOCKALIGN_LONG \ |
| 30 |
BLOCKALIGN; \ |
| 31 |
BYTE $0x66; BYTE $0x0F; BYTE $0x1F; BYTE $0x84; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x00; BYTE $0x00 |