Compare commits

...

1 Commits

Author SHA1 Message Date
coah
0d9bf7c0b8 zi8alpha/zi81key: small fuzzy gains (worker 004853ec) 2026-09-30 22:54:38 +00:00
5 changed files with 194 additions and 55 deletions

View File

@@ -53,7 +53,7 @@ Progress
<!-- progress:start -->
| Decompiled | Matched | Linked | Data |
|:---:|:---:|:---:|:---:|
| 98.82% | 86.03% | 60.25% | 90.87% |
| 98.83% | 86.03% | 60.25% | 90.87% |
units 899/1027 complete, functions 12120/12563 matched.

View File

@@ -311,7 +311,7 @@ Zi8UInt Zi8SpellingPY(ziU16 *output,Zi8UInt key,ziU8 includeTone)
return length;
}
ziU8 Zi8IsMatch1Key(ziU16 *input,Zi8UInt inputLength,Zi8UInt key,ziU8 requireFull,ziU8 usePinyin,Zi8UInt tone)
ziU8 Zi8IsMatch1Key(ziU16 *input,Zi8UInt inputLength,Zi8UInt key,ziU8 requireFull,ziU8 usePinyin,ziU8 tone)
{
ziU16 spelling[16];
Zi8UInt spellingLength;
@@ -330,7 +330,7 @@ ziU8 Zi8IsMatch1Key(ziU16 *input,Zi8UInt inputLength,Zi8UInt key,ziU8 requireFul
if ((requireFull != 0) && ((inputLength & 0xff) != (spellingLength & 0xff))) {
return 0;
}
if (((tone & 0xff) == 0) && ((inputLength & 0xff) > (spellingLength & 0xff))) {
if ((tone == 0) && ((inputLength & 0xff) > (spellingLength & 0xff))) {
switch (input[(inputLength & 0xff) - 1]) {
case 0xeff1:
case 0xeff2:
@@ -943,8 +943,7 @@ Zi8UInt Zi8Get1KeyPressSpelling(Zi8OneKeyParam *params,Zi8OneKeyOptions *options
*output |= 0xf300;
output++;
} else {
*output = 0xf360;
output++;
*output++ = 0xf360;
}
}
tableIndex++;

View File

@@ -305,7 +305,7 @@ ziU8 Zi8LangSupported(ziU8 language, ziPtr work);
ziU8 Zi8MatchOEMdata(ziWChar* elements, ziU8 count, ziU8 language, ziWChar* word, ziU16 capacity, ziU8 mode, ziU8 status, ziPtr work);
ziU8 Zi8MatchPUDdata(ziWChar* elements, ziU8 count, ziU8 language, ziWChar* word, ziU16 capacity, ziU8 mode, ziU8 status, ziPtr work);
ziU8 Zi8MatchROMdata(ziWChar* elements, ziU8 count, ziU8 language, ziWChar* word, ziU16 capacity, ziU8 mode, ziU8 status, ziBool reservedMode, ziBool exactLength, ziPtr work);
ziU8 Zi8MatchUWDdata(ziWChar* elements, ziU8 count, ziWChar* currentWord, ziU8 currentLength, ziU8 language, ziWChar* word, ziU16 capacity, ziU8 mode, ziU8 status, ziPtr work);
ziU8 Zi8MatchUWDdata(ziWChar* elements, ziU8 count, ziWChar* currentWord, ziU16 currentLength, ziU8 language, ziWChar* word, ziU16 capacity, ziU8 mode, ziU8 status, ziPtr work);
void Zi8Memset(ziPtr destination, ziU32 value, ziU32 count);
ziU16 Zi8WCharCount(ziWChar* word, ziPtr work);
ziBool Zi8ZHCheckSpelling(ziWChar* word, ziWChar* elements, ziU8 count, ziPtr work);
@@ -414,7 +414,12 @@ int Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr optionData, ziPtr workDa
phoneticInput = ZI8_TRUE;
for (elementIndex = 0; elementIndex < elementCount; elementIndex++) {
normalizedElements[elementIndex] = elements[elementIndex];
if ((int)elements[elementIndex] < 0xf336 && (int)elements[elementIndex] >= 0xf331) {
switch ((int)elements[elementIndex]) {
case 0xf331:
case 0xf332:
case 0xf333:
case 0xf334:
case 0xf335:
phoneticSeparator = ZI8_TRUE;
phoneticInput = ZI8_FALSE;
if ((language == 0x7d) || ((language == 0x79 || (language == 0x7a)))) {
@@ -887,7 +892,7 @@ selectDictionary:
if ((((matchMode == 0) && (currentVowelRestriction)) &&
((2 < (int)elementCount &&
((((ZiAlphaWork*)workData)->language == language &&
((unsigned int)((ZiAlphaWork*)workData)->prefixCount == elementCount - 1)))))) &&
(((ZiAlphaWork*)workData)->prefixCount == elementCount - 1)))))) &&
(elements[elementCount - 1] == 0xeff1)) {
wordLength = 0;
}
@@ -942,15 +947,15 @@ selectDictionary:
}
if (wordLength != 0) goto filterVowelCandidate;
dictionaryStatus[dictionaryKind] = 1;
if (elements[apostropheIndex] < 0xEFF1) goto finishDictionaryPass;
goto retryDictionary;
if (elements[apostropheIndex] >= 0xEFF1) goto retryDictionary;
goto finishDictionaryPass;
}
filterVowelCandidate:
if ((wordLength != 0) && (prefixVowelRestriction)) {
if ((*wordCursor >= 0x30) && (*wordCursor <= 0x39)) {
wordLength = 0;
} else {
if (((elementCount == 1) && (dictionaryKind != 10)) && (0xeff0 < *wordCursor)) {
if (((elementCount == 1) && (dictionaryKind != 10)) && (*wordCursor >= 0xeff1)) {
punctuationCandidate = ZI8_TRUE;
goto finishDictionaryPass;
}
@@ -1017,60 +1022,52 @@ filterVowelCandidate:
}
break;
case 10:
index = *punctuationCursor;
*wordCursor = index;
if (index == 0) {
if ((*wordCursor = *punctuationCursor) != 0) {
punctuationCursor++;
wordLength = 1;
} else {
wordLength = 0;
}
else {
punctuationCursor = punctuationCursor + 1;
wordLength = 1;
break;
case 11:
if (prefixCount != 0) break;
if (retryPunctuation) {
for (index = 0; index < parameters->elementCount - 1; index++) {
wordCursor[index] = ((ZiAlphaWork*)workData)->prefix[index];
if (wordCursor[index] == 0) break;
}
if (index < parameters->elementCount - 1) {
wordLength = 0;
break;
}
} else {
for (index = 0; index < ((ZiAlphaWork*)workData)->rememberedCount; index++) {
wordCursor[index] = ((ZiAlphaWork*)workData)->rememberedWord[index];
if (wordCursor[index] == 0) break;
}
if (index < ((ZiAlphaWork*)workData)->rememberedCount) {
wordLength = 0;
break;
}
}
if ((wordCursor[index++] = *punctuationCursor) != 0) {
punctuationCursor++;
wordLength = index;
} else {
wordLength = 0;
}
break;
case 0xb:
if (prefixCount == 0) {
if (retryPunctuation) {
for (index = 0;
index < parameters->elementCount - 1; index++) {
wordCursor[index] = ((ZiAlphaWork*)workData)->prefix[index];
if (wordCursor[index] == 0) break;
}
if (index < (int)(parameters->elementCount - 1)) {
wordLength = 0;
}
else {
appendPunctuation:
wordLength = index + 1;
wordCursor[index] = *punctuationCursor;
if (wordCursor[index] == 0) {
wordLength = 0;
}
else {
punctuationCursor = punctuationCursor + 1;
}
}
}
else {
for (index = 0;
index < ((ZiAlphaWork*)workData)->rememberedCount; index++) {
wordCursor[index] = ((ZiAlphaWork*)workData)->rememberedWord[index];
if (wordCursor[index] == 0) break;
}
if ((int)(unsigned int)((ZiAlphaWork*)workData)->rememberedCount <= index) goto appendPunctuation;
wordLength = 0;
}
}
}
dictionaryStatus[dictionaryKind] = 1;
if (wordLength == 0) {
dictionaryStatus[dictionaryKind] = 2;
if ((((((((ZiAlphaWork*)workData)->prefixEnabled != '\0') && (!retryPunctuation)) && (parameters->elementCount != 0)) &&
(((int)(parameters->elementCount - 1) <= (int)(unsigned int)((ZiAlphaWork*)workData)->requiredLength &&
((((ZiAlphaWork*)workData)->requiredLength >= parameters->elementCount - 1 &&
(parameters->elements[parameters->elementCount - 1] == 0xEFF1)))) &&
(((((ZiAlphaWork*)workData)->prefixEnabled != '\x01' ||
(((ZiAlphaWork*)workData)->requiredLength != parameters->elementCount)) &&
(((((ZiAlphaWork*)workData)->prefixLength == '\0' ||
((unsigned int)parameters->elementCount <= ((ZiAlphaWork*)workData)->prefixLength + 1)) && (dictionaryExact != 0)))
(((ZiAlphaWork*)workData)->prefixLength + 1 >= parameters->elementCount)) && (dictionaryExact != 0)))
))) && ((((completionAllowed && (prefixCount == 0)) && (dictionaryKind != 0xb)) &&
((((int)dictionaryIndex < (int)(unsigned int)((ZiAlphaWork*)workData)->dictionaryCount &&
(((ZiAlphaOptions*)optionData)->lookupMode == '\0')) &&
@@ -1089,10 +1086,10 @@ appendPunctuation:
}
if ((((((dictionaryExact == 0) || (!completionAllowed)) || (prefixCount != 0)) ||
((dictionaryKind == 0xb ||
((int)(unsigned int)((ZiAlphaWork*)workData)->dictionaryCount <= (int)dictionaryIndex)))) ||
(elements == (ziU16 *)0x0)) ||
(dictionaryIndex >= ((ZiAlphaWork*)workData)->dictionaryCount)))) ||
(elements == 0)) ||
((((elementCount == 0 || (elements[elementCount - 1] != 0xeff1)) ||
(((unsigned int)((ZiAlphaWork*)workData)->rememberedCount != parameters->elementCount - 1 ||
((((ZiAlphaWork*)workData)->rememberedCount != parameters->elementCount - 1 ||
(((((ZiAlphaWork*)workData)->rememberedWord[0] == 0 || (((ZiAlphaOptions*)optionData)->lookupMode != '\0')) ||
(((ZiAlphaWork*)workData)->dictionaries[language] != 0)))))) ||
(languagePassCount == 2)))) break;

View File

@@ -179,3 +179,74 @@ Final rejected variants (restored the committed higher score after each):
Final retained scores: alternate sound 100%, ZY 99.756096%, PY 97.54777%, spelling 97.867645%, candidates 95.355446%. All large bodies are complete. ZY retains six table-address register differences; PY retains a register-held tone rather than the target halfword stack slot; spelling retains helper-result copies and output-cursor scheduling differences; candidates retain helper-result copies, matcher argument narrowing and counter/output scheduling. Each remaining function has more than three distinct source-level attempts recorded. Five of nine functions are instruction-exact.
Final full gate over both owned units: GATE PASS, full build ok, original DOL hash 26116613f624061ba99c8d1a299aaa6efa85670d, both pools identical, zero regressions, zero added forbidden patterns and zero readability warnings. zi81key exact functions 4/9 -> 5/9, exact code 2588 -> 3952 of 21460 bytes, exact data 1208/1388 unchanged, weighted fuzzy 96.5146% -> 97.1719%. zi8alpha exact functions 10/12 unchanged, exact code 5704/21664 and exact data 72/564 unchanged, weighted fuzzy 86.7764% -> 88.8508%. These are partial matching improvements; the remaining functions are not claimed exact.
## Address-order continuation from 131d8f74, 2026-09-30
Entry open functions, largest first:
- Zi8Get1KeyPressCandidates: 9588 bytes, 95.355446%, 2386/2397 instructions.
- Zi8Get1KeyPressSpelling: 6800 bytes, 97.867645%, 1700/1700 instructions.
- Zi8SpellingPY: 628 bytes, 97.54777%, 158/157 instructions.
- Zi8SpellingZY: 492 bytes, 99.756096%, 123/123 and six register differences.
Entry unit: 5/9 instruction-exact, exact code 3952/21460, data 1208/1388.
The two large frames already agree, 0x140 and 0x90 respectively. Pools are
identical. All rejected variants below were restored before final validation.
Candidate call and output audit:
1. Recovered the byte sixth argument of Zi8IsMatch1Key from the target's literal
argument narrowing. The initial formal change alone added a redundant byte
normalization in the matcher. Replaced its masked zero test with the typed
byte zero test: matcher again 97/97, diffs 0, objdiff 100%. Candidates improve
to 95.39716%, 2387/2397. Retained; quick gate PASS, zero regressions.
2. Halfword key and byte length matcher formals with ordinary typed uses:
matcher stays exact, candidates 95.26784%, 2398/2397. Halfword key alone gives
the same result. Rejected; byte sixth argument remains.
3. Explicit halfword casts of nested Zi8GetPCode results: unchanged 95.39716%.
Explicit halfword masks: 94.456406%, 2391/2397. Rejected.
4. Preincrement total count inside OEM/PUD/phrase capacity comparisons:
95.106384%, 2384/2397. Removes target-redundant reloads but perturbs other
call-result copies; rejected.
5. Byte duplicate-bit result and return in Zi8SetFindCand: helper remains
50/50, diffs 0, 100%; candidates 94.73383%, 2395/2397. Explicit byte casts at
the callers produce the same candidate code. Rejected in favor of the
higher candidate score; original helper remains exact and unchanged.
Spelling call and cursor audit:
1. Postincrement compound store for non-apostrophe conversion: 96.723526%,
1697/1700. The target pointer scheduling is closer, but new helper copies
and register differences lower the score. Rejected.
2. Constant-first language-support comparisons: unchanged 97.867645%,
1700/1700, with the same two missing fallback-call result copies.
3. Put the converted-candidate index increment in the for header: 97.75%,
1700/1700, eight structural groups instead of six. Rejected.
4. Explicit converted-character OR assignment: unchanged 97.867645%.
5. Postincrement only the apostrophe replacement, as at 814620C8..814620D4:
97.92647%, 1699/1700, five structural groups. Retained. The remaining gaps
are fallback-call copies and non-apostrophe cursor scheduling.
ZY register-only attempts: flattened row indexing 125/123, rejected;
row pointer dereference 123/123 and the same six register differences; generic
output formal 123/123 with 115 differences, rejected. Full-width initial/final
indices with explicit halfword normalization separately and together each
retain 99.756096%, 123/123 and the same six table-address register differences.
No variant was retained.
PY attempts: initialize length before decoded components, 97.038216%, 158/157;
signed tone, 94.55414%, 158/157; decode tone after spelling rows, 94.968155%,
158/157; for-loop scans, unchanged 97.54777%, 158/157. No variant recovers the
original halfword tone slot at stack 0x8 without a register-backed tone.
No artificial tone-storage object or volatile qualifier was introduced.
All four open functions have at least three distinct measured source-level
attempts in this run. Only ZY is registers-only. No new exact function is
claimed; both units remain NonMatching. The existing complete function bodies
remain present, and no shared header or other unit was edited.
Final full gate over both units: GATE PASS. Full clean 43U build passes, DOL
SHA1 26116613f624061ba99c8d1a299aaa6efa85670d, both pools identical, zero
regressions, zero forbidden patterns and zero readability warnings. One-key
unit remains 5/9 instruction-exact, code 3952/21460 and data 1208/1388;
weighted fuzzy 97.17185% -> 97.20914%. Exact-count completion is not achieved.

View File

@@ -164,3 +164,75 @@ Final rejected variants (restored the committed higher score after each):
Final retained alpha engine: 84.70755%, frame 0x2b0, 3978/3946 instructions. Every body region is present. Scalar slots remain four bytes below target; the original stores a workspace snapshot at stack 0x20 that is never loaded. Tried used generic snapshots and typed field views; they altered call or field register allocation and lowered the score. No unused snapshot or padding was introduced. Remaining structural differences include phonetic range-load reuse, result copies, punctuation/dictionary branches and cursor scheduling. Case conversion retains eight register swaps in 44/44 instructions, 99.09091%; multiple formal, selector, cursor and loop variants do not resolve them. Ten of twelve functions remain exact.
Final full gate over both owned units: GATE PASS, full build ok, original DOL hash 26116613f624061ba99c8d1a299aaa6efa85670d, both pools identical, zero regressions, zero added forbidden patterns and zero readability warnings. zi81key exact functions 4/9 -> 5/9, exact code 2588 -> 3952 of 21460 bytes, exact data 1208/1388 unchanged, weighted fuzzy 96.5146% -> 97.1719%. zi8alpha exact functions 10/12 unchanged, exact code 5704/21664 and exact data 72/564 unchanged, weighted fuzzy 86.7764% -> 88.8508%. These are partial matching improvements; the remaining functions are not claimed exact.
## Address-order continuation from 131d8f74, 2026-09-30
Entry open functions, largest first: Zi8AlphaGetCandidates, 15784 bytes,
84.70755%, 3978/3946 instructions; Zi8ChangeWordCase, 176 bytes, 99.09091%,
44/44 instructions and eight register differences. Entry unit exact functions
10/12, exact code 5704/21664, exact data 72/564, pool identical.
Frame-first experiments, rejected and restored:
- A typed workspace field view in scalar declaration order: 84.04105%,
3979/3946. It changes parameter allocation and does not recover the snapshot.
- A generic helper workspace used for all helper calls: 83.70933%, 3990/3946.
Scalar offsets agree, but target register moves become stack loads.
- A snapshot used once for duplicate-buffer initialization: 84.86721%,
3979/3946. Rejected despite the small score gain: its main effect is occupying
the target's unused workspace slot, without evidence for that source use.
- Scoped phonetic-character local and nested range comparisons: 82.6779%,
3980/3946, introduces a frame pointer. Rejected.
- Five-case phonetic separator switch: 84.68272%, 3979/3946. Its range dispatch
agrees structurally after accounting for the unresolved scalar offsets, but
register changes lower the whole-function score. Rejected for now.
- Full-width table-count return with explicit halfword casts: 84.361885%,
3979/3946. It does not recover the missing call-result copies. Rejected.
- A switch on the context table flag: 84.68221%, 3979/3946, extra branch.
- Native signed-long scalar types: exactly the original 84.70755%, 3978/3946.
Re-translated the punctuation dictionary and shared remembered/prefix append
blocks at target 81467B08..81467C4C. The target tests the value of the wide
character assignment, emits the nonzero case first, merges both history scans
before appending, and increments the append index before storing word length.
Retained these complete blocks: 85.41105%, 3980/3946, frame 0x2b0. Quick gate
PASS, identical pool, zero regressions, zero forbidden/style patterns.
Case-conversion register-only trials: byte-address workspace, unsigned-long
selector, renamed selector, renamed workspace and renamed word each retain
44/44 instructions and the same eight r29/r30 differences. A const byte
workspace conflicts with the helper's writable generic argument. All rejected;
the original readable case-conversion function remains.
The earliest engine obstacle is still the target's dead workspace store at
stack 0x20. No unused local or artificial stack placeholder was retained.
Later differences include call-result copies, signed comparisons, dispatches
and output cursor scheduling. This engine is not registers-only or exact.
Further block audit in this run:
- Recovered Zi8MatchUWDdata's halfword current-word length formal from the
target's r6 narrowing at 81467A48. Removed the unsigned prefix-count
comparison, restored EFF1 as the lower punctuation bound, and reversed the
failed apostrophe branch to the target's retry-first form: 85.46452%,
3981/3946 instructions. Other functions unchanged.
- Two contiguous next-dictionary switches: 85.34263%, 3978/3946; first switch
alone: 85.37557%, 3978/3946. Both reduce instruction count but lower the
whole score, so rejected.
- Recovered signed length/count comparisons with operands in target order and
ordinary null-pointer comparison: 85.79067%, 3979/3946. Retained.
- Retried the phonetic separator switch after these fixes: 85.829956%,
3980/3946. Retained. The range-dispatch instructions now agree from the
function entry through normalization, apart from the unresolved workspace
snapshot, scalar offsets and register choices. Missing call-result copies
and the safe early dictionary-index initialization remain distinct gaps.
Final full gate over both units: GATE PASS. Full clean 43U build passes, DOL
SHA1 26116613f624061ba99c8d1a299aaa6efa85670d, identical pools, zero
regressions, zero forbidden patterns and zero readability warnings. Alpha
remains 10/12 instruction-exact, code 5704/21664 and data 72/564; weighted
fuzzy 88.850815% -> 89.66857%. Engine 84.70755% -> 85.829956%, 3980/3946
instructions, frame 0x2b0; case conversion unchanged and registers-only.
The requested exact-count improvement and complete retranslation are not
achieved. The unresolved snapshot prevents instruction alignment at the top;
no artificial snapshot was retained to bypass that obstacle.