Run the game on x86-64-v2 CPUs without AVX2

-march=x86-64-v3 kept the port and the installer to CPUs with AVX2 and FMA. --cpu v2 compiles the generated code and the runtime for SSE4.2 instead. Without FMA3 the FP lowering calls fma/fmaf, so runtime/fma.c provides correctly rounded ones (musl, MIT) that honour MXCSR's rounding mode, FTZ and DAZ; the UCRT's software fallback rounds incorrectly by up to half an ulp. simd.h's fast paths keep their assumptions.

The installer's host check asks for x86-64-v2 and selects libtotkrt.a or libtotkrt-v2.a; both release scripts build and ship the pair. The differential tests compile fma.c as well, so a --cflags=-march=x86-64-v2 run tests it.

Tested on an i7-3770K (no AVX2, FMA or BMI) with an RTX 3060 Ti, game 1.4.3: the installer ran end to end, --selftest passed and play holds 40-60 fps at 1080p. fma and fmaf matched 152,288 exact vectors over two seeds, including ties, subnormals and every rounding mode, FTZ and DAZ combination. The v3 build is unchanged: fma.c is an empty translation unit there.
This commit is contained in:
CHEN Feng committed 2026-11-01 07:09:13 +08:00
1 parent 7d62cbfa85
commit 34b4faee7c
19 files changed
+402 -58

No files matched your search

+2 -1
View File
@@ -213,7 +213,8 @@ def build_harness(work, bodies, jobs, cflags):
f.write(''.join(f'void t{k}(Cpu *c);\n' for k in range(len(bodies))))
f.write('GuestFn tests[] = {' + ','.join(f't{k}' for k in range(len(bodies))) + '};\n')
f.write(f'int ntests = {len(bodies)};\n')
srcs += [work / 'table.c', ROOT / 'tests' / 'diff' / 'harness.c']
# fma.c: a --cflags=-march=x86-64-v2 run must exercise the software fma the v2 build links, not the C runtime's.
srcs += [work / 'table.c', ROOT / 'tests' / 'diff' / 'harness.c', ROOT / 'runtime' / 'fma.c']
objs, procs = [], []
for s in srcs:
o = work / (s.stem + '.o')
+2 -1
View File
@@ -204,7 +204,8 @@ def build(work, emitted, jobs, cflags):
f'int ntests = {len(emitted)};\n' + 'void rt_stub_call(Cpu *c, uint64_t target);\n' +
''.join(f'void {gen.fname(t)}(Cpu *c) {{ rt_stub_call(c, {hex(t)}ull); }}\n'
for t in sorted(called)))
srcs += [table, ROOT / 'tests' / 'diff' / 'harness.c']
# fma.c: a --cflags=-march=x86-64-v2 run must exercise the software fma the v2 build links, not the C runtime's.
srcs += [table, ROOT / 'tests' / 'diff' / 'harness.c', ROOT / 'runtime' / 'fma.c']
objs, procs = [], []
for s in srcs:
o = work / (s.stem + '.o')