← Back to Pull requests

Fix upper ZMM clearing for EVEX.512 VGATHERQPS and VPGATHERQD #852

Closed
unknown closed this pull request without merging on Aug 29, 2026 04:50 UTC
View on GitHub
unknown unknown commented on Aug 29, 2026 04:47 UTC
Author

Problem

The shared handler for VGATHERQPS and VPGATHERQD uses the encoded
vector-length value to clear the portion of the architectural destination
above its logical dword result:

if (len == BX_VL128) dest->vmm64u(1) = 0;
else len--;

BX_CLEAR_AVX_REGZ(i->dst(), len);

The vector-length constants are encoded as BX_VL128 = 1,
BX_VL256 = 2, and BX_VL512 = 4. Decrementing the 256-bit value maps
it to BX_VL128, but decrementing the 512-bit value produces 3.
BX_CLEAR_AVX_REGZ recognizes only the 128- and 256-bit constants, so
it performs no clearing for that value.

Consequently, EVEX.512 VGATHERQPS and VPGATHERQD leave destination
bits 511:256 unchanged after successful completion. These instructions
produce eight dword results from eight qword indices, so their logical
result occupies only the low 256 bits of the ZMM destination.

Fix

Shift the vector-length value right by one instead of decrementing it.
This maps each index-vector length to the corresponding dword-result
length:

  • BX_VL256 becomes BX_VL128

  • BX_VL512 becomes BX_VL256
  • The existing special handling for BX_VL128 remains unchanged. The
    shared handler therefore clears the correct upper destination portion
    for both instruction families and all supported vector lengths.

    Architectural reference

    The Intel® 64 and IA-32 Architectures Software Developer's Manual,
    Volume 2, sections “VGATHERQPS—Gather Packed Single Precision
    Floating-Point Values Using Signed Qword Indices” and
    “VPGATHERQD—Gather Packed Dword Values Using Signed Qword Indices,”
    specifies DEST[MAXVL-1:VL/2] := 0 for these forms.

    For an EVEX.512 operation, the eight gathered dwords occupy destination
    bits 255:0 and bits 511:256 must be zero after successful completion.

  • Intel® Software Developer Manuals download page
  • Validation

    A standalone 64-bit CPL3 guest exercised the gather forms on the Bochs
    tigerlake CPU model with AVX-512 state enabled (XCR0=0xe7).
    Destinations were initialized with distinctive nonzero values so that
    retained upper bits were directly observable.

    The zero-mask cases complete without reading memory and isolate the
    architectural merge and upper-clearing behavior. The active-mask
    VPGATHERQD case used ordinary mapped memory, verified the gathered
    dwords and preserved inactive low lanes, and then checked that bits
    511:256 were cleared.

    | Instruction | Vector length | Mask | Before | After |
    |---|---:|---:|---:|---:|
    | VPGATHERQD | 512 | zero | FAIL | PASS |
    | VPGATHERQD | 512 | active (0xa5) | FAIL | PASS |
    | VGATHERQPS | 512 | zero | FAIL | PASS |
    | VPGATHERQD | 256 | zero | PASS | PASS |
    | VPGATHERQD | 128 | zero | PASS | PASS |
    | VPGATHERQQ | 512 | zero | PASS | PASS |

    The 128- and 256-bit VPGATHERQD cases verify the neighboring logical
    result widths. The 512-bit VPGATHERQQ control verifies that a gather
    whose qword results fill the complete ZMM destination remains unchanged.

    The source file used by the patched test build exactly matches the
    committed source. The patched tree builds successfully with make -j2,
    and git diff --check passes.

    Diff: 412 lines (+309 / -103) across 5 files Reviewer: stlintel Review duration: 2m
    All Vouch review confidence checks passed
    Residual risk 0.31 = Change Risk (0.45) × (1 − Review Confidence (0.30)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 412 lines diff across 5 files
    0.45
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 27% · Reviewer familiarity: 35%
    29%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.360
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #852"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 29.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.9% (MEDIUM) · Higher = larger blast radius
    44.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 29.9% · Lower = rushed or shallow review
    29.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 31.5% · Safe to merge
    31.5%