Compare commits
1 Commits
main
...
agent/w092
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
182c9403b5 |
@@ -1006,7 +1006,7 @@ config.libs = [
|
||||
Object(Matching, "clib/zidawg1.c"),
|
||||
Object(Matching, "clib/zikorean.c"),
|
||||
Object(Matching, "clib/ziswordw.c"),
|
||||
Object(NonMatching, "clib/zkokeyp.c"),
|
||||
Object(Matching, "clib/zkokeyp.c"),
|
||||
Object(Matching, "clib/zierror.c"),
|
||||
Object(Matching, "clib/zmtkey.c"),
|
||||
Object(Matching, "clib/zoemdata.c"),
|
||||
|
||||
@@ -189,7 +189,8 @@ ziU32 Zi8_814834AC(ziGetParam* param, ziU16* remaining, ziU8* count,
|
||||
if (matches) {
|
||||
for (candidateIndex = 0; candidateIndex < *count; candidateIndex++) {
|
||||
if (param->candidates[candidateIndex] ==
|
||||
(((ziU16)((ZiKoreanKeyEntry*)tableA)[i].characterHigh << 8) | (ziU16)((ZiKoreanKeyEntry*)tableA)[i].characterLow)) {
|
||||
(((ziU16)tableA[i * sizeof(ZiKoreanKeyEntry) + offsetof(ZiKoreanKeyEntry, characterHigh)] << 8) |
|
||||
(ziU16)tableA[i * sizeof(ZiKoreanKeyEntry) + offsetof(ZiKoreanKeyEntry, characterLow)])) {
|
||||
matched++;
|
||||
param->candidates[candidateIndex] &= 0x7FFF;
|
||||
break;
|
||||
@@ -247,254 +248,251 @@ typedef struct {
|
||||
} ZiKoreanCandidateOptions;
|
||||
|
||||
ziU32 Zi8GetKOcandidates(ziGetParam* param, ZiKoreanCandidateOptions* options ZI_NEED_WORK) {
|
||||
struct {
|
||||
ziBool matches;
|
||||
ziU8 inserted;
|
||||
ziU8 matchPass;
|
||||
ziU8 keyByte;
|
||||
ziU8 candidateCount;
|
||||
ziU8 wordIndex;
|
||||
ziU8 remainingLetters;
|
||||
ziU16 remainingCandidates;
|
||||
ziU16 previousIndex;
|
||||
ziU16 character;
|
||||
ziU16 tableCount;
|
||||
ziU16 keyIndex;
|
||||
ZiKoreanKeyEntry* entry;
|
||||
ziS32 candidateIndex;
|
||||
ziS32 prefixCount;
|
||||
ziU32 wordOffset;
|
||||
ziS32 resultCount;
|
||||
ziS32 tableIndex;
|
||||
ziU8* wordTable;
|
||||
union {
|
||||
ziU32 firstWord;
|
||||
ziU8 bytes[5];
|
||||
} packedKeys;
|
||||
} search;
|
||||
ziU8* wordTable;
|
||||
ziS32 tableIndex;
|
||||
ziS32 resultCount;
|
||||
ziU32 wordOffset;
|
||||
ziS32 prefixCount;
|
||||
ziS32 candidateIndex;
|
||||
ZiKoreanKeyEntry* entry;
|
||||
ziU16 keyIndex;
|
||||
ziU16 tableCount;
|
||||
ziU16 character;
|
||||
ziU16 previousIndex;
|
||||
ziU16 remainingCandidates;
|
||||
ziU8 remainingLetters;
|
||||
ziU8 wordIndex;
|
||||
ziU8 candidateCount;
|
||||
ziU8 keyByte;
|
||||
ziU8 matchPass;
|
||||
ziU8 inserted;
|
||||
ziBool matches;
|
||||
ziU8* keyTable;
|
||||
ziU8* wordNode;
|
||||
|
||||
search.previousIndex = 0xFFFF;
|
||||
search.resultCount = 0;
|
||||
search.packedKeys.firstWord = 0;
|
||||
search.packedKeys.bytes[4] = 0;
|
||||
search.wordIndex = search.remainingLetters = 0;
|
||||
search.candidateCount = 0;
|
||||
search.keyByte = 0;
|
||||
search.remainingCandidates = param->firstCandidate;
|
||||
search.prefixCount = 0;
|
||||
search.candidateIndex = 0;
|
||||
search.inserted = 0;
|
||||
Zi8LogError(100, ZI_WORK);
|
||||
Zi8_81483264(param, ZI_WORK);
|
||||
keyTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 9, ZI_WORK);
|
||||
search.wordTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 10, ZI_WORK);
|
||||
if (keyTable == 0) {
|
||||
Zi8ReplaceLastError(0x76C, ZI_WORK);
|
||||
return 0;
|
||||
} else {
|
||||
if (search.wordTable == 0) {
|
||||
Zi8ReplaceLastError(0x776, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
if (options->countOnly == 0) {
|
||||
param->letters = 0;
|
||||
param->count = 0;
|
||||
param->candidates[0] = 0;
|
||||
}
|
||||
previousIndex = 0xFFFF;
|
||||
resultCount = 0;
|
||||
{
|
||||
ziU8 packedKeys[5] = {0};
|
||||
|
||||
remainingLetters = 0;
|
||||
wordIndex = 0;
|
||||
candidateCount = 0;
|
||||
keyByte = 0;
|
||||
remainingCandidates = param->firstCandidate;
|
||||
prefixCount = 0;
|
||||
candidateIndex = 0;
|
||||
inserted = 0;
|
||||
Zi8LogError(100, ZI_WORK);
|
||||
if (param->wordCharCount == 0) goto scan_key_table;
|
||||
{
|
||||
if (((search.keyIndex = Zi8_8148302C(param->currentWord[0], keyTable, ZI_WORK)) != 0xFFFF) &&
|
||||
((keyTable[(search.keyIndex << 3) + search.keyIndex + offsetof(ZiKoreanKeyEntry, keyBytes[4])] & 8) != 0)) {
|
||||
search.wordOffset = ((ZiKoreanKeyEntry*)(((search.keyIndex << 3) + search.keyIndex) + keyTable))->childLow |
|
||||
((((ZiKoreanKeyEntry*)(((search.keyIndex << 3) + search.keyIndex) + keyTable))->keyBytes[4] & 3) << 16 |
|
||||
((ZiKoreanKeyEntry*)(((search.keyIndex << 3) + search.keyIndex) + keyTable))->childHigh << 8);
|
||||
search.remainingLetters = param->wordCharCount - 1;
|
||||
search.wordIndex = 1;
|
||||
wordNode = search.wordTable + search.wordOffset;
|
||||
match_word:
|
||||
while (search.remainingLetters != 0) {
|
||||
search.keyIndex = Zi8_8148302C(param->currentWord[search.wordIndex], (ziU8*)keyTable, ZI_WORK);
|
||||
if (search.keyIndex == (((ziU16)*wordNode & 0x1F) << 8 | (ziU16)wordNode[1])) {
|
||||
--search.remainingLetters;
|
||||
++search.wordIndex;
|
||||
if ((*wordNode & 0x40) != 0) {
|
||||
search.remainingLetters = param->wordCharCount - 1;
|
||||
search.wordIndex = 1;
|
||||
break;
|
||||
}
|
||||
wordNode += 2;
|
||||
} else {
|
||||
search.wordIndex = 1;
|
||||
search.remainingLetters = param->wordCharCount - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (search.remainingLetters == 0) {
|
||||
search.keyIndex = ((ziU16)*wordNode & 0x1F) << 8 | (ziU16)wordNode[1];
|
||||
search.character = (ziU16)((ziU16)((ZiKoreanKeyEntry*)(((search.keyIndex << 3) + search.keyIndex) + keyTable))->characterHigh << 8 |
|
||||
((ZiKoreanKeyEntry*)(((search.keyIndex << 3) + search.keyIndex) + keyTable))->characterLow);
|
||||
if (param->wordCharCount == 1) {
|
||||
if (search.keyIndex == search.previousIndex) {
|
||||
for (; (*wordNode & 0x40) == 0; wordNode = wordNode + 2) {
|
||||
}
|
||||
wordNode += 2;
|
||||
search.remainingLetters = param->wordCharCount - 1;
|
||||
search.wordIndex = 1;
|
||||
goto next_word;
|
||||
}
|
||||
search.previousIndex = search.keyIndex;
|
||||
if (param->elementCount == 0) {
|
||||
if (search.remainingCandidates != 0) {
|
||||
--search.remainingCandidates;
|
||||
} else {
|
||||
if (options->countOnly != 0) {
|
||||
if (++search.prefixCount < (ziS32)options->maxCount) {
|
||||
goto skip_word;
|
||||
}
|
||||
return options->maxCount;
|
||||
}
|
||||
param->candidates[search.candidateCount++] = search.character;
|
||||
++param->count;
|
||||
if (++param->letters >= param->maxCandidates) {
|
||||
return param->letters;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
param->candidates[search.candidateCount++] = search.character;
|
||||
++param->count;
|
||||
if (++param->letters >= param->maxCandidates) {
|
||||
Zi8_814834AC(param, &search.remainingCandidates, &search.candidateCount, &search.inserted, ZI_WORK);
|
||||
param->count = search.candidateCount;
|
||||
param->letters = search.candidateCount;
|
||||
if (search.candidateCount < param->maxCandidates) goto skip_word;
|
||||
if (options->countOnly != 0) {
|
||||
if ((search.prefixCount += search.candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
|
||||
param->count = 0;
|
||||
param->letters = 0;
|
||||
search.candidateCount = 0;
|
||||
} else {
|
||||
return search.candidateCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (search.candidateIndex = 0; search.candidateIndex < search.candidateCount; search.candidateIndex++) {
|
||||
if (search.character == param->candidates[search.candidateIndex]) break;
|
||||
}
|
||||
if ((search.candidateIndex == search.candidateCount) &&
|
||||
(Zi8_814833F0(param, search.character, ZI_WORK) == 0)) {
|
||||
param->candidates[search.candidateCount++] = search.character;
|
||||
++param->count;
|
||||
if (++param->letters < param->maxCandidates) {
|
||||
goto skip_word;
|
||||
}
|
||||
Zi8_814834AC(param, &search.remainingCandidates, &search.candidateCount, &search.inserted, ZI_WORK);
|
||||
param->count = search.candidateCount;
|
||||
param->letters = search.candidateCount;
|
||||
if (search.candidateCount < param->maxCandidates) goto skip_word;
|
||||
if (options->countOnly != 0) {
|
||||
if ((search.prefixCount += search.candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
|
||||
param->count = 0;
|
||||
param->letters = 0;
|
||||
search.candidateCount = 0;
|
||||
} else {
|
||||
return search.candidateCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
skip_word:
|
||||
for (; (*wordNode & 0x40) == 0; wordNode = wordNode + 2) {
|
||||
}
|
||||
wordNode += 2;
|
||||
search.remainingLetters = param->wordCharCount - 1;
|
||||
search.wordIndex = 1;
|
||||
next_word:
|
||||
if ((*wordNode & 0x80) != 0) {
|
||||
goto search_table;
|
||||
}
|
||||
goto match_word;
|
||||
}
|
||||
}
|
||||
search_table:
|
||||
search.resultCount = search.prefixCount;
|
||||
if (search.candidateCount != 0) {
|
||||
Zi8_814834AC(param, &search.remainingCandidates, &search.candidateCount, &search.inserted, ZI_WORK);
|
||||
if (options->countOnly != 0) {
|
||||
if ((search.prefixCount += search.candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
|
||||
search.resultCount = search.prefixCount;
|
||||
}
|
||||
param->count = search.candidateCount;
|
||||
param->letters = search.candidateCount;
|
||||
}
|
||||
scan_key_table:
|
||||
if (param->elementCount > 9) {
|
||||
param->letters = 0;
|
||||
Zi8_81483264(param, ZI_WORK);
|
||||
keyTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 9, ZI_WORK);
|
||||
wordTable = (ziU8*)Zi8GetTableAddress(ZI8_LANG_KO, 10, ZI_WORK);
|
||||
if (keyTable == 0) {
|
||||
Zi8ReplaceLastError(0x76C, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
{
|
||||
if (param->elementCount != 0 && options->countOnly == 0) {
|
||||
search.matchPass = 0;
|
||||
} else {
|
||||
search.matchPass = 1;
|
||||
} else {
|
||||
if (wordTable == 0) {
|
||||
Zi8ReplaceLastError(0x776, ZI_WORK);
|
||||
return 0;
|
||||
}
|
||||
search.tableCount = Zi8GetTableCount(ZI8_LANG_KO, 9, ZI_WORK);
|
||||
Zi8_81483118(param, search.packedKeys.bytes);
|
||||
do {
|
||||
for (search.tableIndex = 0; search.tableIndex < search.tableCount; search.tableIndex = search.tableIndex + 1) {
|
||||
search.matches = ZI8_TRUE;
|
||||
search.entry = (ZiKoreanKeyEntry*)(((search.tableIndex << 3) + search.tableIndex) + keyTable);
|
||||
search.keyByte = 0;
|
||||
if (1 < param->elementCount) {
|
||||
for (search.keyByte = 0;
|
||||
(ziS32)search.keyByte < (int)param->elementCount / 2;
|
||||
search.keyByte++) {
|
||||
if (search.packedKeys.bytes[search.keyByte] != search.entry->keyBytes[search.keyByte]) {
|
||||
search.matches = ZI8_FALSE;
|
||||
if (options->countOnly == 0) {
|
||||
param->letters = 0;
|
||||
param->count = 0;
|
||||
param->candidates[0] = 0;
|
||||
}
|
||||
Zi8LogError(100, ZI_WORK);
|
||||
if (param->wordCharCount == 0) goto scan_key_table;
|
||||
{
|
||||
if (((keyIndex = Zi8_8148302C(param->currentWord[0], keyTable, ZI_WORK)) != 0xFFFF) &&
|
||||
((keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, keyBytes[4])] & 8) != 0)) {
|
||||
wordOffset = keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, childLow)] |
|
||||
((keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, keyBytes[4])] & 3) << 16 |
|
||||
keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, childHigh)] << 8);
|
||||
remainingLetters = param->wordCharCount - 1;
|
||||
wordIndex = 1;
|
||||
wordNode = wordTable + wordOffset;
|
||||
match_word:
|
||||
while (remainingLetters != 0) {
|
||||
keyIndex = Zi8_8148302C(param->currentWord[wordIndex], (ziU8*)keyTable, ZI_WORK);
|
||||
if (keyIndex == (((ziU16)*wordNode & 0x1F) << 8 | (ziU16)wordNode[1])) {
|
||||
--remainingLetters;
|
||||
++wordIndex;
|
||||
if ((*wordNode & 0x40) != 0) {
|
||||
remainingLetters = param->wordCharCount - 1;
|
||||
wordIndex = 1;
|
||||
break;
|
||||
}
|
||||
wordNode += 2;
|
||||
} else {
|
||||
wordIndex = 1;
|
||||
remainingLetters = param->wordCharCount - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((search.matches && ((param->elementCount % 2) != 0)) &&
|
||||
((search.packedKeys.bytes[search.keyByte] & 0xF0) !=
|
||||
(search.entry->keyBytes[search.keyByte] & 0xF0))) {
|
||||
search.matches = ZI8_FALSE;
|
||||
}
|
||||
if (search.matches) {
|
||||
if (param->elementCount % 2 != 0) {
|
||||
if ((search.entry->keyBytes[search.keyByte] & 0xF) != 0) {
|
||||
if (search.matchPass == 0) goto next_entry;
|
||||
} else if (search.matchPass != 0 && options->countOnly == 0) {
|
||||
goto next_entry;
|
||||
if (remainingLetters == 0) {
|
||||
keyIndex = ((ziU16)*wordNode & 0x1F) << 8 | (ziU16)wordNode[1];
|
||||
character = (ziU16)((ziU16)keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, characterHigh)] << 8 |
|
||||
keyTable[(keyIndex << 3) + keyIndex + offsetof(ZiKoreanKeyEntry, characterLow)]);
|
||||
if (param->wordCharCount == 1) {
|
||||
if (keyIndex == previousIndex) {
|
||||
for (; (*wordNode & 0x40) == 0; wordNode = wordNode + 2) {
|
||||
}
|
||||
wordNode += 2;
|
||||
remainingLetters = param->wordCharCount - 1;
|
||||
wordIndex = 1;
|
||||
goto next_word;
|
||||
}
|
||||
previousIndex = keyIndex;
|
||||
if (param->elementCount == 0) {
|
||||
if (remainingCandidates != 0) {
|
||||
--remainingCandidates;
|
||||
} else {
|
||||
if (options->countOnly != 0) {
|
||||
if (++prefixCount < (ziS32)options->maxCount) {
|
||||
goto skip_word;
|
||||
}
|
||||
return options->maxCount;
|
||||
}
|
||||
param->candidates[candidateCount++] = character;
|
||||
++param->count;
|
||||
if (++param->letters >= param->maxCandidates) {
|
||||
return param->letters;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
param->candidates[candidateCount++] = character;
|
||||
++param->count;
|
||||
if (++param->letters >= param->maxCandidates) {
|
||||
Zi8_814834AC(param, &remainingCandidates, &candidateCount, &inserted, ZI_WORK);
|
||||
param->count = candidateCount;
|
||||
param->letters = candidateCount;
|
||||
if (candidateCount < param->maxCandidates) goto skip_word;
|
||||
if (options->countOnly != 0) {
|
||||
if ((prefixCount += candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
|
||||
param->count = 0;
|
||||
param->letters = 0;
|
||||
candidateCount = 0;
|
||||
} else {
|
||||
return candidateCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ((search.entry->keyBytes[search.keyByte] & 0xF0) != 0) {
|
||||
if (search.matchPass == 0) goto next_entry;
|
||||
} else if (search.matchPass != 0 && options->countOnly == 0) {
|
||||
goto next_entry;
|
||||
for (candidateIndex = 0; candidateIndex < candidateCount; candidateIndex++) {
|
||||
if (character == param->candidates[candidateIndex]) break;
|
||||
}
|
||||
if ((candidateIndex == candidateCount) &&
|
||||
(Zi8_814833F0(param, character, ZI_WORK) == 0)) {
|
||||
param->candidates[candidateCount++] = character;
|
||||
++param->count;
|
||||
if (++param->letters < param->maxCandidates) {
|
||||
goto skip_word;
|
||||
}
|
||||
Zi8_814834AC(param, &remainingCandidates, &candidateCount, &inserted, ZI_WORK);
|
||||
param->count = candidateCount;
|
||||
param->letters = candidateCount;
|
||||
if (candidateCount < param->maxCandidates) goto skip_word;
|
||||
if (options->countOnly != 0) {
|
||||
if ((prefixCount += candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
|
||||
param->count = 0;
|
||||
param->letters = 0;
|
||||
candidateCount = 0;
|
||||
} else {
|
||||
return candidateCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (search.remainingCandidates != 0) {
|
||||
--search.remainingCandidates;
|
||||
} else if (options->countOnly != 0) {
|
||||
if (++search.resultCount >= (ziS32)options->maxCount) return options->maxCount;
|
||||
} else {
|
||||
param->candidates[search.candidateCount++] =
|
||||
(ziU16)((ziU16)((ZiKoreanKeyEntry*)(((search.tableIndex << 3) + search.tableIndex) + keyTable))->characterHigh << 8 |
|
||||
((ZiKoreanKeyEntry*)(((search.tableIndex << 3) + search.tableIndex) + keyTable))->characterLow);
|
||||
if (++param->letters >= param->maxCandidates) return param->letters;
|
||||
}
|
||||
}
|
||||
next_entry:
|
||||
;
|
||||
skip_word:
|
||||
for (; (*wordNode & 0x40) == 0; wordNode = wordNode + 2) {
|
||||
}
|
||||
wordNode += 2;
|
||||
remainingLetters = param->wordCharCount - 1;
|
||||
wordIndex = 1;
|
||||
next_word:
|
||||
if ((*wordNode & 0x80) != 0) {
|
||||
goto search_table;
|
||||
}
|
||||
goto match_word;
|
||||
}
|
||||
} while (++search.matchPass < 2);
|
||||
}
|
||||
search_table:
|
||||
resultCount = prefixCount;
|
||||
if (candidateCount != 0) {
|
||||
Zi8_814834AC(param, &remainingCandidates, &candidateCount, &inserted, ZI_WORK);
|
||||
if (options->countOnly != 0) {
|
||||
if ((prefixCount += candidateCount) >= (ziS32)options->maxCount) return options->maxCount;
|
||||
resultCount = prefixCount;
|
||||
}
|
||||
param->count = candidateCount;
|
||||
param->letters = candidateCount;
|
||||
}
|
||||
scan_key_table:
|
||||
if (param->elementCount > 9) {
|
||||
param->letters = 0;
|
||||
return 0;
|
||||
}
|
||||
{
|
||||
if (param->elementCount != 0 && options->countOnly == 0) {
|
||||
matchPass = 0;
|
||||
} else {
|
||||
matchPass = 1;
|
||||
}
|
||||
tableCount = Zi8GetTableCount(ZI8_LANG_KO, 9, ZI_WORK);
|
||||
Zi8_81483118(param, packedKeys);
|
||||
do {
|
||||
for (tableIndex = 0; tableIndex < tableCount; tableIndex = tableIndex + 1) {
|
||||
matches = ZI8_TRUE;
|
||||
entry = (ZiKoreanKeyEntry*)(((tableIndex << 3) + tableIndex) + keyTable);
|
||||
keyByte = 0;
|
||||
if (1 < param->elementCount) {
|
||||
for (keyByte = 0;
|
||||
(ziS32)keyByte < (int)param->elementCount / 2;
|
||||
keyByte++) {
|
||||
if (packedKeys[keyByte] != entry->keyBytes[keyByte]) {
|
||||
matches = ZI8_FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((matches && ((param->elementCount % 2) != 0)) &&
|
||||
((packedKeys[keyByte] & 0xF0) !=
|
||||
(entry->keyBytes[keyByte] & 0xF0))) {
|
||||
matches = ZI8_FALSE;
|
||||
}
|
||||
if (matches) {
|
||||
if (param->elementCount % 2 != 0) {
|
||||
if ((entry->keyBytes[keyByte] & 0xF) != 0) {
|
||||
if (matchPass == 0) goto next_entry;
|
||||
} else if (matchPass != 0 && options->countOnly == 0) {
|
||||
goto next_entry;
|
||||
}
|
||||
} else {
|
||||
if ((entry->keyBytes[keyByte] & 0xF0) != 0) {
|
||||
if (matchPass == 0) goto next_entry;
|
||||
} else if (matchPass != 0 && options->countOnly == 0) {
|
||||
goto next_entry;
|
||||
}
|
||||
}
|
||||
if (remainingCandidates != 0) {
|
||||
--remainingCandidates;
|
||||
} else if (options->countOnly != 0) {
|
||||
if (++resultCount >= (ziS32)options->maxCount) return options->maxCount;
|
||||
} else {
|
||||
param->candidates[candidateCount++] =
|
||||
(ziU16)((ziU16)keyTable[(tableIndex << 3) + tableIndex + offsetof(ZiKoreanKeyEntry, characterHigh)] << 8 |
|
||||
keyTable[(tableIndex << 3) + tableIndex + offsetof(ZiKoreanKeyEntry, characterLow)]);
|
||||
if (++param->letters >= param->maxCandidates) return param->letters;
|
||||
}
|
||||
}
|
||||
next_entry:
|
||||
;
|
||||
}
|
||||
} while (++matchPass < 2);
|
||||
}
|
||||
if (options->countOnly != 0) return resultCount;
|
||||
return param->letters;
|
||||
}
|
||||
if (options->countOnly != 0) return search.resultCount;
|
||||
return param->letters;
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
214
tools/decomp-assist/rx53.attempts.md
Normal file
214
tools/decomp-assist/rx53.attempts.md
Normal file
@@ -0,0 +1,214 @@
|
||||
# rx53 zkokeyp matching
|
||||
|
||||
Worktree `/mnt/drive2/projects/wii-ipl-workers/sol-high`, branch
|
||||
`agent/w1005/rx53`, starting commit `bf65a26b`. Fresh fetch confirms
|
||||
`origin/main` at that commit. Only `zkokeyp.c`, its Matching flag when all
|
||||
checks pass, and this log are owned. Existing rx4 artifacts are untouched.
|
||||
New measurements and private tooling are under `/tmp/rx53`.
|
||||
|
||||
## Acceptance checks
|
||||
|
||||
Both requested functions must reach exact-name objdiff 100% and ctxdiff zero
|
||||
differences. Preserve all seven functions and all 180 data bytes. Require
|
||||
identical pools, section order, clean full gate, and the retail DOL SHA1 after
|
||||
the Matching flip. Source must preserve behavior and use ordinary C.
|
||||
|
||||
## Fresh baseline
|
||||
|
||||
- `Zi8_814834AC`: 99.94169%, 343/343 instructions, two operand-order differences.
|
||||
- `Zi8GetKOcandidates`: 98.998505%, 669/669 instructions, 71 differences.
|
||||
- Unit: 5/7 exact functions, 1152/5200 matched code, 180/180 matched data.
|
||||
- Pool identical, zero strings. Compiler is GC/3.0a5.
|
||||
|
||||
Read f-round, common, all levers including 20-23, mwdbg README and the a5
|
||||
port, current source and target assembly, Ghidra output, and rx35 attempts.
|
||||
The port already exists in this worktree. A private launcher changes only
|
||||
the capture path and lock location to keep new artifacts under `/tmp/rx53`.
|
||||
|
||||
## Target register map
|
||||
|
||||
`Zi8_814834AC`, target offsets 0x7a4-0x7d0: i is r28; tableA reload is r4;
|
||||
the scaled row offset is r3. Both character byte addresses use
|
||||
`add r3, r3, r4`. Baseline uses `add r3, r4, r3`. Earlier rx35 evidence
|
||||
identifies a pre-allocation operand order difference, so declaration-order
|
||||
experiments cannot repair those two instructions alone.
|
||||
|
||||
`Zi8GetKOcandidates`: param r31, options r30, wordNode r29, keyTable r28,
|
||||
workspace r27 already match. At 0xb80-0xbdc the target adds shifted index
|
||||
and index before adding keyTable. Baseline instead adds keyTable to the
|
||||
shifted index first. Resulting temporary live ranges change caller-saved
|
||||
register assignments. The target also initializes packed keys with one
|
||||
zero load and initializes remainingLetters and wordIndex separately.
|
||||
|
||||
## Exact filter result
|
||||
|
||||
Three new field access forms all produce objdiff 100%, 343/343 instructions,
|
||||
ctxdiff zero, with no function or data drop. They use a byte subscript plus
|
||||
`offsetof` for the named character fields, with either explicit row arithmetic,
|
||||
`sizeof` row multiplication, or reversed C subscript spelling. Retain the
|
||||
ordinary `sizeof` form. The row is nonnegative and bounded by a 16-bit table
|
||||
count, so row-size and offset arithmetic preserve the original byte addresses.
|
||||
|
||||
Fresh mwdbg captures `filter-baseline` and `filter-exact` confirm the cause.
|
||||
The 155-entry priority list and all nine named-register assignments are
|
||||
unchanged. v112/v114/v115 keep r4/r3/r3 and priority positions 80/78/77.
|
||||
v119/v121/v122 keep r4/r3/r3 and priority positions 73/71/70. These six
|
||||
values are not coalesced. Their graph degrees remain 11/10/10 and 12/11/11.
|
||||
The source change reverses the two pre-color ADD input operands; all colors
|
||||
already matched. Both captures have seven accepted GPR coalesces.
|
||||
The exact capture equals its independent normal-compiler object byte for byte;
|
||||
668 GPR and 96 CR operand rewrites pass with zero mismatches.
|
||||
|
||||
## Candidates address diagnosis
|
||||
|
||||
Replacing all seven remaining computed record-field accesses with named
|
||||
byte-field offsets gives 99.70105%, 669/669 instructions, 180/180 data,
|
||||
and four differences, all in initial zero stores. This remains a private
|
||||
candidate until it is exact. Splitting the two byte counter initializations
|
||||
alone introduces a temporary and an extra call-result copy: 671 instructions,
|
||||
98.28849%, 96/180 data. Rejected.
|
||||
|
||||
Fresh baseline and byte-field mwdbg captures keep the same 213-entry priority
|
||||
list, fourteen accepted GPR coalesces, and saved registers r31-r27. keyTable's
|
||||
reference weight rises 14 to 21, still below wordNode's 27. At the first child
|
||||
address, baseline computes v66=r28+v64 then v67=v65+v66. The candidate computes
|
||||
v66=v64+v65 then v67=v66+r28. The index reload v65 loses one interference edge,
|
||||
and v66 loses one. v63/v64/v65 change r3/r0/r3 to target r0/r3/r0; childLow
|
||||
v68 changes r5 to target r6. Priority positions 186 through 181 stay fixed.
|
||||
This is an expression-lifetime change, not declaration-order or saved-register
|
||||
priority. Its full object equals the independent normal build; 1224 GPR and
|
||||
182 CR operand rewrites pass with zero mismatches.
|
||||
|
||||
The remaining initialization difference already exists in initial PCode.
|
||||
Baseline v34 clears the packed word, v35 clears its suffix, and v36 clears
|
||||
both remainingLetters and wordIndex. Retail shares the packed-key zero and
|
||||
uses separate byte counter zeros. Chained assignments introduce a narrowing
|
||||
instruction; comma, signed-word and explicit byte casts fail to remove it.
|
||||
`memset` and `__builtin_memset` emit a call. A compound-literal aggregate emits
|
||||
copies and enlarges the frame. All are rejected. No allocator tie-break is
|
||||
claimed for this structural difference.
|
||||
|
||||
Three 1200-second searches, seeds 5301-5303, were started from the private
|
||||
99.70105% candidate under the shared 24-slot limiter. They have not yet
|
||||
acquired slots. A late array declaration without a new block does not compile
|
||||
under the current C mode; it is not a valid source attempt.
|
||||
|
||||
After the capacity interruption, fresh status and ctxdiff confirm the source
|
||||
still held the original baseline. Only the proven filter change is now applied;
|
||||
the candidates function is unchanged pending an exact result.
|
||||
|
||||
## Filter acceptance and commit
|
||||
|
||||
The fresh non-quick gate passes: full build OK, retail DOL SHA1, pool
|
||||
identical, 6/7 instruction-exact functions, 2524/5200 matched code,
|
||||
180/180 data. Regressions, forbidden additions and readability warnings
|
||||
are all zero. `Zi8GetKOcandidates` remains unchanged at 98.998505%.
|
||||
Gate evidence: `/tmp/rx53/filter-full-gate.log`.
|
||||
|
||||
## Exact candidate result
|
||||
|
||||
The five-byte key initializer belongs to a real array. Keeping the search
|
||||
aggregate while moving that array into a nested block gives 99.75187% with
|
||||
correct instructions but wrong stack offsets. Flattening the aggregate into
|
||||
ordinary locals gives 99.78924% and puts the array at target stack offset
|
||||
0x38. Reversing those declarations restores every scalar slot and reaches
|
||||
100%, 669/669 instructions, zero ctxdiff differences. The final source removes
|
||||
the search aggregate and packed-word union entirely. No new carrier remains.
|
||||
|
||||
The new block permits the array initializer after the two preceding stores
|
||||
under this C compiler. It lasts through all uses of the buffer. Splitting the
|
||||
word counter zeros preserves the original remainingLetters-then-wordIndex
|
||||
store order. The only addresses that escape are the same independent count,
|
||||
remaining and inserted locals passed to the existing helpers. Those helpers
|
||||
access each pointed-to value independently; no source assumes member adjacency.
|
||||
|
||||
Final mwdbg initial PCode uses v34 for both packedKeys stores, v35 for
|
||||
remainingLetters, and v36 for wordIndex. The 213-entry coloring priority and
|
||||
all fourteen accepted GPR coalesces match the byte-field candidate. Saved
|
||||
assignments remain param/options/wordNode/keyTable/work = r31/r30/r29/r28/r27,
|
||||
with weights 110/40/27/21/14. All remaining named locals stay on the stack.
|
||||
This final change fixes initialization and stack placement without changing
|
||||
the already-correct address-expression allocation.
|
||||
|
||||
The exact candidate capture equals an independent wibo build byte for byte.
|
||||
Validation checks 1224 GPR and 182 CR operand rewrites with zero mismatches,
|
||||
plus 1027 machine-register operands across 537 instructions. The filter
|
||||
capture validates 516 machine-register operands across 266 instructions.
|
||||
The first candidate capture uses the port's snapshot mode; a full-event
|
||||
capture is also running to retain simplify and color-mask evidence.
|
||||
|
||||
Stopped the three queued searches once both functions were exact. None had
|
||||
acquired a slot or executed a trial; they contribute no evidence.
|
||||
|
||||
## Trial measurements
|
||||
|
||||
All variants remain under `/tmp/rx53/zkokeyp`. Only the two exact changes
|
||||
are retained. Initializer chain, cast, comma, memcpy-style and wrapper
|
||||
controls failed the required instruction or stack layout. Reversed scalar
|
||||
declarations plus the ordinary scoped array are the successful source.
|
||||
|
||||
| Trial | Function score | Instructions | Matched data |
|
||||
| --- | ---: | ---: | ---: |
|
||||
| filter-byte-field | 100.0 | 343/343 | 180/180 |
|
||||
| filter-byte-size | 100.0 | 343/343 | 180/180 |
|
||||
| filter-byte-index | 100.0 | 343/343 | 180/180 |
|
||||
| ko-byte-fields | 99.70105 | 669/669 | 180/180 |
|
||||
| ko-byte-fields-split | 98.28849 | 671/669 | 96/180 |
|
||||
| ko-init-compound | 97.98954 | 671/669 | 96/180 |
|
||||
| ko-init-chain-word | 98.28849 | 671/669 | 96/180 |
|
||||
| ko-init-memset | 99.14051 | 670/669 | 96/180 |
|
||||
| ko-init-builtin | 99.14051 | 670/669 | 96/180 |
|
||||
| ko-init-reuse-word | 98.18385 | 672/669 | 96/180 |
|
||||
| ko-init-comma | 97.890884 | 672/669 | 96/180 |
|
||||
| ko-init-chain-byte-cast | 98.28849 | 671/669 | 96/180 |
|
||||
| ko-init-chain-signed | 98.28849 | 671/669 | 96/180 |
|
||||
| ko-init-literal | 97.02242 | 678/669 | 96/180 |
|
||||
| ko-init-assign-list | compile failure | - | - |
|
||||
| ko-init-separate-array | compile failure | - | - |
|
||||
| ko-init-scoped-array | 99.75187 | 669/669 | 180/180 |
|
||||
| ko-init-scoped-array-explicit | 99.75187 | 669/669 | 180/180 |
|
||||
| ko-init-scoped-union | 99.66367 | 669/669 | 180/180 |
|
||||
| ko-init-scoped-struct | 99.75187 | 669/669 | 180/180 |
|
||||
| ko-flat-original | 99.78924 | 669/669 | 180/180 |
|
||||
| ko-flat-reversed | 100.0 | 669/669 | 180/180 |
|
||||
| final-readable | 100.0 | 669/669 | 180/180 |
|
||||
|
||||
## Linking and full gate
|
||||
|
||||
The unit is now Matching in configure.py. All seven text symbols match name,
|
||||
offset and size. symorder.py reports only compiler-generated name differences
|
||||
for the jump table and extab/extabindex labels. A complete comparison of all
|
||||
22 defined symbols confirms identical section order, offsets and sizes;
|
||||
there are no .sbss or .bss symbols to reorder.
|
||||
|
||||
The non-quick gate passes after the Matching flip. Code 5200/5200, data
|
||||
180/180, functions 7/7, linked code 5200. Regressions, forbidden additions and
|
||||
readability warnings are zero. The regenerated canonical report confirms
|
||||
complete code 5200/5200 and complete data 180/180. Pool identical; both
|
||||
requested ctxdiff checks report zero differences. Full build and
|
||||
`ninja -C . progress build/43U/report.json build/43U/ok` pass.
|
||||
|
||||
`doldiff.py` reports 0 differing bytes, both files 3867904 bytes. DOL SHA1
|
||||
is 26116613f624061ba99c8d1a299aaa6efa85670d. Gate output is
|
||||
`/tmp/rx53/final-full-gate.log`; the focused report is
|
||||
`/tmp/rx53/final-report.json`. The first exact gain is committed as 52030c54.
|
||||
|
||||
## Full allocator trace and final verification
|
||||
|
||||
The full-event candidate capture completed and independently validated.
|
||||
Both register classes pass reversed-simplify priority and assignment-event
|
||||
checks. For the first child address, v63-v68 simplify in ascending order
|
||||
with remaining degrees 6, 6, 5, 5, 6, 21 against 24 available registers.
|
||||
They color in reverse. v68 sees legal mask 0x1fc0 and selects target r6;
|
||||
v67 sees 0x1ff8 and selects r3; v66 and v65 see 0x1ff9 and select r0;
|
||||
v64 sees 0x1ff8 and selects r3; v63 sees 0x1ff1 and selects r0. None of
|
||||
these values coalesces. The complete pass retains fourteen accepted moves
|
||||
and 52 interference rejections, with no spill. Capture and validator output
|
||||
are under `/tmp/rx53/candidates-exact-full`.
|
||||
|
||||
After whitespace cleanup, the final worktree object equals the independently
|
||||
validated exact candidate snapshot byte for byte. The fresh non-quick gate,
|
||||
canonical progress report, both zero-diff ctxdiff checks, and zero-byte DOL
|
||||
diff pass again. The retained source changes are confined to the two assigned
|
||||
functions; configure.py changes only the authorized zkokeyp Matching flag.
|
||||
All other eZiText source files and the inherited rx4 artifacts are untouched.
|
||||
Reference in New Issue
Block a user