Skip to content

Performance Research Checks

github-actions[bot] edited this page Sep 15, 2026 · 1 revision

Performance research — reproducible checks

Reproducible research checks

Unproven performance research · Performance research — common test protocol

These are small mathematical models and standalone source-equivalent C reductions from the September 15, 2026 review. They do not include or link a production xemu build, drive a game, prove title reachability, or measure emulator performance. Source logic was inspected at 322986f4c5502b3fa887a9605ac8cd88e9b2c579.

The retained archive's SHA-256 manifest was verified, both programs were rerun, and new outputs matched the original results while preparing these wiki notes. The C outputs also match between -O0 and -O2 with contraction disabled.

Recorded results and limits

Check Recorded result Scope
HRTF address/predecessor/walk 97,309 tuples; zero mismatches Integer indexing over stated valid positions, delays and taps
HRTF target update Two stale-right-target counterexamples; sum-2 control matches Standalone normalization logic, not full-emulator title reachability
Attenuation table All 65,536 uint16 inputs match float bits; 16,384-byte table Same calculation/environment; not a universal cross-libm result
DSP N/M restore Current-state non-identity examples reproduced Reduced conversion; not proof that a retail title reaches the values
Mixer regrouping Different intermediate floats and final PCM 1 versus 0 Constructed nearest-even numerical counterexample
Silent stateful effect Nonzero output tail Generic counterexample to silence-only skipping
Periodic deadline 266,240 cases; zero mismatches Positive periods and mathematical integers, not PTIMER IRQ/wrap/zero-ratio behavior
Staging removal Staged and overlapping forward copies differ Generic aliasing hazard, not proof current MCPX buffers alias

Reproduce

Copy the complete Python and C listings below into the two indicated files. Keep the C copyright/license header. Python requires only its standard library; the C reduction assumes binary32 float and a C11 compiler. Do not disable assertions, use python -O, or enable fast-math. The examples assume the default nearest-even rounding environment.

python3 research_checks.py --output model-results.json
cc -std=c11 -Wall -Wextra -Werror -O0 -ffp-contract=off source_reproductions.c -lm -o source-repro-O0
./source-repro-O0 > source-repro-O0.txt
cc -std=c11 -Wall -Wextra -Werror -O2 -ffp-contract=off source_reproductions.c -lm -o source-repro-O2
./source-repro-O2 > source-repro-O2.txt
cmp source-repro-O0.txt source-repro-O2.txt

The model contains eight groups, including deliberately reproduced counterexamples and calculated opportunity scenarios. A successful run must contain those counterexamples; they are not failed test executions. No timing speedup is measured by either program.

Rerun environment: cc (Debian 14.2.0-19) 14.2.0; Python 3.13.5.

C output

HRTF left_gain=0 original_right_tap1=0.00 reference_right_tap1=-1.00 COUNTEREXAMPLE_REPRODUCED
HRTF left_gain=1 original_right_tap1=0.00 reference_right_tap1=-1.00 COUNTEREXAMPLE_REPRODUCED
HRTF left_gain=2 original_right_tap1=-1.00 reference_right_tap1=-1.00 POSITIVE_CONTROL_MATCH
DSP_N before=0x007fff after=0x007fff
DSP_N before=0x008000 after=0xff8000
DSP_N before=0x128001 after=0xff8001
DSP_N before=0xff8000 after=0xff8000
DSP_M before=0x00ffff after=0xffffff COUNTEREXAMPLE_REPRODUCED
ATTENUATION_LUT inputs=65536 mismatches=0 bytes=16384 SAME_ENVIRONMENT_BITWISE_MATCH

research_checks.py

SHA-256: 74c8a7e20ac8fd4a6339693b252cd017c3e96c500fe28b192fd3d7706e3b3853.

#!/usr/bin/env python3
"""Source-informed mathematical checks. No xemu build or game benchmark is run.

Usage: python3 research_checks.py --output model-results.json
Only the Python standard library is required. Source-equivalent C reductions
are supplied separately in source_reproductions.c.
"""
from __future__ import annotations
import argparse
import json
import struct
from pathlib import Path

SOURCE_COMMIT = "322986f4c5502b3fa887a9605ac8cd88e9b2c579"

def f32(x: float) -> float:
    return struct.unpack("<f", struct.pack("<f", x))[0]

def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--output", type=Path, default=Path("model-results.json"))
    args = parser.parse_args()
    checks: list[dict[str, object]] = []

    # 73 ring positions * 43 possible integer delays * 31 taps.
    cases = 0
    for pos in range(73):
        for delay in range(43):
            walk = pos - delay
            if walk < 0:
                walk += 73
            for tap in range(31):
                old = (pos - delay - tap + 73) % 73
                t = pos - delay - tap
                new = t + 73 if t < 0 else t
                old_prev = (old - 1 + 73) % 73
                new_prev = 72 if new == 0 else new - 1
                assert old == new == walk
                assert old_prev == new_prev
                walk = 72 if walk == 0 else walk - 1
                cases += 1
    checks.append({"name": "HRTF ring index and predecessor equivalence",
                   "result": "PASS", "tuples": cases, "mismatches": 0,
                   "scope": "Integer addressing only; not audio output or runtime speed."})

    # A counterexample entirely within ordinary normalized audio amplitudes.
    a, b, c = f32(1.0), f32(-1.0), f32(2.0 ** -25)
    left = f32(f32(a + b) + c)
    right = f32(a + f32(b + c))
    assert left != right
    # This second case crosses a signed-24-bit nearest-even rounding boundary.
    # It stays far from saturation, so round(x * 2**23) models the relevant
    # finite, non-saturating part of float_to_24b with FE_TONEAREST.
    quant_c = f32(2.0 ** -24 + 2.0 ** -40)
    quant_left = f32(f32(a + b) + quant_c)
    quant_right = f32(a + f32(b + quant_c))
    left_pcm = round(quant_left * (2 ** 23))
    right_pcm = round(quant_right * (2 ** 23))
    assert left_pcm == 1 and right_pcm == 0
    checks.append({"name": "Binary32 regrouping and PCM quantization counterexamples",
                   "result": "COUNTEREXAMPLE_REPRODUCED", "inputs": [a, b, c],
                   "left_associated": left, "right_associated": right,
                   "quantization_example": {
                       "inputs": [a, b, quant_c],
                       "left_associated": quant_left,
                       "right_associated": quant_right,
                       "left_signed_24_bit_pcm": left_pcm,
                       "right_signed_24_bit_pcm": right_pcm,
                       "rounding": "nearest, ties to even"},
                   "scope": "Regrouping can change a final PCM word; not a captured xemu audio event."})

    # Source-model of the legacy N/M widening performed during JIT restore.
    before_n = 0x008000
    after_n = before_n | 0xff0000 if before_n & 0x8000 else before_n
    before_m, after_m = 0x00ffff, 0xffffff
    assert after_n != before_n and after_m != before_m
    checks.append({"name": "JIT state legacy conversion is not a general identity",
                   "result": "COUNTEREXAMPLE_REPRODUCED",
                   "N_before": hex(before_n), "N_after": hex(after_n),
                   "M_before": hex(before_m), "M_after": hex(after_m),
                   "scope": "Source-level state transform; no claim that a particular game reaches these values."})

    # Any stateful effect can emit after the input has become zero.
    state = 1.0
    tail = []
    for _ in range(8):
        state = f32(0.5 * state)
        tail.append(state)
    assert any(x != 0 for x in tail)
    checks.append({"name": "Zero-input does not imply zero-output or quiescence",
                   "result": "COUNTEREXAMPLE_REPRODUCED", "tail": tail,
                   "scope": "Generic stateful-filter counterexample, not an Xbox DSP implementation."})

    # The closed-form epoch rule preserves the next strictly future deadline.
    epoch_cases = 0
    for period in range(1, 65):
        for deadline in range(0, 64):
            for lag in range(0, 257, 4):
                now = deadline + lag
                closed = deadline + ((now - deadline) // period + 1) * period
                scalar = deadline
                while scalar <= now:
                    scalar += period
                assert closed == scalar and closed > now
                epoch_cases += 1
    checks.append({"name": "Overdue periodic deadline arithmetic",
                   "result": "PASS", "cases": epoch_cases,
                   "scope": "Positive periods, mathematical integers; not PTIMER IRQ semantics, wraparound, or zero-ratio handling."})

    # A mapped/staged copy can differ from an overlapping forward stream.
    original = [0, 1, 2, 3]
    staged = original.copy()
    staged[1:4] = original[0:3]
    streamed = original.copy()
    for i in range(3):
        streamed[1+i] = streamed[i]
    assert staged != streamed
    checks.append({"name": "Removing staging requires an aliasing proof",
                   "result": "COUNTEREXAMPLE_REPRODUCED",
                   "staged": staged, "forward_stream": streamed,
                   "scope": "Generic overlapping-buffer counterexample; not proof that MCPX buffers actually alias."})

    # Call-count and Amdahl scenarios are explicitly models, not measurements.
    scalar_calls = 32 * 32 * (48000 // 32)
    bulk_calls = 48000 // 32
    checks.append({"name": "VP-to-DSP nominal work model", "result": "CALCULATED",
                   "scalar_writes_per_second": scalar_calls,
                   "bulk_calls_per_second": bulk_calls,
                   "removed_dispatches_per_second": scalar_calls - bulk_calls,
                   "word_payload_bytes_per_second": scalar_calls * 4,
                   "savings_ms_per_second_at_assumed_50ns": (scalar_calls-bulk_calls)*50e-6,
                   "scope": "48 kHz, 32-sample frames, one 1024-word bulk call; dispatch latency is an assumption."})
    checks.append({"name": "Whole-path speedup scenarios", "result": "CALCULATED",
                   "half_of_10_percent_path_speedup": 1.0/(0.9+0.1/2),
                   "half_of_34_percent_path_speedup": 1.0/(0.66+0.34/2),
                   "scope": "Serial critical-path scenarios, not xemu FPS predictions."})

    result = {"source_commit": SOURCE_COMMIT,
              "classification": "SOURCE_INFORMED_MODELS_NOT_XEMU_BENCHMARKS",
              "checks": checks, "check_groups": len(checks)}
    args.output.parent.mkdir(parents=True, exist_ok=True)
    args.output.write_text(json.dumps(result, indent=2) + "\n", encoding="utf-8")
    print(json.dumps(result, indent=2))

if __name__ == "__main__":
    main()

source_reproductions.c

SHA-256: e8f5d334257286893fc3d6c8d9a4b541c1b0771bd14188d148de11da8025e46f.

/*
 * Standalone, source-equivalent reductions for the xemu research review.
 * These are NOT full-xemu tests or a proposed production patch.
 * Relevant source logic inspected at Mainkill1/xemu commit
 * 322986f4c5502b3fa887a9605ac8cd88e9b2c579:
 *   hw/xbox/mcpx/apu/vp/hrtf.h: hrtf_filter_set_target_params
 *   hw/xbox/mcpx/apu/dsp/dsp_jit.c: dsp_jit_sync_from_vm
 *   hw/xbox/mcpx/apu/vp/vp.c: attenuate and its per-bin call site
 *
 * HRTF normalization logic derives from code copyright (c) 2025 Matt Borgerson,
 * LGPL-2.1-or-later. DSP state conversion derives from code copyright (c) 2026
 * Matt Borgerson, GPL-2.0-or-later. This combined reproducer is GPL-2.0-or-later.
 * Provided without warranty. It tests reduced logic, not title reachability.
 */
#include <assert.h>
#include <inttypes.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>

#define TAPS 31

static void normalize_original(float dst[2][TAPS], float src[2][TAPS])
{
    for (int ch = 0; ch < 2; ++ch) {
        memcpy(dst[ch], src[ch], sizeof(dst[ch]));
        float s = 0.0f;
        for (int k = 0; k < TAPS; ++k) s += fabsf(dst[ch][k]);
        if (s == 0.0f || s == 1.0f) break;
        for (int k = 0; k < TAPS; ++k) dst[ch][k] /= s;
    }
}

/* Comparison model: independently update both supplied channel targets. */
static void normalize_reference(float dst[2][TAPS], float src[2][TAPS])
{
    for (int ch = 0; ch < 2; ++ch) {
        memcpy(dst[ch], src[ch], sizeof(dst[ch]));
        float s = 0.0f;
        for (int k = 0; k < TAPS; ++k) s += fabsf(dst[ch][k]);
        if (s == 0.0f || s == 1.0f) continue;
        for (int k = 0; k < TAPS; ++k) dst[ch][k] /= s;
    }
}

/* Same calculation and mute sentinel as the inspected attenuate(). */
static float attenuation_source(uint16_t vol)
{
    vol &= 0xfff;
    return vol == 0xfff ? 0.0f : powf(10.0f, vol / (64.0 * -20.0f));
}

int main(void)
{
    for (int left_gain = 0; left_gain <= 2; ++left_gain) {
        float src[2][TAPS] = {{0}}, old[2][TAPS] = {{0}}, ref[2][TAPS] = {{0}};
        /* All coefficients can be encoded by the source int8 / 128 path. */
        for (int k = 0; k < left_gain * 2; ++k) src[0][k] = 0.5f;
        src[1][1] = -1.0f;
        old[1][0] = ref[1][0] = 0.25f;
        normalize_original(old, src);
        normalize_reference(ref, src);
        assert(ref[1][0] == 0.0f && ref[1][1] == -1.0f);
        if (left_gain < 2) {
            assert(old[1][0] == 0.25f && old[1][1] == 0.0f);
        } else {
            assert(memcmp(old, ref, sizeof(old)) == 0);
        }
        printf("HRTF left_gain=%d original_right_tap1=%.2f reference_right_tap1=%.2f %s\n",
               left_gain, old[1][1], ref[1][1],
               left_gain < 2 ? "COUNTEREXAMPLE_REPRODUCED" : "POSITIVE_CONTROL_MATCH");
    }

    const uint32_t n_inputs[] = {0x007fff, 0x008000, 0x128001, 0xff8000};
    for (unsigned i = 0; i < sizeof(n_inputs)/sizeof(n_inputs[0]); ++i) {
        uint32_t n = n_inputs[i];
        if (n & 0x8000) n |= 0xff0000;
        printf("DSP_N before=0x%06" PRIx32 " after=0x%06" PRIx32 "\n", n_inputs[i], n);
        if (n_inputs[i] == 0x008000) assert(n == 0xff8000 && n != n_inputs[i]);
        if (n_inputs[i] == 0x128001) assert(n == 0xff8001 && n != n_inputs[i]);
    }
    uint32_t m = 0x00ffff;
    if (m == 0x00ffff) m = 0xffffff;
    assert(m != 0x00ffff);
    printf("DSP_M before=0x00ffff after=0x%06" PRIx32 " COUNTEREXAMPLE_REPRODUCED\n", m);
    float attenuation_table[4096];
    for (unsigned i = 0; i < 4096; ++i)
        attenuation_table[i] = attenuation_source((uint16_t)i);
    unsigned compared = 0;
    for (unsigned i = 0; i < 65536; ++i) {
        float old_value = attenuation_source((uint16_t)i);
        float table_value = attenuation_table[i & 0xfff];
        assert(memcmp(&old_value, &table_value, sizeof(float)) == 0);
        ++compared;
    }
    assert(attenuation_table[4095] == 0.0f);
    printf("ATTENUATION_LUT inputs=%u mismatches=0 bytes=%zu SAME_ENVIRONMENT_BITWISE_MATCH\n",
           compared, sizeof(attenuation_table));
    return 0;
}

Keeping future results honest

Passing these reductions supports the bounded arguments above. Qualification of a production patch must call the actual changed code and use the topic-specific oracles. Record current source/build identities separately; never label these checks a full xemu or XISO pass.

Clone this wiki locally