mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-27 19:48:49 -04:00
Triforce v0.8.4
Smoother frames and less memory: a compact pipeline cache on NVIDIA, the renderer and game-code profiles, native float in the hot game code, late GPU work left as before. A PC whose NVIDIA shader cache drops the game's gets a driver cache folder of its own. Fixes from the 0.8.3 reports: RenoDX's encoder and tone mapping matched on NVIDIA again; the out-of-memory notice at the next start; no microphone open without a recording device; Evil HD undergrowth kept to 80/120 m; the FG HUD layer keeps what it learned; a stick past 92% is a full push; the DualSense jack read only when used; Linux Save Select, Quit and Restart, and the Linux launcher's sound; the update check uses the program's own version.
This commit is contained in:
23
tests/nativefp_cpu.c
Normal file
23
tests/nativefp_cpu.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* Baseline-compiled feature probe, run before either ISA-specific test driver. */
|
||||
#include <cpuid.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
unsigned a, b, c, d;
|
||||
if (argc != 2 || !__get_cpuid(1, &a, &b, &c, &d)) return 1;
|
||||
/* x86-64-v2: SSE3, SSSE3, CMPXCHG16B, SSE4.1/4.2 and POPCNT. */
|
||||
const unsigned v2 = (1u << 0) | (1u << 9) | (1u << 13) | (1u << 19) | (1u << 20) | (1u << 23);
|
||||
if ((c & v2) != v2) return 1;
|
||||
if (!__get_cpuid(0x80000001u, &a, &b, &c, &d) || !(c & (1u << 0))) return 1; /* LAHF/SAHF */
|
||||
if (!atoi(argv[1])) return 0;
|
||||
if (!(c & (1u << 5))) return 1; /* LZCNT */
|
||||
if (!__get_cpuid(1, &a, &b, &c, &d)) return 1;
|
||||
/* FMA, MOVBE, XSAVE, OSXSAVE, AVX and F16C. */
|
||||
const unsigned v3 = (1u << 12) | (1u << 22) | (1u << 26) | (1u << 27) | (1u << 28) | (1u << 29);
|
||||
if ((c & v3) != v3) return 1;
|
||||
__asm__ volatile ("xgetbv" : "=a" (a), "=d" (d) : "c" (0));
|
||||
if ((a & 6u) != 6u) return 1; /* OS saves XMM and YMM state. */
|
||||
if (!__get_cpuid_count(7, 0, &a, &b, &c, &d)) return 1;
|
||||
const unsigned v3b = (1u << 3) | (1u << 5) | (1u << 8); /* BMI1, AVX2, BMI2 */
|
||||
return (b & v3b) != v3b;
|
||||
}
|
||||
346
tests/nativefp_test.c
Normal file
346
tests/nativefp_test.c
Normal file
@@ -0,0 +1,346 @@
|
||||
/* tests/test_native_fp.py's driver: nx2/nativefp.py (ProjectReLink's native floating point, ported) against the exact
|
||||
bodies recomp_fpe_* (pure integer code: Arm's result and flags), built against the real a64.h with the a64_suyu.h /
|
||||
a64_suyu.c / a64_fpx.h the generators write (A64_NATIVE_FP=1, A64_FPX_EASY=1).
|
||||
|
||||
nativefp_test easy <n> <seed> A64_FPX_EASY: the binary32 FADD / FSUB / FMUL wrappers (a64_fpx_add32_add32,
|
||||
a64_fpx_sub32_sub32, a64_fpx_mul32_fma32 with the product's signed zero as the addend),
|
||||
random operands weighted to the special classes, random FPCR / FPSR (gate open and
|
||||
closed), and a sweep of special pairs: result AND FPSR equal to the body's.
|
||||
nativefp_test native <n> <seed> A64_NATIVE_FP's scalar helpers (a64_fpx_nat_*, every shape with a native form),
|
||||
its 2/4-lane FADD / FSUB / FMUL (a64_vfpx_nat_*), its conversions (a64_nat_*) and, at
|
||||
x86-64-v3, the FP blocks' native ops (a64_bk_n*, a lane kept when the op says not bad),
|
||||
with MXCSR's FTZ and DAZ set from FPCR.FZ as host/hos_thread.c sets them: the value
|
||||
equal to the body's (FPSR not compared: a native op raises no flag), but under FZ a
|
||||
result the body flushes to a zero that the host rounded up to the smallest normal
|
||||
(counted: "edge"; it must stay rare).
|
||||
nativefp_test nomxcsr <n> <seed> the same as native with MXCSR left at the host's default: must find mismatches (exit 1),
|
||||
or the test would not show that FTZ and DAZ are needed.
|
||||
Exit 0: pass. 1: a mismatch. */
|
||||
#include "a64.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <xmmintrin.h>
|
||||
#ifndef A64_BK
|
||||
#define A64_BK 0 /* (no FP blocks in this kit's lift) */
|
||||
#endif
|
||||
#if RECOMP_FPX_HOST != 2
|
||||
#error "x86-64 with SSE2 only"
|
||||
#endif
|
||||
|
||||
void hos_fpcr_follow(void) {} /* (the native lift's constructor calls it: host/hos_thread.c) */
|
||||
|
||||
static uint64_t rs;
|
||||
static uint64_t rnd(void) { rs ^= rs << 13; rs ^= rs >> 7; rs ^= rs << 17; return rs; }
|
||||
static uint32_t r32(void) { return (uint32_t)(rnd() >> 16); }
|
||||
static uint32_t rbelow(uint32_t n) { return (uint32_t)(((rnd() >> 32) * n) >> 32); }
|
||||
static uint32_t mkf(uint32_t s, int e, uint32_t frac) { return (s << 31) | ((uint32_t)e << 23) | (frac & 0x7fffff); }
|
||||
static uint64_t mkd(uint64_t s, int e, uint64_t frac) { return (s << 63) | ((uint64_t)e << 52) | (frac & UINT64_C(0xfffffffffffff)); }
|
||||
static float F(uint32_t x) { float f; memcpy(&f, &x, 4); return f; }
|
||||
static uint32_t B(float f) { uint32_t x; memcpy(&x, &f, 4); return x; }
|
||||
|
||||
static uint32_t op32(void) {
|
||||
const uint32_t s = r32() & 1;
|
||||
switch (rbelow(22)) {
|
||||
case 0: return s << 31;
|
||||
case 1: return mkf(s, 0, r32() | 1); /* subnormal */
|
||||
case 2: return mkf(s, 0, rbelow(4) + 1);
|
||||
case 3: return mkf(s, 1 + rbelow(3), r32()); /* near the smallest normal */
|
||||
case 4: return mkf(s, 254 - rbelow(3), r32()); /* near the largest */
|
||||
case 5: case 6: return mkf(s, 255, 0); /* inf */
|
||||
case 7: return 0x7fc12345u; /* quiet NaN with payload */
|
||||
case 8: return mkf(s, 255, 0x400000 | r32()); /* quiet NaN */
|
||||
case 9: return mkf(s, 255, (r32() & 0x3fffff) | (1u << rbelow(22))); /* signalling NaN */
|
||||
case 10: case 11: return mkf(s, 60 + rbelow(10), r32()); /* products near the normal range's bottom */
|
||||
case 12: return mkf(s, 0x7f, rbelow(3) ? 0 : r32()); /* 1.0, -1.0 */
|
||||
default: return mkf(s, 1 + rbelow(254), r32());
|
||||
}
|
||||
}
|
||||
static uint64_t op64(void) {
|
||||
const uint64_t s = r32() & 1;
|
||||
switch (rbelow(22)) {
|
||||
case 0: return s << 63;
|
||||
case 1: return mkd(s, 0, rnd() | 1);
|
||||
case 2: return mkd(s, 0, rbelow(4) + 1);
|
||||
case 3: return mkd(s, 1 + rbelow(3), rnd());
|
||||
case 4: return mkd(s, 2046 - rbelow(3), rnd());
|
||||
case 5: case 6: return mkd(s, 2047, 0);
|
||||
case 7: return UINT64_C(0x7ff8000000000000);
|
||||
case 8: return mkd(s, 2047, UINT64_C(0x8000000000000) | rnd());
|
||||
case 9: return mkd(s, 2047, (rnd() & UINT64_C(0x7ffffffffffff)) | ((uint64_t)1 << rbelow(51)));
|
||||
case 10: case 11: return mkd(s, 500 + rbelow(30), rnd());
|
||||
case 12: return mkd(s, 1023, 0);
|
||||
default: return mkd(s, 1 + rbelow(2046), rnd());
|
||||
}
|
||||
}
|
||||
/* the third operand of a multiply-add: often near the negated product (cancellations, tiny results) */
|
||||
static uint32_t addend32(uint32_t a, uint32_t b) {
|
||||
switch (rbelow(6)) {
|
||||
case 0: return B(-(float)((double)F(a) * (double)F(b)));
|
||||
case 1: return B(-(float)((double)F(a) * (double)F(b))) + (uint32_t)((int)rbelow(5) - 2);
|
||||
default: return op32();
|
||||
}
|
||||
}
|
||||
static void gen_state(uint64_t *fpcr, uint64_t *fpsr, int native) {
|
||||
uint64_t cr = 0, sr = 0;
|
||||
if (rbelow(2)) cr |= 1u << 24; /* FZ */
|
||||
if (rbelow(native ? 30 : 12) == 0) cr |= 1u << 25; /* DN (gate closed) */
|
||||
if (rbelow(native ? 30 : 12) == 0) cr |= (uint64_t)rbelow(4) << 22;
|
||||
if (rbelow(200) == 0) cr |= RECOMP_FPX_INHIBIT;
|
||||
static const uint32_t bits[6] = {1, 2, 4, 8, 16, 128};
|
||||
if (rbelow(3) == 0) sr = 0x9f;
|
||||
else for (int k = 0; k < 6; k++) if (k == 4 ? rbelow(10) != 0 : rbelow(3) != 0) sr |= bits[k];
|
||||
*fpcr = cr;
|
||||
*fpsr = sr;
|
||||
}
|
||||
|
||||
static unsigned long long checks, mismatches, edges, kept_bad;
|
||||
static int report_left = 20;
|
||||
static int mxcsr_follow = 1;
|
||||
static unsigned default_csr;
|
||||
static void csr_for(uint64_t fpcr) {
|
||||
_mm_setcsr(mxcsr_follow && (fpcr & (1u << 24)) ? (default_csr | 0x8040u) : (default_csr & ~0x8040u));
|
||||
}
|
||||
static void mism(const char *what, uint64_t cr, uint64_t sr, uint64_t a, uint64_t b, uint64_t z, uint64_t want, uint64_t wsr,
|
||||
uint64_t got, uint64_t gsr) {
|
||||
mismatches++;
|
||||
if (report_left-- > 0)
|
||||
printf("MISMATCH %s fpcr %#llx fpsr %#llx a %#llx b %#llx z %#llx: body %#llx fpsr %#llx, got %#llx fpsr %#llx\n", what,
|
||||
(unsigned long long)cr, (unsigned long long)sr, (unsigned long long)a, (unsigned long long)b,
|
||||
(unsigned long long)z, (unsigned long long)want, (unsigned long long)wsr, (unsigned long long)got,
|
||||
(unsigned long long)gsr);
|
||||
}
|
||||
/* a native value against the body's: equal, or under FZ the body's flushed zero where the host rounded up to the smallest
|
||||
normal (same sign) */
|
||||
static int native_ok(int w64, uint64_t cr, uint64_t want, uint64_t got) {
|
||||
if (want == got) return 1;
|
||||
if (!(cr & (1u << 24))) return 0;
|
||||
const uint64_t sign = w64 ? UINT64_C(1) << 63 : UINT64_C(1) << 31;
|
||||
const uint64_t minn = w64 ? UINT64_C(1) << 52 : UINT64_C(1) << 23;
|
||||
if ((want & ~sign) == 0 && (got & ~sign) == minn && (want & sign) == (got & sign)) { edges++; return 1; }
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ---- A64_FPX_EASY ---- */
|
||||
static void easy_one(int op, uint64_t cr, uint64_t sr, uint32_t a, uint32_t b) {
|
||||
Ctx ref, got;
|
||||
memset(&ref, 0, sizeof ref); ref.fpcr = cr; ref.fpsr = sr; got = ref;
|
||||
uint64_t w, v;
|
||||
const uint32_t z = (a ^ b) & 0x80000000u;
|
||||
const char *name;
|
||||
if (op == 0) { name = "fadd"; w = recomp_fpe_add32(&ref, a, b); v = a64_fpx_add32_add32(&got, a, b); }
|
||||
else if (op == 1) { name = "fsub"; w = recomp_fpe_sub32(&ref, a, b); v = a64_fpx_sub32_sub32(&got, a, b); }
|
||||
else { name = "fmul"; w = recomp_fpe_fma32(&ref, a, b, z); v = a64_fpx_mul32_fma32(&got, a, b, z); }
|
||||
checks++;
|
||||
if (w != v || ref.fpsr != got.fpsr) mism(name, cr, sr, a, b, z, w, ref.fpsr, v, got.fpsr);
|
||||
}
|
||||
static int run_easy(unsigned long long n) {
|
||||
for (unsigned long long i = 0; i < n; i++) {
|
||||
uint64_t cr, sr;
|
||||
gen_state(&cr, &sr, 0);
|
||||
easy_one((int)rbelow(3), cr, sr, op32(), op32());
|
||||
}
|
||||
static const uint32_t sp[] = {0, 0x80000000u, 1, 0x80000001u, 0x007fffffu, 0x00800000u, 0x80800000u, 0x00800001u,
|
||||
0x3f800000u, 0xbf800000u, 0x7f7fffffu, 0xff7fffffu, 0x7f800000u, 0xff800000u, 0x7fc00000u,
|
||||
0xffc00000u, 0x7fc12345u, 0x7f800001u, 0xff812345u, 0x1f800000u, 0x1f000000u, 0x20000000u,
|
||||
0x5f800000u, 0x60000000u, 0x00400000u, 0x80400000u, 0x34000000u, 0x0c000000u};
|
||||
const int ns = (int)(sizeof sp / sizeof sp[0]);
|
||||
static const uint64_t crs[2] = {0, 1u << 24}, srs[3] = {0x10, 0x9f, 0x18};
|
||||
for (int ci = 0; ci < 2; ci++)
|
||||
for (int si = 0; si < 3; si++)
|
||||
for (int i = 0; i < ns; i++)
|
||||
for (int j = 0; j < ns; j++)
|
||||
for (int op = 0; op < 3; op++) easy_one(op, crs[ci], srs[si], sp[i], sp[j]);
|
||||
printf("easy: %llu checks, %llu mismatches\n", checks, mismatches);
|
||||
return mismatches ? 1 : 0;
|
||||
}
|
||||
|
||||
/* ---- A64_NATIVE_FP ---- */
|
||||
/* (and the exact wrapper the other functions call, under the same MXCSR: its value must stay the body's exactly) */
|
||||
#define SCALAR(name, w64, body, native, exact) do { \
|
||||
Ctx ref, got, ex; \
|
||||
memset(&ref, 0, sizeof ref); ref.fpcr = cr; ref.fpsr = sr; got = ref; ex = ref; \
|
||||
_mm_setcsr(default_csr); \
|
||||
const uint64_t w_ = (body); \
|
||||
csr_for(cr); \
|
||||
const uint64_t v_ = (native); \
|
||||
const uint64_t x_ = (exact); \
|
||||
_mm_setcsr(default_csr); \
|
||||
checks += 2; \
|
||||
if (!native_ok(w64, cr, w_, v_)) mism(name, cr, sr, a, b, z, w_, ref.fpsr, v_, got.fpsr); \
|
||||
if (x_ != w_) mism(name " (exact wrapper)", cr, sr, a, b, z, w_, ref.fpsr, x_, ex.fpsr); \
|
||||
} while (0)
|
||||
|
||||
/* products whose exact value sits just below the smallest normal, where rounding may reach it: the FZ edge */
|
||||
static void edge32(uint64_t *a, uint64_t *b) {
|
||||
const double x = 1.0 + (double)(r32() & 0xffffff) / 16777216.0, t = 0x1p-126 * (1.0 - (double)(rbelow(64) + 1) * 0x1p-30);
|
||||
const float fa = (float)x, fb = (float)(t / (double)fa);
|
||||
*a = B(fa); *b = B(fb);
|
||||
if (r32() & 1) *a ^= 0x80000000u;
|
||||
}
|
||||
static void native_scalar(void) {
|
||||
uint64_t cr, sr, a, b, z;
|
||||
gen_state(&cr, &sr, 1);
|
||||
if (rbelow(8) == 0) { /* (the edge, FZ set and the gate open) */
|
||||
cr = 1u << 24;
|
||||
edge32(&a, &b);
|
||||
z = (a ^ b) & 0x80000000u;
|
||||
SCALAR("mul32 (edge)", 0, recomp_fpe_fma32(&ref, a, b, z), a64_fpx_nat_mul32_fma32(&got, a, b, z), a64_fpx_mul32_fma32(&ex, a, b, z));
|
||||
return;
|
||||
}
|
||||
switch (rbelow(12)) {
|
||||
case 0: a = op32(); b = op32(); z = 0;
|
||||
SCALAR("add32", 0, recomp_fpe_add32(&ref, a, b), a64_fpx_nat_add32_add32(&got, a, b), a64_fpx_add32_add32(&ex, a, b)); break;
|
||||
case 1: a = op32(); b = op32(); z = 0;
|
||||
SCALAR("sub32", 0, recomp_fpe_sub32(&ref, a, b), a64_fpx_nat_sub32_sub32(&got, a, b), a64_fpx_sub32_sub32(&ex, a, b)); break;
|
||||
case 2: a = op32(); b = op32(); z = (a ^ b) & 0x80000000u;
|
||||
SCALAR("mul32", 0, recomp_fpe_fma32(&ref, a, b, z), a64_fpx_nat_mul32_fma32(&got, a, b, z), a64_fpx_mul32_fma32(&ex, a, b, z)); break;
|
||||
case 3: a = op32(); b = op32(); z = 0;
|
||||
SCALAR("div32", 0, recomp_fpe_div32(&ref, a, b), a64_fpx_nat_div32_div32(&got, a, b), a64_fpx_div32_div32(&ex, a, b)); break;
|
||||
case 4: a = op32(); b = 0; z = 0;
|
||||
SCALAR("sqrt32", 0, recomp_fpe_sqrt32(&ref, a), a64_fpx_nat_sqrt32_sqrt32(&got, a), a64_fpx_sqrt32_sqrt32(&ex, a)); break;
|
||||
case 5: a = op32(); b = op32(); z = addend32((uint32_t)a, (uint32_t)b);
|
||||
SCALAR("fma32", 0, recomp_fpe_fma32(&ref, a, b, z), a64_fpx_nat_fma32_fma32(&got, a, b, z), a64_fpx_fma32_fma32(&ex, a, b, z)); break;
|
||||
case 6: a = op64(); b = op64(); z = 0;
|
||||
SCALAR("add64", 1, recomp_fpe_add64(&ref, a, b), a64_fpx_nat_add64_add64(&got, a, b), a64_fpx_add64_add64(&ex, a, b)); break;
|
||||
case 7: a = op64(); b = op64(); z = 0;
|
||||
SCALAR("sub64", 1, recomp_fpe_sub64(&ref, a, b), a64_fpx_nat_sub64_sub64(&got, a, b), a64_fpx_sub64_sub64(&ex, a, b)); break;
|
||||
case 8: a = op64(); b = op64(); z = (a ^ b) & (UINT64_C(1) << 63);
|
||||
SCALAR("mul64", 1, recomp_fpe_fma64(&ref, a, b, z), a64_fpx_nat_mul64_fma64(&got, a, b, z), a64_fpx_mul64_fma64(&ex, a, b, z)); break;
|
||||
case 9: a = op64(); b = op64(); z = 0;
|
||||
SCALAR("div64", 1, recomp_fpe_div64(&ref, a, b), a64_fpx_nat_div64_div64(&got, a, b), a64_fpx_div64_div64(&ex, a, b)); break;
|
||||
case 10: a = op64(); b = 0; z = 0;
|
||||
SCALAR("sqrt64", 1, recomp_fpe_sqrt64(&ref, a), a64_fpx_nat_sqrt64_sqrt64(&got, a), a64_fpx_sqrt64_sqrt64(&ex, a)); break;
|
||||
default: a = op64(); b = op64(); z = op64();
|
||||
SCALAR("fma64", 1, recomp_fpe_fma64(&ref, a, b, z), a64_fpx_nat_fma64_fma64(&got, a, b, z), a64_fpx_fma64_fma64(&ex, a, b, z)); break;
|
||||
}
|
||||
}
|
||||
static void native_vector(void) {
|
||||
uint64_t cr, sr;
|
||||
gen_state(&cr, &sr, 1);
|
||||
const int op = (int)rbelow(3), k = op == 2 ? 4 : (rbelow(2) ? 4 : 2);
|
||||
uint32_t a[4], b[4], want[4] = {0, 0, 0, 0}, got4[4];
|
||||
for (int j = 0; j < 4; j++) { a[j] = op32(); b[j] = op32(); }
|
||||
Ctx ref, got;
|
||||
memset(&ref, 0, sizeof ref); ref.fpcr = cr; ref.fpsr = sr; got = ref;
|
||||
_mm_setcsr(default_csr);
|
||||
for (int j = 0; j < k; j++)
|
||||
want[j] = (uint32_t)(op == 0 ? recomp_fpe_add32(&ref, a[j], b[j]) : op == 1 ? recomp_fpe_sub32(&ref, a[j], b[j])
|
||||
: recomp_fpe_fma32(&ref, a[j], b[j], (a[j] ^ b[j]) & 0x80000000u));
|
||||
uint64_t d[2], n[2], m[2];
|
||||
memcpy(n, a, 16); memcpy(m, b, 16);
|
||||
csr_for(cr);
|
||||
if (op == 0) a64_vfpx_nat_add32(&got, d, n, m, k);
|
||||
else if (op == 1) a64_vfpx_nat_sub32(&got, d, n, m, k);
|
||||
else a64_vfpx_nat_mul32(&got, d, n, m, k);
|
||||
_mm_setcsr(default_csr);
|
||||
memcpy(got4, d, 16);
|
||||
for (int j = 0; j < 4; j++) {
|
||||
checks++;
|
||||
if (!native_ok(0, cr, want[j], got4[j])) mism(op == 0 ? "vadd" : op == 1 ? "vsub" : "vmul", cr, sr, a[j], b[j], (uint64_t)j, want[j], ref.fpsr, got4[j], got.fpsr);
|
||||
}
|
||||
}
|
||||
static void native_conv(void) {
|
||||
uint64_t cr, sr;
|
||||
gen_state(&cr, &sr, 1);
|
||||
const unsigned fpb = rbelow(2) ? 32 : 64, ib = rbelow(2) ? 32 : 64, sg = rbelow(2);
|
||||
uint64_t want, got, f1 = sr, f2 = sr, x;
|
||||
if (rbelow(2)) { /* FCVTZ* (and the other rounding modes, which the native helper gives to the body) */
|
||||
const unsigned rm = rbelow(4) ? 3 : rbelow(3);
|
||||
x = fpb == 32 ? (uint64_t)op32() : op64();
|
||||
if (rbelow(2)) { /* (values in or near an integer's range, so the host's conversion is taken) */
|
||||
const int64_t iv = (int64_t)rnd() >> rbelow(64);
|
||||
const double fr = (double)iv + (double)(int)rbelow(8) / 8.0;
|
||||
if (fpb == 32) x = B((float)fr); else memcpy(&x, &fr, 8);
|
||||
}
|
||||
_mm_setcsr(default_csr);
|
||||
want = recomp_fp_to_int(x, fpb, ib, sg, rm, cr, &f1);
|
||||
csr_for(cr);
|
||||
got = a64_nat_fp_to_int(x, fpb, ib, sg, rm, cr, &f2);
|
||||
_mm_setcsr(default_csr);
|
||||
checks++;
|
||||
if (want != got) mism("fcvtz", cr, sr, x, fpb * 1000 + ib, sg * 10 + rm, want, f1, got, f2);
|
||||
} else { /* SCVTF / UCVTF */
|
||||
const unsigned fb = rbelow(4) ? 0 : rbelow(ib);
|
||||
x = rbelow(3) ? rnd() >> rbelow(64) : (uint64_t)(int64_t)(int32_t)r32();
|
||||
_mm_setcsr(default_csr);
|
||||
want = recomp_fixed_to_fp(x, fpb, ib, fb, sg, cr, &f1);
|
||||
csr_for(cr);
|
||||
got = a64_nat_fixed_to_fp(x, fpb, ib, fb, sg, cr, &f2);
|
||||
_mm_setcsr(default_csr);
|
||||
checks++;
|
||||
if (want != got) mism("cvtf", cr, sr, x, fpb * 1000 + ib, sg * 100 + fb, want, f1, got, f2);
|
||||
}
|
||||
}
|
||||
#if A64_BK
|
||||
static void native_block(void) {
|
||||
uint64_t cr, sr;
|
||||
gen_state(&cr, &sr, 1);
|
||||
cr &= (1u << 24); /* (a block runs under its gate: FPCR's FZ only) */
|
||||
const int op = (int)rbelow(10);
|
||||
uint32_t a[4], b[4], w[4], want[4] = {0, 0, 0, 0}, got4[4];
|
||||
for (int j = 0; j < 4; j++) { a[j] = op32(); b[j] = op32(); w[j] = rbelow(2) ? addend32(a[j], b[j]) : op32(); }
|
||||
Ctx ref;
|
||||
memset(&ref, 0, sizeof ref); ref.fpcr = cr; ref.fpsr = sr;
|
||||
const int lanes = op >= 4 ? 1 : 4;
|
||||
_mm_setcsr(default_csr);
|
||||
for (int j = 0; j < lanes; j++) {
|
||||
switch (op) {
|
||||
case 0: case 4: want[j] = (uint32_t)recomp_fpe_add32(&ref, a[j], b[j]); break;
|
||||
case 1: case 5: want[j] = (uint32_t)recomp_fpe_sub32(&ref, a[j], b[j]); break;
|
||||
case 2: case 6: want[j] = (uint32_t)recomp_fpe_fma32(&ref, a[j], b[j], (a[j] ^ b[j]) & 0x80000000u); break;
|
||||
case 3: case 8: want[j] = (uint32_t)recomp_fpe_fma32(&ref, a[j], b[j], w[j]); break;
|
||||
case 7: want[j] = (uint32_t)recomp_fpe_div32(&ref, a[j], b[j]); break;
|
||||
default: want[j] = (uint32_t)recomp_fpe_sqrt32(&ref, a[j]); break;
|
||||
}
|
||||
}
|
||||
__m128i va, vb, vw, bad = _mm_setzero_si128(), r;
|
||||
memcpy(&va, a, 16); memcpy(&vb, b, 16); memcpy(&vw, w, 16);
|
||||
const __m128i fzm = _mm_set1_epi32((cr & (1u << 24)) ? -1 : 0);
|
||||
csr_for(cr);
|
||||
switch (op) {
|
||||
case 0: r = a64_bk_nvadd(&bad, fzm, va, vb, A64_BK_L4); break;
|
||||
case 1: r = a64_bk_nvsub(&bad, fzm, va, vb, A64_BK_L4); break;
|
||||
case 2: r = a64_bk_nvmul(&bad, fzm, va, vb, A64_BK_L4); break;
|
||||
case 3: r = a64_bk_nvfma(&bad, fzm, va, vb, vw, A64_BK_L4); break;
|
||||
case 4: r = a64_bk_nsadd(&bad, fzm, va, vb); break;
|
||||
case 5: r = a64_bk_nssub(&bad, fzm, va, vb); break;
|
||||
case 6: r = a64_bk_nsmul(&bad, fzm, va, vb); break;
|
||||
case 7: r = a64_bk_nsdiv(&bad, fzm, va, vb); break;
|
||||
case 8: r = a64_bk_nsfma(&bad, fzm, va, vb, vw); break;
|
||||
default: r = a64_bk_nssqrt(&bad, fzm, va); break;
|
||||
}
|
||||
_mm_setcsr(default_csr);
|
||||
if (_mm_movemask_epi8(bad)) { kept_bad++; return; } /* (the block's fallback runs: the per-op helpers, checked above) */
|
||||
memcpy(got4, &r, 16);
|
||||
for (int j = 0; j < 4; j++) {
|
||||
checks++;
|
||||
if (!native_ok(0, cr, want[j], got4[j])) mism("block", cr, sr, a[j], b[j], (uint64_t)(op * 10 + j), want[j], ref.fpsr, got4[j], 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
static int run_native(unsigned long long n) {
|
||||
for (unsigned long long i = 0; i < n; i++) {
|
||||
native_scalar();
|
||||
native_vector();
|
||||
native_conv();
|
||||
#if A64_BK
|
||||
native_block();
|
||||
#endif
|
||||
}
|
||||
printf("native%s: %llu checks, %llu mismatches, %llu at the smallest normal's edge under FZ, %llu blocks sent to their "
|
||||
"fallback%s\n", mxcsr_follow ? "" : " (MXCSR left at its default)", checks, mismatches, edges, kept_bad,
|
||||
A64_BK ? "" : " (no FP blocks at this -march)");
|
||||
return mismatches ? 1 : 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc < 2) return 2;
|
||||
default_csr = _mm_getcsr() & ~0x8040u;
|
||||
const unsigned long long n = argc > 2 ? strtoull(argv[2], NULL, 10) : 100000;
|
||||
rs = argc > 3 ? strtoull(argv[3], NULL, 10) : 1;
|
||||
if (!rs) rs = 1;
|
||||
if (!strcmp(argv[1], "easy")) return run_easy(n);
|
||||
if (!strcmp(argv[1], "native")) return run_native(n);
|
||||
if (!strcmp(argv[1], "nomxcsr")) { mxcsr_follow = 0; return run_native(n); }
|
||||
return 2;
|
||||
}
|
||||
@@ -39,6 +39,7 @@ int rx_option(int id, int otherwise) {
|
||||
}
|
||||
static int pad_headphones = -1; /* (what the made-up pad's report says: -1 nothing) */
|
||||
int hos_sdl_pad_headphones(void *pad) { (void)pad; return pad_headphones; }
|
||||
void hos_sdl_pad_headphones_release(void) {}
|
||||
|
||||
static int endpoints = 1, endpoint_channels = 4, alive = 1, opened, closed, open_fails;
|
||||
static void *unmatched_pad;
|
||||
|
||||
@@ -78,12 +78,15 @@ int main(void) {
|
||||
evil_hd_foliage(1.0f, out);
|
||||
CHECK(same(out, game, 1.0f));
|
||||
evil_hd_foliage(2.5f, out);
|
||||
CHECK(out[0] == 100.0f && out[1] == 150.0f && out[5] == 337.5f && out[4] == 100.0f && out[7] == 112.5f);
|
||||
CHECK(out[0] == 80.0f && out[1] == 120.0f && out[5] == 337.5f && out[4] == 100.0f && out[7] == 112.5f);
|
||||
CHECK(out[2] == 75.0f && out[3] == 70.0f); /* (the ornaments and shoot leaves kept to 75 and 70 m: 11-25 flicker) */
|
||||
evil_hd_foliage(4.0f, out);
|
||||
CHECK(out[0] == 160.0f && out[1] == 240.0f && out[5] == 540.0f && out[2] == 75.0f && out[3] == 70.0f);
|
||||
CHECK(out[0] == 80.0f && out[1] == 120.0f && out[5] == 540.0f && out[2] == 75.0f && out[3] == 70.0f);
|
||||
evil_hd_foliage(2.0f, out);
|
||||
CHECK(out[2] == 70.0f && out[3] == 60.0f); /* (under their most: the factor's own) */
|
||||
CHECK(out[0] == 80.0f && out[1] == 120.0f); /* (the undergrowth at its most: 11-26 child Kokiri Forest) */
|
||||
evil_hd_foliage(1.5f, out);
|
||||
CHECK(out[0] == 60.0f && out[1] == 90.0f);
|
||||
/* which bytes are known: the game's, or what a write of this left (a factor from 1 to 4) */
|
||||
CHECK(evil_hd_foliage_known(game));
|
||||
for (float f = 1.0f; f <= 4.0f; f += 0.25f) {
|
||||
|
||||
@@ -96,6 +96,7 @@ using std::abs; // (GLSL's abs of a float, not the C library's of an int)
|
||||
static float clamp(float v, float lo, float hi) { return v < lo ? lo : v > hi ? hi : v; }
|
||||
static vec3 clamp(vec3 v, float lo, float hi) { return {clamp(v.r, lo, hi), clamp(v.g, lo, hi), clamp(v.b, lo, hi)}; }
|
||||
static float min(float a, float b) { return a < b ? a : b; }
|
||||
static float max(float a, float b) { return a > b ? a : b; }
|
||||
static bvec3 lessThanEqual(vec3 a, vec3 b) { return {a.r <= b.r, a.g <= b.g, a.b <= b.b}; }
|
||||
static bool all(bvec3 v) { return v.r && v.g && v.b; }
|
||||
static bool any(bvec3 v) { return v.r || v.g || v.b; }
|
||||
@@ -210,6 +211,24 @@ int main() {
|
||||
for (int i = 0; i < 300; i++) r.frame_(scene_at(5), glow, glow_t);
|
||||
need(std::fabs(r.layer.w - glow_t) < 0.03f, "the camera still: T kept", r.layer.w, glow_t);
|
||||
|
||||
// A calm background after a turn (a plain cliff face, standing by a moving waterline): the scene behind the HUD changes
|
||||
// a little every frame, far less than kMinChange. What the turn taught is kept: T stays known (the HUD did not change),
|
||||
// and the next turn finds it right, not started again
|
||||
Run calm;
|
||||
for (int i = 0; i < 6; i++) calm.frame_(scene_at(i), glow, glow_t);
|
||||
int calm_unknown = 0, calm_wrong = 0;
|
||||
for (int i = 0; i < 300; i++) {
|
||||
const float k = 0.004f * (i % 3);
|
||||
calm.frame_(vec3(0.20f + k, 0.30f + k, 0.25f - k), glow, glow_t);
|
||||
if (calm.layer.w < 0) calm_unknown++;
|
||||
else if (std::fabs(calm.layer.w - glow_t) > 0.04f) calm_wrong++;
|
||||
}
|
||||
need(calm_unknown <= 4, "a calm background after a turn: T stays known", calm_unknown, 4);
|
||||
need(calm_wrong == 0, "and stays the HUD's", calm_wrong, 0);
|
||||
const float calm_frames = calm.fit.z;
|
||||
calm.frame_(scene_at(7), glow, glow_t);
|
||||
need(calm.fit.z > calm_frames && calm.layer.w >= 0, "the next turn: known at once, not started again", calm.layer.w, glow_t);
|
||||
|
||||
// No HUD: no layer to lay (the made frame untouched: fg_hud_composite.comp returns at (0, 0, 0, 1))
|
||||
Run none;
|
||||
for (int i = 0; i < 4; i++) none.frame_(scene_at(i), glow, 0.0f, false);
|
||||
|
||||
210
tests/test_native_fp.py
Normal file
210
tests/test_native_fp.py
Normal file
@@ -0,0 +1,210 @@
|
||||
"""(Triforce, 11-26) nx2/nativefp.py (ProjectReLink's native floating point, ported), game-free: A64_FPX_EASY bit-exact with the
|
||||
software bodies (result and FPSR), A64_NATIVE_FP's helpers equal to the bodies in value with MXCSR's FTZ / DAZ following
|
||||
FPCR.FZ (the smallest normal's rounding edge under FZ counted apart), the exact wrappers' values unchanged under that MXCSR,
|
||||
and the lift's text: the options off leave a64_fpx.h and a hot function's text as they were, to the byte; a function the
|
||||
game's patches name keeps the exact helpers.
|
||||
|
||||
Built like tests/test_fpx_sticky.py (a64emit from its source, a64_suyu.h / a64_suyu.c by a64_rtgen, a64_fpx.h by a64_lift.fpx_header
|
||||
with the passes nx2/lift.py installs and nx2/nativefp.py last), and tests/nativefp_test.c compiled against the real rt/a64.h
|
||||
at the lifted code's FP flags, at -march=x86-64-v3 (a host FMA) and x86-64-v2. Then deliberately broken helpers, each built
|
||||
at v3 and run on a smaller set, must fail, and the driver run with MXCSR left at its default must find mismatches (FTZ and
|
||||
DAZ are needed).
|
||||
|
||||
python -I -B tests/test_native_fp.py [--cc clang] [--cxx clang++] [--n 300000] [--no-faults]
|
||||
|
||||
Skipped (exit 0) on a host that is not x86-64 or has no C/C++ compiler; a build this CPU cannot run is skipped.
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import platform
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
sys.path.insert(0, os.path.join(ROOT, "tests"))
|
||||
sys.path.insert(0, os.path.join(ROOT, "nx2"))
|
||||
import test_fpx_sticky as fs # noqa: E402 (its compiler, target, build and run helpers; its paths on sys.path)
|
||||
|
||||
SEED = 20261126
|
||||
BUILDS = (("x86-64-v3", 1), ("x86-64-v2", 0))
|
||||
SHAPES = {("add32", "add32", 2, 2), ("sub32", "sub32", 2, 2), ("mul32", "fma32", 2, 3), ("div32", "div32", 2, 2),
|
||||
("sqrt32", "sqrt32", 1, 1), ("fma32", "fma32", 3, 3), ("add64", "add64", 2, 2), ("sub64", "sub64", 2, 2),
|
||||
("mul64", "fma64", 2, 3), ("div64", "div64", 2, 2), ("sqrt64", "sqrt64", 1, 1), ("fma64", "fma64", 3, 3)}
|
||||
# (name, text in the generated a64_fpx.h, its broken form, the driver's mode that must fail)
|
||||
FAULTS = (
|
||||
("easy: an overflow without OFC", "if (m == 0x7f800000u) fl |= 4u | 16u; /* (overflow: OFC and IXC) */",
|
||||
"if (m == 0x7f800000u) fl |= 16u;", "easy"),
|
||||
("easy: inf - inf as the host's default NaN", "t = 0x7fc00000u, fl |= 1u; /* inf - inf */", "t = 0xffc00000u, fl |= 1u;",
|
||||
"easy"),
|
||||
("easy: a tiny product under FZ not flushed", "if (fz) t = sign, fl |= 8u;", "if (fz) fl |= 8u;", "easy"),
|
||||
("native: a scalar NaN result kept", "if (RECOMP_LIKELY(r == r)) goto done;", "goto done;", "native"),
|
||||
("native: a vector NaN lane kept", "if (RECOMP_LIKELY(!(_mm_movemask_ps(odd) & (lanes)))) {", "if (1) {", "native"),
|
||||
("native: FCVTZS's out-of-range answer kept", "if (RECOMP_LIKELY(r != INT32_MIN)) return (uint32_t)r;",
|
||||
"return (uint32_t)r;", "native"),
|
||||
("native: UCVTF from 64 bits by the signed conversion", " if (is_signed) {\n const int64_t v = (int64_t)bits;",
|
||||
" {\n const int64_t v = (int64_t)bits;", "native"),
|
||||
)
|
||||
|
||||
|
||||
def generate(cxx, tmp, flags):
|
||||
"""a64_suyu.h / .c and a64_fpx.h (the lift's passes, A64_NATIVE_FP and A64_FPX_EASY on), with the checks of the options off
|
||||
and of the hot text's rewrite"""
|
||||
dll = os.path.join(tmp, "a64emit.dll" if os.name == "nt" else "liba64emit.so")
|
||||
fs.build([cxx, "-std=c++20", "-O0", "-shared", "-Wno-everything", "-o", dll, os.path.join(fs.KIT, "lift", "a64emit.cpp")]
|
||||
+ flags + ([] if os.name == "nt" else ["-fPIC"]), "a64emit")
|
||||
import build_emit
|
||||
build_emit.build = lambda force=False: dll
|
||||
import a64_lift
|
||||
import a64_rtgen
|
||||
import a64emit
|
||||
import fastvec
|
||||
import fma_soft
|
||||
import fma_steps
|
||||
import nativefp
|
||||
fastvec.install()
|
||||
fma_soft.install()
|
||||
fma_steps.install()
|
||||
base = a64_lift.fpx_header(SHAPES)
|
||||
base_hot = a64_lift.hot_text
|
||||
saved = {k: os.environ.get(k) for k in ("A64_NATIVE_FP", "A64_FPX_EASY")}
|
||||
try:
|
||||
for k in saved: # (on by default since 11-26: unset is on, =0 off)
|
||||
os.environ.pop(k, None)
|
||||
if not (nativefp.native_fp() and nativefp.fpx_easy()):
|
||||
raise SystemExit("nativefp: A64_NATIVE_FP / A64_FPX_EASY are not on by default")
|
||||
for k in saved:
|
||||
os.environ[k] = "0"
|
||||
if nativefp.native_fp() or nativefp.fpx_easy():
|
||||
raise SystemExit("nativefp: =0 does not turn an option off")
|
||||
nativefp.install()
|
||||
if a64_lift.fpx_header(SHAPES) != base or a64_lift.hot_text is not base_hot:
|
||||
raise SystemExit("nativefp: the options off changed a64_fpx.h or the hot text")
|
||||
nativefp._installed = False
|
||||
os.environ["A64_NATIVE_FP"] = "1"
|
||||
os.environ["A64_FPX_EASY"] = "1"
|
||||
nativefp.install()
|
||||
header = a64_lift.fpx_header(SHAPES)
|
||||
check_text(nativefp, a64_lift)
|
||||
finally:
|
||||
for k, v in saved.items():
|
||||
if v is None:
|
||||
os.environ.pop(k, None)
|
||||
else:
|
||||
os.environ[k] = v
|
||||
if header == base:
|
||||
raise SystemExit("nativefp: not on")
|
||||
for (fast, exact), (_, _, call) in nativefp.EASY.items():
|
||||
line = [x for x in header.split("\n") if x.startswith("A64_FPX_FN uint64_t a64_fpx_%s_%s(" % (fast, exact))]
|
||||
if len(line) != 1 or (call + "} return recomp_fpe_") not in line[0]:
|
||||
raise SystemExit("nativefp: the wrapper a64_fpx_%s_%s has no easy rescue last: %s" % (fast, exact, line))
|
||||
try:
|
||||
a64_rtgen.write(tmp)
|
||||
finally:
|
||||
if a64emit._lib is not None:
|
||||
import _ctypes
|
||||
(_ctypes.FreeLibrary if os.name == "nt" else _ctypes.dlclose)(a64emit._lib._handle)
|
||||
a64emit._lib = None
|
||||
with open(os.path.join(tmp, "a64_fpx.h"), "w", newline="\n") as f:
|
||||
f.write(header)
|
||||
return header
|
||||
|
||||
|
||||
def check_text(nativefp, a64_lift):
|
||||
"""the hot text's rewrite: names only, nothing in a function the game's patches name, and MSR FPCR followed by the host's
|
||||
sync"""
|
||||
text = ("void f_8ff01000(Ctx *__restrict A64_NOESC c) {\n"
|
||||
" { uint64_t _a=0,_b=0,_v; _v=a64_fpx_hot_add32_add32(c,_a,_b); }\n"
|
||||
" a64_vfpx_mul32(c,c->vreg[1],c->vreg[2],c->vreg[3],4);\n"
|
||||
" c->x[8]=recomp_fp_to_int(c->vreg[0][0]&UINT64_C(0xffffffff),32,32,1,3,c->fpcr,&c->fpsr);\n}\n")
|
||||
out = nativefp.native_text(text)
|
||||
want = (text.replace("a64_fpx_hot_add32_add32(c,", "a64_fpx_nat_add32_add32(c,")
|
||||
.replace("a64_vfpx_mul32(c,", "a64_vfpx_nat_mul32(c,").replace("recomp_fp_to_int(", "a64_nat_fp_to_int("))
|
||||
if out != want:
|
||||
raise SystemExit("nativefp: the hot text's rewrite:\n%s\nwanted:\n%s" % (out, want))
|
||||
if "a64_fpx_nat_" not in a64_lift.hot_text(text):
|
||||
raise SystemExit("nativefp: a function the patches do not name kept the exact helpers")
|
||||
import fastfp
|
||||
named = sorted(fastfp.mentioned_addresses())
|
||||
if not named:
|
||||
raise SystemExit("nativefp: the game's patches name no address (fastfp.mentioned_addresses)")
|
||||
kept = a64_lift.hot_text(text.replace("f_8ff01000", "f_%08x" % named[0]))
|
||||
if "a64_fpx_nat_" in kept or "a64_vfpx_nat_" in kept:
|
||||
raise SystemExit("nativefp: a function the game's patches name was given the native names")
|
||||
msr = " c->fpcr = (c->x[5] & 0xffffffffULL) | (c->fpcr & RECOMP_FPX_INHIBIT);\n"
|
||||
if nativefp.fpcr_text(msr) != msr.rstrip("\n") + " { extern void hos_fpcr_sync(Ctx *A64_NOESC); hos_fpcr_sync(c); }\n":
|
||||
raise SystemExit("nativefp: MSR FPCR not followed by hos_fpcr_sync: %r" % nativefp.fpcr_text(msr))
|
||||
|
||||
|
||||
def compile_driver(cc, tmp, march, inc, name):
|
||||
exe = os.path.join(tmp, "nativefp_test_%s.exe" % name)
|
||||
fs.build([cc] + fs.target_flags(cc, tmp) + ["-march=" + march] + fs.FLAGS +
|
||||
["-D_CRT_SECURE_NO_WARNINGS", "-I" + inc, "-I" + tmp, "-I" + os.path.join(fs.KIT, "rt"),
|
||||
os.path.join(ROOT, "tests", "nativefp_test.c"), os.path.join(tmp, "a64_suyu.c"), "-o", exe],
|
||||
"the driver " + name)
|
||||
return exe
|
||||
|
||||
|
||||
def main():
|
||||
p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
p.add_argument("--cc")
|
||||
p.add_argument("--cxx")
|
||||
p.add_argument("--n", type=int, default=300000)
|
||||
p.add_argument("--no-faults", action="store_true")
|
||||
a = p.parse_args()
|
||||
if platform.machine().lower() not in ("x86_64", "amd64"):
|
||||
fs.skip("not an x86-64 host: %s" % platform.machine())
|
||||
if not os.environ.get("HOOKSHOT_MINGW") and os.name == "nt": # (an llvm-mingw on PATH, as test_fpx_sticky.py)
|
||||
w = shutil.which("clang++")
|
||||
if w and os.path.isfile(os.path.join(os.path.dirname(w), "x86_64-w64-mingw32-clang++.exe")):
|
||||
os.environ["HOOKSHOT_MINGW"] = os.path.dirname(os.path.dirname(w))
|
||||
cc = fs.compiler(a.cc, "CC", ("clang", "gcc", "cc"), "clang")
|
||||
cxx = fs.compiler(a.cxx, "CXX", ("clang++", "g++", "c++"), "clang++")
|
||||
if not cc or not cxx:
|
||||
fs.skip("no C compiler" if not cc else "no C++ compiler")
|
||||
t0 = time.time()
|
||||
failed, ran = [], []
|
||||
with tempfile.TemporaryDirectory(prefix="nativefp-") as tmp:
|
||||
probe = os.path.join(tmp, "nativefp_cpu.exe")
|
||||
fs.build([cc] + fs.target_flags(cc, tmp) + ["-march=x86-64", os.path.join(ROOT, "tests", "nativefp_cpu.c"), "-o", probe],
|
||||
"the CPU feature probe")
|
||||
supported = {march: fs.run([probe, str(fma)]).returncode == 0 for march, fma in BUILDS}
|
||||
header = generate(cxx, tmp, fs.target_flags(cxx, tmp))
|
||||
for march, _ in BUILDS:
|
||||
if not supported[march]:
|
||||
print("%-10s skipped (this CPU or OS does not support %s)" % (march, march))
|
||||
continue
|
||||
exe = compile_driver(cc, tmp, march, tmp, march)
|
||||
for mode in ("easy", "native"):
|
||||
r = fs.run([exe, mode, str(a.n), str(SEED)], timeout=3600)
|
||||
print("%-10s %s" % (march, r.stdout.rstrip()))
|
||||
ran.append(march)
|
||||
if r.returncode:
|
||||
failed.append("%s %s (exit %d)" % (march, mode, r.returncode))
|
||||
r = fs.run([exe, "nomxcsr", str(a.n // 4), str(SEED)], timeout=3600)
|
||||
print("%-10s %s" % (march, r.stdout.rstrip().splitlines()[-1] if r.stdout.strip() else r.returncode))
|
||||
if r.returncode != 1:
|
||||
failed.append("%s: native ops with MXCSR at its default found no mismatch (exit %d)" % (march, r.returncode))
|
||||
if not a.no_faults and "x86-64-v3" in ran:
|
||||
for i, (what, old, new, mode) in enumerate(FAULTS):
|
||||
if header.count(old) < 1:
|
||||
raise SystemExit("nativefp: the fault %r: its text is not in a64_fpx.h" % what)
|
||||
d = os.path.join(tmp, "fault%d" % i)
|
||||
os.makedirs(d)
|
||||
with open(os.path.join(d, "a64_fpx.h"), "w", newline="\n") as f:
|
||||
f.write(header.replace(old, new))
|
||||
exe = compile_driver(cc, tmp, "x86-64-v3", d, "fault%d" % i)
|
||||
code = fs.run([exe, mode, str(max(20000, a.n // 10)), str(SEED)], timeout=3600).returncode
|
||||
print("fault %-55s %s (exit %d)" % (what, "caught" if code == 1 else "NOT CAUGHT", code))
|
||||
if code != 1:
|
||||
failed.append("fault not caught: " + what)
|
||||
if not ran:
|
||||
fs.skip("this CPU is not x86-64-v2")
|
||||
if failed:
|
||||
raise SystemExit("nativefp: FAIL (%s) in %.1f s" % (", ".join(failed), time.time() - t0))
|
||||
print("nativefp: pass in %.1f s" % (time.time() - t0))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -1,7 +1,8 @@
|
||||
"""host/oot_menu.c's two halves: what other host files call is defined in both, and benchmark mode presses through the start
|
||||
in both.
|
||||
|
||||
The file is one half on Windows (#if defined(_WIN32)) and another elsewhere (#else). A function the Windows half added for the
|
||||
The file is one half for the game (#if !defined(HOS_OOT_MENU_NO_MOUSE): Windows, and Linux since the System page's Quit entry)
|
||||
and another for the tests (#else). A function the first half added for the
|
||||
rest of the host (v0.5.0's hos_oot_mods_down, nn_hid.c) and not the other half stopped every Linux build at the link (11-18).
|
||||
This test lists the non-static functions each half defines and the ones host/*.c outside it call, and checks that every one
|
||||
called from outside is in the non-Windows half too.
|
||||
@@ -29,7 +30,7 @@ DEF = re.compile(r"^(?!static\b)[A-Za-z_][\w \t\*]*?\b(hos_\w+)\s*\([^;]*\)\s*\{
|
||||
|
||||
|
||||
def halves(text):
|
||||
start = text.index("#if defined(_WIN32)")
|
||||
start = text.index("#if !defined(HOS_OOT_MENU_NO_MOUSE)")
|
||||
other = text.index("\n#else", start)
|
||||
end = text.index("\n#endif", other)
|
||||
return text[start:other], text[other:end]
|
||||
@@ -196,7 +197,7 @@ class OotMenuBenchOtherHalfTest(unittest.TestCase):
|
||||
shutil.copy(ROOT / "host" / "guest_bounds.h", tmp / "host" / "guest_bounds.h")
|
||||
(tmp / "host" / "t.c").write_text(FIXTURE, encoding="utf-8")
|
||||
binary = tmp / "t.exe"
|
||||
other_half = ["-DHOS_OOT_MENU_NO_MOUSE"] if sys.platform == "win32" else []
|
||||
other_half = ["-DHOS_OOT_MENU_NO_MOUSE"] # (the game's builds, Linux's too, have the first half)
|
||||
build = subprocess.run([compiler, "-std=gnu11", "-Wall", "-Werror", "-O1", "-g"] + other_half +
|
||||
[str(tmp / "host" / "t.c"), str(tmp / "host" / "oot_menu.c"), "-o", str(binary)],
|
||||
text=True, capture_output=True)
|
||||
|
||||
@@ -628,7 +628,7 @@ int main(void) {
|
||||
|
||||
|
||||
# The game's own Options screen named for the renderer (its tabs sit in it): every system's, the mouse or not. On Windows
|
||||
# the file's other half is compiled for this (HOS_OOT_MENU_NO_MOUSE), which is the half Linux gets
|
||||
# the file's other half is compiled for this (HOS_OOT_MENU_NO_MOUSE) on every system
|
||||
OPTIONS_FIXTURE = r"""
|
||||
#include "hos.h"
|
||||
#include "../gpu/vk/vk_api.h"
|
||||
@@ -718,7 +718,7 @@ class OotOptionsScreenTests(unittest.TestCase):
|
||||
shutil.copy(ROOT / "host" / "oot_title_movie.h", tmp / "host" / "oot_title_movie.h") # (oot_menu_screen_tick)
|
||||
(tmp / "host" / "t.c").write_text(OPTIONS_FIXTURE + MENU_TICK, encoding="utf-8")
|
||||
binary = tmp / "t.exe"
|
||||
other_half = ["-DHOS_OOT_MENU_NO_MOUSE"] if sys.platform == "win32" else []
|
||||
other_half = ["-DHOS_OOT_MENU_NO_MOUSE"]
|
||||
build = subprocess.run([compiler, "-std=gnu11", "-Wall", "-O1", "-g", str(tmp / "host" / "t.c")] +
|
||||
["-c", "-o", str(tmp / "t.o")], text=True, capture_output=True)
|
||||
self.assertEqual(build.returncode, 0, build.stderr)
|
||||
|
||||
Reference in New Issue
Block a user