← Back to Pull requests

Fix full-width VPCOMPRESS byte and word masks #850

Closed
unknown closed this pull request without merging on Aug 29, 2026 04:23 UTC
View on GitHub
unknown unknown commented on Aug 28, 2026 20:36 UTC
Author

Problem

VPCOMPRESSB and VPCOMPRESSW construct a dense write mask after
packing the selected source elements:

Bit64u writemask = (BX_CONST64(1) << k) - 1;
Bit32u writemask = (1 << k) - 1;

For an EVEX.512 instruction with every mask bit set, k reaches 64
for byte elements and 32 for word elements. The resulting C++ shifts
use a shift count equal to the width of the operand, which is undefined
behavior.

On the tested build, both expressions produced a zero write mask. The
shared instruction handlers consequently suppressed the complete
register write or memory store instead of writing all selected
elements.

Fix

Use an all-ones write mask when k reaches the full element count:

  • 0xffffffffffffffff for 64 byte elements

  • 0xffffffff for 32 word elements
  • Retain the existing shift expression for smaller element counts. The
    same handlers implement register and memory destinations, so this
    corrects both forms.

    Architectural reference

    The Intel® 64 and IA-32 Architectures Software Developer’s Manual,
    Volume 2, sections “VPCOMPRESSB/VPCOMPRESSW—Store Sparse Packed
    Byte/Word Integer Values Into Dense Memory/Register,” specify that
    source elements selected by the writemask are copied consecutively
    into the low elements of the destination.

    For an EVEX.512 operation with every writemask bit set, all 64 byte
    elements or all 32 word elements are selected. The instruction must
    therefore write the complete 512-bit result.

  • Intel® Software Developer Manuals download page
  • Validation

    A standalone 64-bit CPL3 guest exercised the instructions on the Bochs
    tigerlake CPU model with AVX-512 state enabled (XCR0=0xe7).

    Each test initialized its destination with a distinguishable sentinel.
    The full-width cases compared all 64 result bytes with the source. The
    boundary controls selected 63 bytes or 31 words and additionally
    verified that the unselected final destination element retained its
    sentinel value.

    | Instruction | Destination | Selected elements | Before | After |
    |---|---|---:|---:|---:|
    | VPCOMPRESSB | register | 64 | FAIL | PASS |
    | VPCOMPRESSB | register | 63 | PASS | PASS |
    | VPCOMPRESSB | memory | 64 | FAIL | PASS |
    | VPCOMPRESSB | memory | 63 | PASS | PASS |
    | VPCOMPRESSW | register | 32 | FAIL | PASS |
    | VPCOMPRESSW | register | 31 | PASS | PASS |
    | VPCOMPRESSW | memory | 32 | FAIL | PASS |
    | VPCOMPRESSW | memory | 31 | PASS | PASS |

    UBSan also identified the two affected expressions as shifts with
    exponents 64 and 32, respectively.

    The patched tree was rebuilt successfully with make -j2.

    Diff: 344 lines (+258 / -86) across 4 files Reviewer: stlintel Review duration: 467m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.42 · 344 lines diff across 4 files
    0.42
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.350
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #850"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 42.4% (MEDIUM) · Higher = larger blast radius
    42.4%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 16.7% · Safe to merge
    16.7%