← Back to Pull requests

Fix KSHIFTW behavior for a shift count of 15 #844

Closed
unknown closed this pull request without merging on Aug 28, 2026 05:56 UTC
View on GitHub
unknown unknown commented on Aug 28, 2026 04:22 UTC
Author

Problem

The 16-bit KSHIFTLW and KSHIFTRW forms treat an immediate count of
15 as out of range.

The architectural operation shifts the 16-bit source for counts through
15 and clears the destination only when the count is greater than 15.
The Bochs handlers currently perform the shift only when count < 15,
so the maximum valid count incorrectly produces zero.

For example:

source k1:   0x0001
bytes:       c4 e3 f9 32 d1 0f
instruction: kshiftlw k2, k1, 15
expected:    k2 = 0x8000
before fix:  k2 = 0x0000

Similarly:

source k1:   0x8000
bytes:       c4 e3 f9 30 d1 0f
instruction: kshiftrw k2, k1, 15
expected:    k2 = 0x0001
before fix:  k2 = 0x0000

Fix

Use count < 16 for the word-form KSHIFTLW and KSHIFTRW
handlers.

This includes the valid count of 15 while retaining a zero result for
counts greater than 15.

Architectural reference

The Intel® 64 and IA-32 Architectures Software Developer’s Manual,
Volume 2B, sections “KSHIFTLW/KSHIFTLB/KSHIFTLQ/KSHIFTLD—Shift Left
Mask Registers” and
“KSHIFTRW/KSHIFTRB/KSHIFTRQ/KSHIFTLD—Shift Right Mask Registers,”
specifies that the 16-bit forms perform the shift when the count is less
than or equal to 15 and clear the destination otherwise.

  • Intel® 64 and IA-32 Architectures Software Developer’s Manual, Volume 2B

  • Intel® Software Developer Manuals download page
  • Validation

    Bochs was rebuilt successfully:

    make -C bochs -j2
    

    A temporary protected-mode boot probe selected corei7_skylake_x,
    enabled opmask and AVX-512 state in XCR0, and tested counts 14, 15, and
    16 for both instructions.

    Before the fix:

    L14/L15/L16=4000/0000/0000
    R14/R15/R16=0002/0000/0000
    

    After the fix:

    L14/L15/L16=4000/8000/0000
    R14/R15/R16=0002/0001/0000
    

    The neighboring counts remain unchanged: count 14 shifts normally and
    count 16 produces zero.

    Diff: 263 lines (+197 / -66) across 3 files Reviewer: stlintel Review duration: 93m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.39) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 263 lines diff across 3 files
    0.39
    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%
    56%
    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.334
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #844"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 39.3% (MEDIUM) · Higher = larger blast radius
    39.3%
    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: 56.8% · Lower = rushed or shallow review
    56.8%
    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: 17.0% · Safe to merge
    17.0%