Compare commits

...

1 Commits

Author SHA1 Message Date
coah
b03456b238 decomp: correct Chinese phonetic contracts and Zhuyin dispatch 2026-10-02 19:03:25 -05:00
5 changed files with 220 additions and 21 deletions

View File

@@ -138,11 +138,11 @@ extern ziU16 Zi8GetTableCount(ziU8 language, ziU8 table, ziPtr work);
extern ziU8 Zi8IsDupWChar(ziWChar character, ziPtr work);
extern ziU8 Zi8IsDupWordW(ziWChar* word, ziU8 length, ziPtr work);
extern ziWChar Zi8Ord2Uni(ziU16 ordinal, ziPtr work);
extern ziU8 Zi8MatchPhonetic(ziU8* phonetics, ZiChineseRecord* records,
ziPtr indexTable, ziU16 indexCount, ziPtr dictionary,
ZiChineseRecord* record, ziU16* mask, ziU16* match,
ziU16* length, ZiChineseRecord** matchedRecord,
int* matchedIndex, ziU8 wordMode, ziU8 partial,
extern ziU8 Zi8MatchPhonetic(ziPtr phonetics, ziU8* records,
ziPtr indexTable, ziU16 indexCount, ziU32 dictionary,
ziU8* record, ziU16* mask, ziU16* match,
ziU16* length, ziU8** matchedRecord,
ziU8** matchedString, ziU8 wordMode, ziU8 partial,
ziU8 oneCharacter, ziU16 excludedMask,
ziU16 excludedMatch, ziU8 charset, ziU8 options,
ziU16 ordinal, ziU16* tone, ziU8 spellingOnly,
@@ -614,10 +614,10 @@ static int zi8InternalGetZH(ziGetParam* request, ZiChineseOptions* options, ziPt
case 56: case 59:
if (((ziFuzzyZYPairs*)&((struct __zi8_work_data_s*)work)->unk_0x1B2C.word)->fANDh) ordinalIndex = 0xF9FF;
break;
case 52: case 55:
case 60: case 63:
if (((ziFuzzyZYPairs*)&((struct __zi8_work_data_s*)work)->unk_0x1B2C.word)->bANDp) ordinalIndex = 0xF9FF;
break;
case 60: case 63:
case 52: case 55:
if (((ziFuzzyZYPairs*)&((struct __zi8_work_data_s*)work)->unk_0x1B2C.word)->gANDk) ordinalIndex = 0xF9FF;
break;
case 38:
@@ -1612,9 +1612,9 @@ phonetic_ordinal_search:
record = records + phraseOrdinal * 12;
candidateCount = 0;
phoneticGroups = 0;
if (!Zi8MatchPhonetic(phoneticTable, (ZiChineseRecord*)records, alternateTable, alternateCount,
phraseTable, (ZiChineseRecord*)record, match.phon, match.phon2,
&candidateCount, (ZiChineseRecord**)&record, (int*)&phoneticGroups,
if (!Zi8MatchPhonetic(phoneticTable, records, alternateTable, alternateCount,
(ziU32)phraseTable, record, match.phon, match.phon2,
&candidateCount, &record, &phoneticGroups,
0, 1, match.nCand, phoneticMask, phoneticMatch, charset, requireFull,
phraseOrdinal, &candidateOrdinal, 0, work)) continue;
if (charsetTable) {
@@ -2323,9 +2323,9 @@ phonetic_ordinals:
candidateCount = recordCount;
phoneticGroups = 0;
while (emittedCount < request->maxCandidates && candidateCount) {
if (!Zi8MatchPhonetic(phoneticTable, (ZiChineseRecord*)records, alternateTable, alternateCount,
phraseTable, (ZiChineseRecord*)record, match.phon, match.phon2,
&candidateCount, (ZiChineseRecord**)&record, (int*)&phoneticGroups,
if (!Zi8MatchPhonetic(phoneticTable, records, alternateTable, alternateCount,
(ziU32)phraseTable, record, match.phon, match.phon2,
&candidateCount, &record, &phoneticGroups,
emitWords, singleCharacterPass, match.nCand, phoneticMask, phoneticMatch, charset,
requireFull, recordCount, &candidateOrdinal, filteringMode, work)) break;
ordinalIndex = recordCount - candidateCount - 1;
@@ -2608,10 +2608,10 @@ static int Zi8NewMatchPhonetic(ziGetParam* request, ZiChineseRecord* records,
ziU8* phonetics;
int totalResults;
int emittedCharacters;
ZiChineseRecord* matchedRecord;
ziU8* matchedRecord;
ziU8* phoneticGroups;
ziU8* candidateGroups;
int matchedIndex;
ziU8* matchedString;
int capacity;
ziU8* groupCandidates;
ziU16 phoneticCount;
@@ -2782,12 +2782,12 @@ next_group_candidate:
}
}
if (stopAfterTone) {
matchedRecord = records + character;
matchedRecord = (ziU8*)(records + character);
matchedLength = 0;
matchedIndex = 0;
if (!Zi8MatchPhonetic(phonetics, records, indexTable, indexCount,
dictionary, matchedRecord, &mask, &match,
&matchedLength, &matchedRecord, &matchedIndex,
matchedString = 0;
if (!Zi8MatchPhonetic(phonetics, (ziU8*)records, indexTable, indexCount,
(ziU32)dictionary, matchedRecord, &mask, &match,
&matchedLength, &matchedRecord, &matchedString,
wordMode, 1, 1, excludedMask, excludedMatch,
charset, request->getOptions & 0x40, character,
&matchedTone, 0, work)) {

View File

@@ -254,7 +254,7 @@ ziBool Zi8PriMatchNextComp(ziU8* node, ziU8 mask0, ziU8 value0, ziU8 mask1, ziU8
return 0;
}
ziBool Zi8SecMatchComp(ziPtr nodeAddress, ziMatchParam* matchAddress, ziPtr dictionaryAddress) {
ziBool Zi8SecMatchComp(ziPtr nodeAddress, ziMatchParam* matchAddress, ziPtr dictionaryAddress ZI_NEED_WORK) {
int chainIndex;
ziU16 matchCode;
ziU16 targetCode;

View File

@@ -0,0 +1,75 @@
# Chinese phonetic callee contract, 2026-10-02
Base: 654c65dd; branch agent/bittle/chinese-source-reconstruction.
Changed source: libs/RVLMiddleware/eZiText/src/clib/zi8cgetc.c only.
This is type-correctness work with zero code-generation or percentage gain.
## Callee evidence
The actual Zi8MatchPhonetic definition in zi8match.c takes a byte-addressed
12-byte dictionary, a native-width ziU32 dictionary address, a byte record
pointer, and two byte-pointer outputs. In particular its stringOffset output
is ziU8**: it tests *stringOffset, compares a sound cursor against it, and
writes the sound cursor to it. It is not an integer index output.
The old zi8cgetc declaration instead described records and the record output
with a different struct-pointer type, the dictionary address as ziPtr, and
the string output as int*. The two engine calls cast &phoneticGroups to
int*. The third call, in Zi8NewMatchPhonetic, supplied an address-taken int
matchedIndex even though the callee wrote a pointer through it.
The corrected local declaration now has exactly the callee's parameter
representations and compatible C types:
- ziPtr for the opaque phonetic table
- ziU8* for the dictionary and current record
- ziU32 for the packed-table address
- ziU8** for the current-record and string-cursor outputs
- the unchanged matching halfword, byte and workspace parameter types
All three call sites were inspected and updated. The engine's real byte
pointer variables can now be passed by address directly, without incompatible
pointer-to-pointer casts. The small exact helper retains its typed dictionary
array but passes its byte address and uses actual byte-pointer output locals;
matchedString names the recovered cursor role. No shared header or callee
implementation is changed, and the pointer-to-native-word cast is explicit
only at the callee's existing native-address argument boundary.
## Isolated investigation
- Native 12-byte dictionary table indexing: codegen/metrics unchanged
- Named dictionary-record stride: codegen/metrics unchanged
- String-pointer output correction alone: codegen/metrics unchanged
- Complete callee contract, all three call sites: codegen/metrics unchanged
Only the callee-contract correction is retained. These are source-type
checks, not register/declaration-order permutations. The previously parked
halfword-result and component-cursor experiments were not repeated in this
candidate or combined incidentally.
## Validation
Baseline: /tmp/ezi-chinese-recon-baseline.json.
Final full report: /tmp/ezi-chinese-contract-full-report.json.
Full build: /tmp/ezi-chinese-contract-full-build.log.
Detailed checks: /tmp/ezi-chinese-contract-verification.txt.
All 1027 full-report unit measures are unchanged. Unit fuzzy remains
96.65468%; zi8InternalGetZH remains 96.27482%. Exact functions remain 5/8,
exact code 4168/47816, and exact data 144/536. No metric gain is claimed.
Compared with a preserved baseline object, every owned code/data section has
identical length, payload bytes and canonical relocation tuples:
.text 47816, .sdata2 16, .sbss2 8, .data 392, extab 48, extabindex 72.
The NOBITS section is checked by extent; all other payloads compare bytewise.
Pool first: identical and empty. All five baseline exact functions retain
ctxdiff diffs 0 with identical instruction counts:
Zi8SetFindCand 50, ZiGetNextPhonetic 31, ZiPartialMatch 51,
Zi8NewMatchPhonetic 755, Zi8GetChineseCandidates 155.
The unmatched engine remains 10676/10676 instructions; its code payload and
relocations are baseline-identical as well.
Full 43U build passes with the approved wrapper and WIBO_SJIS_MISSING_IMPORTS=1.
DOL SHA1: 26116613f624061ba99c8d1a299aaa6efa85670d.
git diff --check passes. No linking, remote, metadata, shared-header, assembly,
volatile, artificial storage or register-forcing changes.

View File

@@ -0,0 +1,67 @@
# Chinese Zhuyin initial dispatch correction, 2026-10-02
Parent: 1b1a944a on base 654c65dd. The pointer-contract candidate is unchanged.
Changed source: two case-label lines in zi8cgetc.c / zi8InternalGetZH.
This is a demonstrated behavioral correction; aggregate metrics are neutral.
## Discovery
A complete fresh flow audit checked the compiler-generated switch tables as
well as direct branches. All 1594 mapped direct branches and all 168 ordered
helper calls agreed before this change. However, four of the 98 generated
switch relocation entries dispatched to the wrong semantic bodies. A direct
branch-only audit cannot see that defect, and the linear effect audit compares
both bodies without knowing which switch cases reach them.
The relevant switch uses the phonetic initial (match.phon2[index] >> 9),
subtracts case 24 for its 40-entry table and rejects indexes greater than39.
The table starts at .data+0x58. Its four incorrect entries were:
- .data+0xC8, case52: source selected bANDp; target selects gANDk
- .data+0xD4, case55: source selected bANDp; target selects gANDk
- .data+0xE8, case60: source selected gANDk; target selects bANDp
- .data+0xF4, case63: source selected gANDk; target selects bANDp
The bodies are identified by their actual tests of the workspace word at
0x1B2C: bANDp tests the bit at MSB-relative position10, while gANDk tests
position11. Both successful bodies store the same phonetic mask0xF9FF, but
they consult independent user fuzzy-pair settings. Crossing the labels
therefore changes behavior, even though both body instruction shapes match.
Target cases52/55 enter function+0x1288 (position11), while60/63 enter+0x1264
(position10). Current compiled bodies are four bytes later, and the corrected
entries now select their corresponding semantic bodies.
The fix swaps only the two case-label pairs, preserving body/source order,
header layout, tests, masks, all other cases and function size. It does not
change shared bitfield names to compensate for the bad dispatch.
## Verification
Fresh report: /tmp/ezi-chinese-switch-full-report.json.
Full build: /tmp/ezi-chinese-switch-full-build.log.
Detailed gates: /tmp/ezi-chinese-switch-verification.txt.
Switch/direct-flow audit: /tmp/ezi-chinese-switch-flow-audit.txt.
After correction, all 98 switch entries have corresponding target semantic
destinations, with zero destination mismatches. The four table extents remain
44,44,160,144 bytes. The 1594 mapped direct branches and168 ordered helper
calls also still agree. This is an advisory relocation/control-flow check,
not formal whole-program equivalence or a claim of exact assembly.
Every code/data section size and payload is baseline-identical. All normalized
relocations are unchanged except exactly the four corrected .data entries.
The .text section, extab and extabindex are unchanged byte-for-byte. The
engine stays10676/10676 instructions with the same0x4E0 frame.
All1027 unit measures are unchanged with no regressions. Unit fuzzy remains
96.65468%; engine fuzzy96.27482%. Exact functions5/8, code4168/47816 and
matched data144/536 are preserved. The switch section remains unmatched
because case body addresses still differ from the target; no percentage or
new exact function is claimed.
All five previously exact functions still have ctxdiff diffs0 and identical
instruction counts. Pool first: identical and empty. Full43U build passes
with the approved wrapper and WIBO_SJIS_MISSING_IMPORTS=1. DOL SHA1:
26116613f624061ba99c8d1a299aaa6efa85670d.
git diff --check passes. No shared header, metadata, link flag, assembly,
volatile, register/storage workaround, or remote action was changed.

View File

@@ -0,0 +1,57 @@
# Secondary component matcher workspace formal, 2026-10-02
Parent: bfcc8a44. Scope extension to zi8match.c was coordinated before editing.
Changed source: the Zi8SecMatchComp definition's parameter list only.
This is an interface correction with no percentage or code-generation gain.
## All-caller and callee evidence
A source-wide search finds one caller, in zi8InternalGetZH, and its explicit
four-argument declaration. A scan of every extracted43U object's relocation
tables likewise finds exactly one text reference, in zi8cgetc.o. The only
other direct symbol reference is the function's own extabindex entry.
No function-pointer data reference or second callsite was found.
The target caller at zi8InternalGetZH+0x8380 supplies the component cursor,
match object, dictionary base and workspace in argument registers3..6.
The workspace is the same saved incoming pointer used by the surrounding
engine helpers. This agrees with the reconstructed caller and its declaration.
The target callee is68 instructions /0x110 bytes and does not consume the
incoming fourth argument. Every path that reads register6 first defines a
new temporary there; no incoming workspace load or use is present. The
missing fourth formal is therefore an unused workspace parameter, consistent
with neighboring component matchers' ZI_NEED_WORK convention. Removing the
caller argument would contradict the target call sequence.
Added ZI_NEED_WORK to the existing definition, preserving its first three
formals and entire body. No local or storage was added, no value was made
volatile, and no register/spill was forced. The existing shared macro simply
expands to the same ziPtr workspace formal already declared by the caller.
No shared header or caller change was needed.
## Validation
Before-object: /tmp/ezi-chinese-reconstruction/zi8match-before-work-formal.o.
Fresh full report: /tmp/ezi-component-contract-full-report.json.
Build log: /tmp/ezi-component-contract-full-build.log.
Detailed checks: /tmp/ezi-component-contract-verification.txt.
All owned emitted sections have identical lengths, payloads and normalized
relocations: .text8256, .rodata528, extab80, extabindex120. The compiler
comment section is also unchanged. Symbol entries, relocation records and
section extents are unchanged; only compiler-generated anonymous extab names
in .strtab advance numerically after the additional formal. The entire object
file is therefore not byte-identical, but its emitted code/data and relocation
meaning are identical. No symbol-metadata edits were made to hide this.
All1027 full-report unit measures are unchanged. zi8match remains8/10 exact,
5172/8256 exact code,728/728 exact data and99.53004% unit fuzzy. All eight
baseline exact functions have ctxdiff diffs0 and identical instruction counts;
Zi8SecMatchComp remains68/68 instructions,0x110 bytes and exact100%.
Pool first: identical and empty. Full43U build passes with the approved
wrapper and WIBO_SJIS_MISSING_IMPORTS=1. DOL SHA1:
26116613f624061ba99c8d1a299aaa6efa85670d.
git diff --check passes. No remote, linking, shared-header, assembly, metadata,
artificial storage or undefined-value change.