Files
Jake WriterandClaude Opus 5.5 21fdf1c59c Canvas and Opus follow a claimed CPU vendor (Intel/AMD); vendor joins the fingerprint (#1024)
* Canvas: reproduce Intel's or AMD's RCPPS/RSQRTPS, chosen per identity

Skia's raster pipeline uses x86's estimate instructions for the
non-separable and dodge/burn blend modes, perspective and matrix
inversion. Intel and AMD implement them with different tables (the same
across each vendor's generations and OSes), so canvas readback shows the
host's CPU vendor.

- cpu-vendor-estimates.patch: pref gfx.skia.cpu_vendor_estimates
  (0 host, 1 Intel, 2 AMD). When it names the other vendor, rcp_approx
  and rsqrt_approx in the HSW and SSE paths compute that vendor's bits
  from a recorded table (SkCpuEstimates.h, SkCpuEstimateTables.h).
- browser/tests/cpu-estimates: records each vendor's table and checks the
  emulation against the native instruction over all 2^32 inputs, and
  against the other vendor's recorded hashes.
- Launcher (Python and TypeScript): cpu_vendor option and cpu:vendor key.
  The identity derives it from the GPU where only one vendor carries that
  GPU, and otherwise draws it at Firefox's x86 share (81.4% Intel). A
  coherence rule warns when the two disagree. Apple Silicon gets none.
- Guard cpu-vendor-estimates: stock Firefox 159 hashes from an Intel and
  an AMD CPU; the build matches each when told to.

Audio is not affected: its render splits x86-64 from ARM64, not Intel
from AMD.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Opus: encode with the claimed CPU vendor's RCPPS/RSQRTPS; add the CPU probe

libopus's PVQ search (celt/x86/vq_sse2.c) uses the same two estimate
instructions as Skia, so a WebCodecs, MediaRecorder or WebRTC Opus stream
showed the host's vendor: stock Firefox 159 gives one byte stream on Intel
and another on AMD. libopus lives in libgkcodecs, which cannot read prefs,
so Gecko hands it the table gfx.skia.cpu_vendor_estimates selects
(opus_mozilla_set_cpu_estimates) before each encoder is created, and the
SSE2 search computes the estimates from it lane by lane.

The guard now also encodes one second of Opus and checks it against both
vendors' stock streams, on a secure page since WebCodecs needs one. It
passes on an AMD host for both vendors.

browser/tests/cpu-probe/ is the probe that found it: Math, DOMMatrix,
layout, canvas, WebGL, relaxed SIMD, Web Audio and WebCodecs, with stock
Firefox 159 results from Intel and AMD on Linux and Windows and from an
Apple M4 on macOS and Linux. Intel and AMD differ only in the six
estimate-based composite operations and Opus; ARM64 differs in much more,
which docs/HOST-PARITY.md now lists as not emulated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* cpu:vendor: a core count only Intel ships implies Intel

No AMD x86 CPU since 2015 reports 10, 14, 18, 22 or 28 logical cores:
AMD runs one or two threads per core, and its one-thread parts have 2 to 8
cores. Intel's hybrids report all of them (Core Ultra 5 225, 245K, 125H,
155H; i7-14700K). So an identity with such a hardwareConcurrency is drawn
Intel, and a cpu_vendor='amd' beside it is reported and repaired.

The GPU still decides first: a Radeon APU beside an Intel-only count keeps
AMD and is reported, since no vendor matches both. The rule is renamed
cpu-vendor-matches-hardware. The counts live in launcher-constants.json
(intelOnlyCoreCounts) for both launchers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* cpu {arch, manufacturer}: ARM64 emulation on x86 alongside Intel/AMD

The fingerprint's CPU is now { arch: "x86" | "arm", manufacturer } instead
of a bare vendor, validated per OS (launcher-constants cpuManufacturers):
e.g. Apple + x86 or AMD on macOS is rejected, as is a GPU that never sits
beside the claimed CPU. general.cpu_identity = 3 makes an x86 build compute
what Firefox's aarch64 build computes:

- Skia: the NEON raster pipeline and blend kernels, emulated lane for lane
  (SkOpts_neonemu, SkNeonEmu.h, SkArmEstimates.h).
- Opus: the aarch64 CELT kernels and the NEON inverse MDCT (celt_neonemu.c,
  celt_tx_neonemu.c, translated from celt_tx_neon.S by scripts/a64toc.py),
  for decode and encode.
- WebAudio / wasm / NaN payloads follow the ARM rules.
- libvpx: Firefox configures libvpx realtime-only for linux/arm64 and
  win/aarch64 (not mac/arm64), which changes WebCodecs VP9 output and
  rejects quality-mode VP8. The ARM64 configs are now the full encoder and
  realtime-only is a runtime switch (media.libvpx.realtime_only), so either
  build can produce either result. libvpx NEON itself is bit-exact with x86.

The launchers (Python and TypeScript) set general.cpu_identity and, for an
ARM Windows/Linux identity, media.libvpx.realtime_only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ARM64 identity: make the guard's probe reproducible, fail loudly in ffvpx

The guard served only the probe's own files, so the two webfonts 404ed and
the layout step threw. The probe page draws every input from one seeded
stream, so the throw shifted every later key and made wasm relaxed SIMD and
the convolver look wrong. The fonts now ship beside the probe (both freely
licensed, from Firefox's layout reftests), and the guard fails on any probe
step that errors where stock does not.

Canvas text is rasterized at the identity's devicePixelRatio, which the
launcher draws, so the guard leaves it out; at a ratio of 1 it matches the
M4's.

FFVPXRuntimeLinker asserts that libmozavutil exports the ARM64 switch
instead of skipping it silently. cpu:vendor is kept in properties.json as
removed, and the tribal rule, docs and the constants test follow the
general.cpu_identity pref.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 05:59:20 +00:00

213 lines
9.8 KiB
Python

"""cpu:arch and cpu:manufacturer: the CPU whose arithmetic the page sees.
Firefox never reports the CPU, but canvas pixels, Web Audio samples, encoded
Opus, relaxed-SIMD wasm and NaN signs differ between x86-64 and ARM64, and
canvas and Opus between Intel's and AMD's RCPPS/RSQRTPS (browser/tests/
cpu-probe). The CPU is part of the identity: drawn once with it, consistent
with its GPU and OS, and sent to the browser as general.cpu_identity.
"""
import pytest
from camoufox import coherence
from camoufox.fingerprints import X86_INTEL_SHARE, set_cpu_default
from camoufox.pkgman import LAUNCHER_CONSTANTS
from camoufox.utils import _os_for_cpu, cpu_identity_pref, vpx_realtime_only
WIN_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:159.0) Gecko/20100101 Firefox/159.0"
NVIDIA = "ANGLE (NVIDIA, NVIDIA GeForce GTX 980 Direct3D11 vs_5_0 ps_5_0), or similar"
APPLE = "Apple M1, or similar"
def _drawn(renderer, target_os="win", salt=0, cores=8):
config = {"navigator.userAgent": WIN_UA, "navigator.hardwareConcurrency": cores}
if renderer:
config["webGl:renderer"] = renderer
set_cpu_default(config, target_os, salt)
return config.get("cpu:arch"), config.get("cpu:manufacturer")
# --- the caller's option -----------------------------------------------------
@pytest.mark.parametrize(
"cpu,target_os,resolved",
[
({"arch": "x86", "manufacturer": "intel"}, "mac", ("x86", "intel")),
({"arch": "arm", "manufacturer": "apple"}, "mac", ("arm", "apple")),
({"manufacturer": "apple"}, "mac", ("arm", "apple")),
({"manufacturer": "amd"}, "win", ("x86", "amd")),
({"arch": "arm", "manufacturer": "qualcomm"}, "win", ("arm", "qualcomm")),
({"manufacturer": "broadcom"}, "lin", ("arm", "broadcom")),
({"manufacturer": "apple"}, "lin", ("arm", "apple")),
({"arch": "x86"}, "lin", ("x86", None)),
],
)
def test_real_machines_resolve(cpu, target_os, resolved):
got = coherence.resolve_cpu(cpu, target_os)
assert (got.get("cpu:arch"), got.get("cpu:manufacturer")) == resolved
@pytest.mark.parametrize(
"cpu,target_os",
[
({"arch": "x86", "manufacturer": "amd"}, "mac"), # every x86 Mac is Intel
({"arch": "x86", "manufacturer": "apple"}, "mac"), # Apple makes no x86 CPU
({"arch": "x86", "manufacturer": "apple"}, "lin"),
({"arch": "arm", "manufacturer": "intel"}, "win"),
({"arch": "arm", "manufacturer": "amd"}, "lin"),
({"arch": "arm", "manufacturer": "broadcom"}, "win"), # Windows on ARM is Snapdragon
({"arch": "arm", "manufacturer": "qualcomm"}, "mac"),
({"manufacturer": "qualcomm"}, "mac"),
({"manufacturer": "cyrix"}, "win"),
({"arch": "riscv"}, "lin"),
({"arch": "x86", "vendor": "intel"}, "win"),
("arm", "win"),
],
)
def test_impossible_machines_are_rejected(cpu, target_os):
with pytest.raises(ValueError):
coherence.resolve_cpu(cpu, target_os)
def test_an_os_left_open_is_drawn_among_those_with_a_gpu_for_the_cpu():
# fpgen records Apple GPUs only on macOS and no ARM GPU on Windows, so an
# ARM identity is a Mac or a Linux machine rendering in software.
assert _os_for_cpu({"arch": "arm"}, None) == ["macos", "linux"]
assert _os_for_cpu({"manufacturer": "amd"}, None) == ["windows", "linux"]
assert _os_for_cpu({"arch": "x86"}, ["macos", "linux"]) == ["macos", "linux"]
with pytest.raises(ValueError):
_os_for_cpu({"manufacturer": "amd"}, "macos")
assert _os_for_cpu({"manufacturer": "qualcomm"}, None) == "linux"
@pytest.mark.parametrize(
"renderer,target_os,arch,maker,fits",
[
(APPLE, "mac", "arm", "apple", True),
(APPLE, "mac", "x86", "intel", False),
("Radeon R9 200 Series, or similar", "mac", "arm", None, False),
("Radeon R9 200 Series, or similar", "mac", "x86", "intel", True),
("Intel(R) HD Graphics, or similar", "lin", "x86", "amd", False),
("Radeon HD 3200 Graphics, or similar", "lin", "x86", "intel", False),
(NVIDIA, "win", "x86", "amd", True),
(NVIDIA, "win", "arm", "qualcomm", False), # no Snapdragon laptop has a GeForce
("ANGLE (Qualcomm, Adreno X1-85 GPU Direct3D11 vs_5_0 ps_5_0), or similar", "win", "arm", "qualcomm", True),
("V3D 4.2", "lin", "arm", "broadcom", True),
("V3D 4.2", "lin", "arm", "qualcomm", False),
("llvmpipe, or similar", "lin", "arm", "ampere", True), # software rendering runs on any CPU
("llvmpipe, or similar", "lin", "x86", "amd", True),
],
)
def test_the_gpu_must_fit_the_cpu(renderer, target_os, arch, maker, fits):
assert coherence.gpu_fits_cpu(renderer, target_os, arch, maker) is fits
# --- the default ---------------------------------------------------------------
def test_a_discrete_gpu_draws_firefoxs_x86_split():
draws = [_drawn(NVIDIA, salt=salt) for salt in range(4000)]
share = draws.count(("x86", "intel")) / len(draws)
assert set(draws) == {("x86", "intel"), ("x86", "amd")}
assert abs(share - X86_INTEL_SHARE) < 0.03
def test_the_draw_is_a_pure_function_of_the_identity():
assert [_drawn(NVIDIA, salt=s) for s in range(50)] == [_drawn(NVIDIA, salt=s) for s in range(50)]
@pytest.mark.parametrize(
"renderer,target_os,cpu",
[
("ANGLE (Intel, Intel(R) HD Graphics Direct3D11 vs_5_0 ps_5_0), or similar", "win", ("x86", "intel")),
("ANGLE (Intel, Intel(R) HD Graphics 400 Direct3D11 vs_5_0 ps_5_0), or similar", "win", ("x86", "intel")),
("Intel(R) HD Graphics, or similar", "lin", ("x86", "intel")),
("ANGLE (AMD, Radeon HD 3200 Graphics Direct3D11 vs_5_0 ps_5_0), or similar", "win", ("x86", "amd")),
("Radeon HD 3200 Graphics, or similar", "lin", ("x86", "amd")),
# every x86 Mac has an Intel CPU, whatever its GPU
("Radeon R9 200 Series, or similar", "mac", ("x86", "intel")),
("Intel(R) HD Graphics 400, or similar", "mac", ("x86", "intel")),
(APPLE, "mac", ("arm", "apple")),
("V3D 4.2", "lin", ("arm", "broadcom")),
("Mali-G610", "lin", ("arm", None)), # several SoC makers ship Mali
],
)
def test_the_gpu_decides_the_cpu(renderer, target_os, cpu):
assert {_drawn(renderer, target_os, salt) for salt in range(200)} == {cpu}
@pytest.mark.parametrize("cores", [10, 14, 18, 22, 28])
def test_a_core_count_only_intel_ships_decides_the_x86_vendor(cores):
assert {_drawn(NVIDIA, salt=salt, cores=cores) for salt in range(200)} == {("x86", "intel")}
def test_an_intel_only_core_count_says_nothing_about_arm():
# An M4 Pro reports 14.
assert _drawn(APPLE, "mac", cores=14) == ("arm", "apple")
config = {"cpu:arch": "arm", "cpu:manufacturer": "apple", "webGl:renderer": APPLE,
"navigator.hardwareConcurrency": 14}
assert coherence.cpu_conflict(config, "mac") is None
def test_a_core_count_both_vendors_ship_leaves_the_draw_open():
assert {_drawn(NVIDIA, salt=salt, cores=16) for salt in range(200)} == {("x86", "intel"), ("x86", "amd")}
def test_a_callers_cpu_is_kept():
config = {"cpu:arch": "x86", "cpu:manufacturer": "amd", "webGl:renderer": NVIDIA}
set_cpu_default(config, "win")
assert (config["cpu:arch"], config["cpu:manufacturer"]) == ("x86", "amd")
# --- coherence -------------------------------------------------------------------
def test_coherence_repairs_a_cpu_the_gpu_contradicts():
config = {"cpu:arch": "x86", "cpu:manufacturer": "amd", "webGl:renderer": "Intel(R) HD Graphics, or similar"}
coherence.apply(config, "lin")
assert (config["cpu:arch"], config["cpu:manufacturer"]) == ("x86", "intel")
config = {"cpu:arch": "x86", "cpu:manufacturer": "intel", "webGl:renderer": APPLE}
coherence.apply(config, "mac")
assert (config["cpu:arch"], config["cpu:manufacturer"]) == ("arm", "apple")
def test_coherence_keeps_and_reports_a_callers_cpu():
config = {"cpu:arch": "x86", "cpu:manufacturer": "amd", "webGl:renderer": "Intel(R) HD Graphics, or similar"}
left = coherence.apply(config, "lin", keep=frozenset({"cpu:arch", "cpu:manufacturer"}))
assert config["cpu:manufacturer"] == "amd"
assert [v.rule for v in left] == ["cpu-matches-hardware"]
def test_coherence_repairs_an_x86_vendor_its_core_count_contradicts():
config = {"cpu:arch": "x86", "cpu:manufacturer": "amd", "webGl:renderer": NVIDIA,
"navigator.hardwareConcurrency": 22}
assert [v.rule for v in coherence.validate(config, "win")] == ["cpu-matches-hardware"]
coherence.apply(config, "win")
assert config["cpu:manufacturer"] == "intel"
def test_the_gpu_decides_before_the_core_count():
amd_apu = "Radeon HD 3200 Graphics, or similar"
assert _drawn(amd_apu, "lin", cores=14) == ("x86", "amd")
# --- the pref ----------------------------------------------------------------------
def test_the_pref_values_are_the_patchs():
# CPU_IDENTITY_* in cpu-identity.patch (mozilla/CpuIdentity.h)
assert LAUNCHER_CONSTANTS["cpuIdentityPref"] == {"x86/intel": 1, "x86/amd": 2, "arm": 3}
assert cpu_identity_pref({"cpu:arch": "x86", "cpu:manufacturer": "intel"}) == 1
assert cpu_identity_pref({"cpu:arch": "x86", "cpu:manufacturer": "amd"}) == 2
assert cpu_identity_pref({"cpu:arch": "arm", "cpu:manufacturer": "apple"}) == 3
assert cpu_identity_pref({"cpu:arch": "arm"}) == 3
assert cpu_identity_pref({}) == 0
def test_vpx_is_realtime_only_on_arm_windows_and_linux():
# Mozilla configures libvpx --enable-realtime-only for win/aarch64 and
# linux/arm64, not mac/arm64 (media/libvpx/generate_sources_mozbuild.sh)
arm = {"cpu:arch": "arm", "cpu:manufacturer": "qualcomm"}
assert vpx_realtime_only(arm, "win") and vpx_realtime_only(arm, "lin")
assert not vpx_realtime_only({"cpu:arch": "arm", "cpu:manufacturer": "apple"}, "mac")
for os_ in ("win", "lin", "mac"):
assert not vpx_realtime_only({"cpu:arch": "x86", "cpu:manufacturer": "amd"}, os_)
assert not vpx_realtime_only({}, "lin")