← Back to Pull requests

Fix POPCNT instruction feature gate #842

Closed
unknown closed this pull request without merging on Aug 28, 2026 06:03 UTC
View on GitHub
unknown unknown commented on Aug 28, 2026 03:46 UTC
Author

Problem

POPCNT availability is enumerated independently through
CPUID.01H:ECX.POPCNT[23].

The three POPCNT opcode declarations currently use BX_ISA_SSE4_2 as
their feature guard. As a result, decoder initialization disables POPCNT
when SSE4.2 is absent, even if the selected CPU model advertises POPCNT.

The built-in AMD Phenom X3 8650 Toliman model demonstrates this feature
combination: it enables BX_ISA_POPCNT, does not enable
BX_ISA_SSE4_2, and reports CPUID.01H:ECX.POPCNT=1. Before this fix,
executing POPCNT with that model dispatches BxError and raises #UD.

For example:

CPU model:    phenom_8650_toliman
CPUID.1:ECX:  0x00802009
POPCNT:       1
SSE4.2:       0
bytes:        f3 0f b8 c0
instruction:  popcnt eax, eax
expected:     executes
before fix:   #UD

The inverse configuration can also incorrectly make POPCNT
decode-reachable when SSE4.2 is enabled but POPCNT is not advertised.

Fix

Use BX_ISA_POPCNT as the feature guard for the 16-, 32-, and 64-bit
POPCNT opcode declarations.

This makes instruction decoding agree with the independently enumerated
POPCNT CPUID feature.

Architectural reference

The Intel® 64 and IA-32 Architectures Software Developer’s Manual,
Volume 2B, section “POPCNT—Return the Count of Number of Bits Set to 1,”
specifies that software must check CPUID.01H:ECX.POPCNT[23]. If that bit
is clear, POPCNT raises #UD.

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

  • Intel® Software Developer Manuals download page
  • Validation

    Bochs was rebuilt successfully after rebuilding the affected decoder
    object:

    make -C bochs/cpu -B decoder/fetchdecode32.o
    make -C bochs -j2
    

    A temporary real-mode boot probe selected phenom_8650_toliman,
    confirmed CPUID.01H:ECX.POPCNT=1 and SSE4.2=0, and executed 16-bit
    POPCNT on 0xffff:

    POPCNT=1 SSE4.2=0 POPCNT_AX=16 PASS
    

    Diff: 264 lines (+198 / -66) across 3 files Reviewer: stlintel Review duration: 136m
    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 · 264 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 #842"
    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% · Safe to merge
    17%