mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-22 05:05:56 +00:00
Test functions with calls in tests/diff/func.py: every BL and BLR goes to one stub on both sides, which folds the registers at the call into a digest kept in the scratch buffer and sets X0-X18, NZCV and V0-V7 from it, so a register missing from the Cpu at a call or held across one fails the case
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6c14dd5937
commit
e9216b8b49
3 files changed
+174
-38
No files matched your search
+48
-4
@@ -1,5 +1,6 @@
|
||||
// Runs lifted single-instruction tests and writes the resulting CPU state per case.
|
||||
// Shared by tests/diff/lift.py and tests/diff/simd.py; the expected state comes from Unicorn on the Python side.
|
||||
// Runs lifted tests and writes the resulting CPU state per case.
|
||||
// Shared by tests/diff/lift.py, simd.py, atomic.py and func.py; the expected state comes from Unicorn on the Python
|
||||
// side.
|
||||
//
|
||||
// argv: buf.bin cases.bin out.bin image base [image base ...]
|
||||
// Each image is mapped at its guest address (guest == host), the scratch buffer at BUF.
|
||||
@@ -19,7 +20,48 @@ extern int ntests;
|
||||
#define BUF 0x7200000000ull
|
||||
#define BUF_SIZE 0x40000
|
||||
|
||||
void rt_dispatch(Cpu *c) { (void)c; }
|
||||
#define PTR_LO (BUF + 0x8000)
|
||||
#define PTR_SPAN 0x20000
|
||||
|
||||
static int g_stubs; // In.stubs of the running case
|
||||
static uint64_t g_stub_h; // digest of every call's state so far
|
||||
|
||||
static uint64_t splitmix(uint64_t z) {
|
||||
z += 0x9E3779B97F4A7C15ull;
|
||||
z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ull;
|
||||
z = (z ^ (z >> 27)) * 0x94D049BB133111EBull;
|
||||
return z ^ (z >> 31);
|
||||
}
|
||||
|
||||
static uint64_t mix(uint64_t h, uint64_t w) { return (h ^ w) * 0x100000001B3ull; }
|
||||
|
||||
// The callee of every call in a function under tests/diff/func.py; Runner.stub there is the same function on the
|
||||
// Unicorn side. Folds the target, X0-X30, SP and V0-V7 into a digest, so a register the caller left unwritten at the
|
||||
// call changes it, then sets X0-X18, NZCV and V0-V7 from the digest, so a caller reading a register it held across
|
||||
// the call sees a value the callee could have left. X0-X7 mostly get pointers into the scratch buffer. The digest
|
||||
// and the call count go to the top of the scratch buffer, which the memory check covers.
|
||||
static void rt_stub(Cpu *c, uint64_t target) {
|
||||
uint64_t h = mix(g_stub_h, target);
|
||||
for (int i = 0; i < 31; i++) h = mix(h, c->x[i]);
|
||||
h = mix(h, c->sp);
|
||||
for (int i = 0; i < 8; i++) h = mix(mix(h, (uint64_t)c->v[i]), (uint64_t)(c->v[i] >> 64));
|
||||
g_stub_h = h;
|
||||
for (int i = 0; i < 19; i++) {
|
||||
uint64_t s = splitmix(h + i);
|
||||
c->x[i] = i < 8 && (s & 3) ? PTR_LO + ((s >> 4) % (PTR_SPAN / 16)) * 16 : s;
|
||||
}
|
||||
c->nzcv = splitmix(h + 19) >> 60 << 28;
|
||||
for (int i = 0; i < 8; i++)
|
||||
c->v[i] = (__uint128_t)splitmix(h + 33 + 2 * i) << 64 | splitmix(h + 32 + 2 * i);
|
||||
uint64_t *slot = (uint64_t *)(uintptr_t)(BUF + BUF_SIZE - 16);
|
||||
slot[0]++;
|
||||
slot[1] = h;
|
||||
}
|
||||
|
||||
void rt_dispatch(Cpu *c) {
|
||||
if (g_stubs) rt_stub(c, c->pc);
|
||||
}
|
||||
void rt_stub_call(Cpu *c, uint64_t target) { rt_stub(c, target); }
|
||||
void rt_svc(Cpu *c, uint32_t imm, uint64_t pc) { (void)c; (void)imm; (void)pc; }
|
||||
void rt_brk(Cpu *c, uint32_t imm, uint64_t pc) { (void)c; (void)imm; (void)pc; abort(); }
|
||||
void rt_udf(Cpu *c, uint64_t pc) { (void)c; (void)pc; abort(); }
|
||||
@@ -61,7 +103,7 @@ static uint32_t crc32_buf(const uint8_t *p, size_t n) {
|
||||
}
|
||||
|
||||
// Layouts match IN_FMT / OUT_FMT in tests/diff/common.py.
|
||||
struct In { uint64_t k, fpcr, x[32], sp, nzcv; __uint128_t v[32]; uint64_t memchk, pad; };
|
||||
struct In { uint64_t k, fpcr, x[32], sp, nzcv; __uint128_t v[32]; uint64_t memchk, stubs; };
|
||||
struct Out { uint64_t x[32], sp, nzcv, pc, mem; __uint128_t v[32]; };
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
@@ -96,6 +138,8 @@ int main(int argc, char **argv) {
|
||||
c.fpcr = in.fpcr;
|
||||
memcpy(c.v, in.v, sizeof c.v);
|
||||
c.excl_addr = ~0ull;
|
||||
g_stubs = (int)in.stubs;
|
||||
g_stub_h = 0;
|
||||
tests[in.k](&c);
|
||||
memcpy(out.x, c.x, sizeof out.x);
|
||||
out.sp = c.sp;
|
||||
|
||||
Reference in new issue
Block a user