Skip to content

Translate cpu detection from assembly to C++ - #74

Merged
ZivDero merged 3 commits into
OpenTS-Developers:mainfrom
tinix0:translate-cpu-detection-to-cpp
Aug 30, 2026
Merged

Translate cpu detection from assembly to C++#74
ZivDero merged 3 commits into
OpenTS-Developers:mainfrom
tinix0:translate-cpu-detection-to-cpp

Conversation

@tinix0

@tinix0 tinix0 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Translates detproc.asm, the last hand-written x86 assembly CPU-detection
routine, to C++, folding it directly into getcpu.cpp alongside the rest of
Get_CPU_Type. While doing so, this simplifies MMX and CMOV detection to
assume both are always present rather than probing CPUID feature bits, since
the project's supported minimum hardware (SSE2, so a Pentium 4 or Athlon 64
onward) always carries them. Detect_CMOV_Availability and Processor are
removed outright, as neither had a remaining caller once that assumption held.
Get_CPU_Clock (previously #if 0'd out in mpu.cpp) is enabled using the
__rdtsc() intrinsic in place of the inline _emit opcode bytes it used
before.

A new tests/cpudetect CTest target builds the ported detection standalone
and checks its reported family, vendor, and feature flags against CPUID read
directly. No gameplay-visible change on any machine
meeting the documented minimum hardware.

Behavior and compatibility

  • Preserved: the CPUID-derived processor family and vendor string
    (Get_CPU_Type's cpu_type/vendor output, the CPUType/VendorID
    globals) — the family is still read from CPUID leaf 1 exactly as the
    assembly did.
  • Intentional behavior change (breaking): UseMMX, UseCMOV, and
    HasCMOV are now fixed-true constants instead of being written by CPUID
    feature-bit checks, and Detect_CMOV_Availability/Processor are removed.
    These globals still gate the MMX/CMOV instruction paths in winasm.asm's
    palette-fade routines, so a machine below the documented minimum hardware
    (SSE2, so a Pentium 4 or Athlon 64 onward) would now execute an instruction
    it lacks instead of falling back to the plain path — such hardware was
    never in the supported build matrix, so this formalizes an existing
    requirement rather than narrowing one.
  • Not a compatibility boundary: no changes to save/replay/network
    formats, INI/data formats, or COM/ABI surfaces — this is process-internal
    engine plumbing.
  • Version and migration: targets release 0.2.0 (current development
    release). Migration steps are recorded in
    manual/changes/cpu-feature-detection.md: drop any code calling
    Detect_CMOV_Availability or Processor, and treat UseMMX/UseCMOV/
    HasCMOV as fixed-true constants rather than runtime-detected flags.

Validation

  • Manual build smoke tested on GDI 1
  • CTest ensures all the fields are set when calling the ported methods

Documentation

  • Added manual/changes/cpu-feature-detection.md (breaking: true, release
    0.2.0) documenting the MMX/CMOV assumption, the removed functions, and the
    migration steps.
  • Updated inline comments in getcpu.h, getcpu.cpp, mpu.h, mpu.cpp,
    init.cpp, and misc.h to state the modern-hardware assumption and remove
    stale references to the now-removed Detect_CMOV_Availability, Processor,
    and the deleted DETPROC.ASM.

Checklist

  • The change is focused; unrelated mechanical cleanup is separate
  • Compatibility effects and any migration are explicit
  • A player- or modder-visible engine change carries its change record
  • Validation distinguishes what passed, failed, and was not run
  • No prohibited assets, binaries, SDKs, credentials, or generated output are included

tinix0 added 2 commits August 29, 2026 20:03
No documentation update: tests/cpudetect checks the ported detection against values derived directly from CPUID, so the documented CPU-detection behavior is unchanged.
@ZivDero ZivDero added the no change record Engine change needs no manual change record label Aug 29, 2026
Comment thread code/init.cpp
Comment thread code/getcpu.cpp Outdated
Comment thread code/getcpu.cpp Outdated
@tinix0
tinix0 requested a review from ZivDero August 30, 2026 06:51
@github-actions

Copy link
Copy Markdown

Development builds of 96ae888:

The links work without a GitHub account. Artifacts expire after 90 days, and this comment follows the latest successful build.

@ZivDero
ZivDero merged commit 2c44f20 into OpenTS-Developers:main Aug 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no change record Engine change needs no manual change record

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants