Compare commits

...

1 Commits

Author SHA1 Message Date
coah
f68c6e173d decomp: reconstruct typed CHANSVm operands 2026-10-02 17:26:59 -05:00
2 changed files with 65 additions and 20 deletions

View File

@@ -7207,7 +7207,7 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
u32 cmpLow;
struct {
CHANSVmObjType operandTypes[2];
u64 floatBits;
double floatLiteral;
CHANSVmObjHdr copies[2];
CHANSVmObjHdr load;
CHANSVmObjHdr operand;
@@ -7291,8 +7291,8 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
case CHANS_VM_OP_LOAD_FLOAT: {
opSize = 9;
operandBuf = VmGetOperand(vm, 1, 9);
memcpy(&scratch.floatBits, operandBuf, 8);
result = CHANSVmSetFloat(vm, &pVm->accumulator, *(double*)&scratch.floatBits);
memcpy(&scratch.floatLiteral, operandBuf, 8);
result = CHANSVmSetFloat(vm, &pVm->accumulator, scratch.floatLiteral);
break;
}
@@ -7769,8 +7769,8 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
arrayIdx = (u32)stackPtr->value.int_v;
goto set_index_ok;
case CHANS_VM_OBJ_TYPE_FLOAT: {
double stackFloat = *(double*)stackPtr;
if (stackFloat <= 4294967294.0 && 0.0 <= stackFloat) {
double stackFloat = stackPtr->value.float_v;
if (stackFloat >= 0.0 && stackFloat <= 4294967294.0) {
arrayIdx = (u32)stackFloat;
goto set_index_ok;
}
@@ -8004,34 +8004,27 @@ CHANSVmErr CHANSVmStep(CHANSVm* vm, int stepCount) {
if (pVm->pActiveCtx->stackDepth != 0 && pVm->pObjStackTopBuf + sizeof(CHANSVmObjHdr) <= pVm->pHeapEnd) {
CHANSVmObjHdr* stackTop = (CHANSVmObjHdr*)pVm->pObjStackTopBuf;
isTypeMatch = 0;
if (pVm->accumulator.type == stackTop->type) {
if (stackTop->type == pVm->accumulator.type) {
switch (stackTop->type) {
case CHANS_VM_OBJ_TYPE_INTEGER: {
u32 low1 = *(u32*)stackTop;
u32 low2 = *(u32*)&pVm->accumulator;
u32 high1 = *((u32*)stackTop + 1);
u32 high2 = *((u32*)&pVm->accumulator + 1);
u32 xor1 = low1 ^ low2;
u32 xor2 = high1 ^ high2;
isTypeMatch = !(xor1 | xor2);
isTypeMatch = stackTop->value.int_v == pVm->accumulator.value.int_v;
goto end_branch_check;
}
case CHANS_VM_OBJ_TYPE_FLOAT: {
double stackFloat = stackTop->value.float_v;
double accFloat = pVm->accumulator.value.float_v;
isTypeMatch = stackFloat == accFloat ? 1 : 0;
isTypeMatch = stackTop->value.float_v == pVm->accumulator.value.float_v;
goto end_branch_check;
}
case CHANS_VM_OBJ_TYPE_STRING: {
u32 len1, len2;
CHANSVmObjHdr* stackObj = (CHANSVmObjHdr*)pVm->pObjStackTopBuf;
const vmWStringObjVal* accumulatorString = pVm->accumulator.value.wstring_v;
const vmWStringObjVal* stackString = stackTop->value.wstring_v;
u32 strEqual;
isTypeMatch = 0;
len1 = stackObj->value.wstring_v->len;
len2 = pVm->accumulator.value.wstring_v->len;
len1 = stackString->len;
len2 = accumulatorString->len;
if (len1 == len2) {
strEqual = 0;
if (len1 == 0 || memcmp(stackObj->value.wstring_v->spData, pVm->accumulator.value.wstring_v->spData, len1) == 0) {
if (len1 == 0 || memcmp(stackString->spData, accumulatorString->spData, len1) == 0) {
strEqual = 1;
}
if (strEqual) {

View File

@@ -0,0 +1,52 @@
# CHANSVm typed comparison reconstruction
Baseline: ec75ddb0. This candidate is separate from the accepted load-string and opcode-error-path work. Those commits and their logs are unchanged. Only CHANSVm.c and this log changed; no headers, linking classifications, metadata, or original assets changed.
## Retained reconstruction
- LOAD_FLOAT copies the eight-byte literal into a double scratch member and passes that value directly. This replaces a u64 temporary followed by a double-pointer reinterpretation. Scratch alignment, member offsets, and emitted code are unchanged.
- SET_INDEX reads the floating operand through its union member and checks its lower bound before its upper bound, matching the target's comparison order. The accepted interval remains [0, 4294967294], with NaN and infinities rejected.
- Strict integer equality uses the declared 64-bit integer values rather than four offset-based u32 loads and manual XOR/OR expressions.
- Strict floating equality uses the declared floating values directly.
- Strict string equality uses named, read-only payload pointers rather than recreating a header pointer. The stack operand is consistently first in the outer type comparison, following the target.
This is structural/type reconstruction, not a newly discovered behavior fix. No register forcing, declaration sweep, or alignment padding was introduced.
## Target evidence
After rebuilding, the integer-comparison block (Step instructions 1093-1102), floating-comparison block (1103-1108), string-comparison block (1109-1128), and floating-index block (703-712) have the same instructions, control flow, constants, and memory offsets as the target after register names are normalized. This comparison is advisory: register differences remain, and Step is not exact.
The floating range's instruction forms now use the target's lower-bound-first order. Integer equality emits the same target ten-instruction two-word equality sequence naturally from the 64-bit value comparison. LOAD_FLOAT retains its original eight-byte copy and call sequence without a pointer reinterpretation.
## Measurements
- Instruction-exact functions: 221/233 -> 221/233; no previously exact function regressed.
- Unit Decompiled/fuzzy: 99.406320% -> 99.413185%.
- Step: 96.913800% -> 96.987230%; 1253/1253 instructions; differing positions 285 -> 276.
- Exact code: unchanged at 37608/53564 bytes (70.211334%).
- Exact data: unchanged at 6904/6904 bytes (100%).
- Per-function score regressions: zero.
- Unit remains NonMatching/unlinked, with twelve non-exact functions.
## Attempts
- Direct 64-bit equality alone: Step 96.933760%, data 100%; retained for combination.
- Typed integer/float/string comparison paths: 96.971270%, data 100%; retained.
- Those typed paths plus a separate strict-comparison local error result: 1254 instructions, table relocations moved; rejected.
- Floating index member access alone preserves the typed-comparison score. Lower-bound-first range checking raises it to 96.983240%, data 100%; retained.
- A union literal temporary produced the same code; simplified to a direct double member instead, also with identical code.
- Stack-first type comparison raises Step to 96.987230% with unchanged data; retained.
## Verification
- Full 43U build passed with the assigned wrapper and WIBO_SJIS_MISSING_IMPORTS=1.
- DOL SHA1: 26116613f624061ba99c8d1a299aaa6efa85670d.
- pool_diff: all 125 strings identical.
- .data: 4672/4672 raw bytes and 352/352 canonical relocations identical.
- .rodata: 1432/1432 raw bytes and 258/258 canonical relocations identical.
- All 233 functions checked with ctxdiff/odiff: 221 instruction-exact; no falsely exact objdiff functions.
- Literal-reference audit: 233 functions analyzed, 40 resolvable call-string arguments checked, no candidates/errors/skips.
- Source-extracted host C harnesses passed 20 strict-comparison cases, nine floating-index-bound cases, and eight floating-literal bit patterns. Coverage includes signed integer extremes, differing high words, signed zero, NaN, infinities, strings, references, deletion errors, and literal payload preservation. They stub surrounding dependencies and do not constitute Wii runtime execution.
- git diff --check passed.
Source is paused for independent parent verification.