Compare commits

...

4 Commits

Author SHA1 Message Date
Devin AI
65e8afde6f zi8uwd: fix priority sort polarity (candidate->priority > word->priority)
Orig emits bgt after cmplw candidate.prio,word.prio — the priority-sorted
insert stops at the first candidate with HIGHER priority (descending list),
not lower. Zi8_81480224 9 -> 8 diffs (all remaining count-equal r26/r28
web-homing swaps). Also documents constant-pooling + temp-numbering walls
found across zkokeyp/kbd_lib/zi81key probes.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 23:21:32 +00:00
Devin AI
04444a26ff zprepare: decode write-only componentFlag byte (slot 0xf, decl-order frame layout); kbd_lib: document select/IV walls
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 23:11:23 +00:00
Devin AI
26996c811b kbd_lib: decode cmdbuf scan loop + u32 index in SetLeds fns
Orig scans kbdCmdBuf via base+byteOfs indexed lwzx/stwx; the
index*sizeof access with an ofs header tracker reproduces it exactly
in KBDSetLedsAsync. u32 index yields orig's cmplwi post-loop check.
Remaining diffs: channel-park vs product-remat allocator wall
(documented in kbd_lib.attempts.md).

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 22:40:56 +00:00
Devin AI
cfee2beee7 zi8alpha: add savedWork backup-pointer local (orig stores workData to frame 0x20)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 22:03:13 +00:00
7 changed files with 92 additions and 13 deletions

View File

@@ -368,6 +368,7 @@ int Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr optionData, ziPtr workDa
ziU16 normalizedElements[64];
unsigned int dictionaryStatus[14];
ziU8 candidateBytes[64];
ZiAlphaWork *savedWork;
prefixMode = 0;
prefixTableFlags = 0;
@@ -406,6 +407,7 @@ int Zi8AlphaGetCandidates(ziGetParam* parameters, ziPtr optionData, ziPtr workDa
contextEnabled = 0;
keyLayoutCount = 0;
keyLayout = 0;
savedWork = (ZiAlphaWork*)workData;
phoneticInput = 0;
phoneticSeparator = 0;
if ((((((language == 0x7c) || (language == 0x7d)) || (language == 0x7b)) ||

View File

@@ -41,7 +41,7 @@ ziBool Zi8_81480224(ziUserWord* word ZI_NEED_WORK) {
current = ZI_WORK->uwdList;
while (current != 0) {
candidate = (ziUserWord*)current->word;
if (ZI_WORK->uwdPrioritySort == 1 && candidate->priority < word->priority) break;
if (ZI_WORK->uwdPrioritySort == 1 && candidate->priority > word->priority) break;
if (candidate->length == length) {
position = 0;
while (position < length) {

View File

@@ -21,6 +21,7 @@ ziBool Zi8PrepareMatch(ziGetParam* request, ziMatchParam* match, ziU8 skipMode Z
ziWChar bestFinal;
ziWChar previousInitial;
ziWChar previousFinal;
ziU8 componentFlag;
ziU8 elementCount;
ziU8 elementIndex;
ziU8 stroke;
@@ -43,6 +44,7 @@ ziBool Zi8PrepareMatch(ziGetParam* request, ziMatchParam* match, ziU8 skipMode Z
stroke = 0;
contextMask = 0x20;
Zi8Memset(match,0,0x1ee);
componentFlag = 0;
nibbles = 0;
elementIndex = 0;
elementCount = request->elementCount;
@@ -61,6 +63,7 @@ ziBool Zi8PrepareMatch(ziGetParam* request, ziMatchParam* match, ziU8 skipMode Z
match->comp = element = request->elements[0];
if (Zi8IsComponent(element,__zi8_work_data) != 0) {
elementIndex++;
componentFlag = 1;
buffers.component = (ziU8*)Zi8GetTableAddress(1,2,__zi8_work_data);
buffers.componentIndex = (ziU8*)Zi8GetTableAddress(1,6,__zi8_work_data);
buffers.componentIndex += (element - 0xef10) * 2;

View File

@@ -583,9 +583,9 @@ static void kbd_led_handler(BOOL success, void* callbackArg) {
}
USBKBDErr KBDSetLedsAsync(u32 channel, u32 leds, USBKBDCmdLEDCallback callback, void* callbackArg) {
s32 index;
u32 ofs;
u8 ledBits;
u32 index;
u32 ofs;
BOOL interrupts;
USBKBDErr result;
if (!kbdInitialized) {
@@ -600,8 +600,8 @@ USBKBDErr KBDSetLedsAsync(u32 channel, u32 leds, USBKBDCmdLEDCallback callback,
ledBits = leds;
interrupts = OSDisableInterrupts();
for (index = 0, ofs = 0; index < 12; index++, ofs += sizeof(KBDLEDCommand)) {
if (*(u32*)&((u8*)kbdCmdBuf)[ofs] == 0) {
*(u32*)&((u8*)kbdCmdBuf)[ofs] = (u32)kbdData[channel].device;
if (*(u32*)&((u8*)kbdCmdBuf)[index * sizeof(KBDLEDCommand)] == 0) {
*(u32*)&((u8*)kbdCmdBuf)[index * sizeof(KBDLEDCommand)] = (u32)kbdData[channel].device;
break;
}
}
@@ -624,7 +624,6 @@ USBKBDErr KBDSetLedsAsync(u32 channel, u32 leds, USBKBDCmdLEDCallback callback,
USBKBDErr KBDSetLeds(u32 channel, u32 leds) {
u32 index;
KBDLEDCommand* command;
BOOL interrupts;
USBKBDErr result;
u8 ledBits;
@@ -639,15 +638,11 @@ USBKBDErr KBDSetLeds(u32 channel, u32 leds) {
}
ledBits = leds & 0xff;
interrupts = OSDisableInterrupts();
index = 0;
command = kbdCmdBuf;
while (index < 12) {
if (command->device == 0) {
command->device = (u32)kbdData[channel].device;
for (index = 0; index < 12; index++) {
if (*(u32*)&((u8*)kbdCmdBuf)[index * sizeof(KBDLEDCommand)] == 0) {
*(u32*)&((u8*)kbdCmdBuf)[index * sizeof(KBDLEDCommand)] = (u32)kbdData[channel].device;
break;
}
index++;
command++;
}
OSRestoreInterrupts(interrupts);
if (index == 12) {

View File

@@ -50,3 +50,18 @@
Old leaf tip f2afe0e8 beat upstream on: zoemdata +34.2, ziswordw +10.5,
zi8uwd +7.3, zidawg1 +1.7, zi8pud2 +0.7, zi81key/zmtkey marginal.
Upstream won on: zi8alpha +4.5, zi8cgetc +16, zconvert +0.4, zkokeyp +0.1.
## zi81key Get1KeyPressCandidates mr+clrlwi staging wall (~10 forms)
Base pattern at each `Zi8IsMatch1Key(...,Zi8GetPCode(pt,ph),...)` site:
`bl GetPCode; mr r5,r3; <arg1/arg2 setup>; clrlwi r5,r5,0x10; bl` — call result
parked RAW in the arg3 reg, narrowed at the marshal slot. Mine fuses:
`clrlwi r5,r3,0x10` at call exit. Tried: `(ziU16)` cast (folds), `& 0xffff` mask
(folds into same fused clrlwi), u32/s32 extern decl + mask (still fused),
`Zi8UInt/ziU16/int/register pcode` inner-scope local (all SPILL to stack —
named locals never stay in volatile arg regs in this fn), `(ziU16)(ziU32)` cast
chain (folds), ziU16 param on IsMatch1Key (breaks callee: +3 insns inside).
The stage-vs-fuse choice is MWCC's arg-scheduling: it narrows at call-exit when
r3 is dead, at marshal-slot only when the raw web escapes — and no reachable
source form makes the u16 result web escape. Same wall family as zi8cgetc's
22 "return-value move displacement" diffs. UNSOLVED.

View File

@@ -227,3 +227,60 @@ KBDResetChannel remains objdiff 100% with identical raw instruction bytes. Its g
no relocs, no .text reads. Blind `=0` static is banned filler. Leftover.
- kbdEventHandler/KBDSetModState/KBDTranslateHidCode: insn-count-equal
residual regname/sched swaps; probed variants regressed.
## kbd_led_handler select-vs-branch wall (~20 forms)
Orig tail: `cmpwi r3,1; bne->0xcd8(li r3,7); li r3,0; b join; li7; join` — the
standard `if(c)err=0 else err=7` if-lowering with both constants materialized in
their own incoming blocks. MWCC if-converts EVERY leaf-const diamond into the
branchless select (addi/subfic/nor|or/srawi/andc+clrlwi ~6 insns) regardless of
source form: if/else both polarities, ?:, both-goto diamond, early-init+single-
arm (7 or 0 — the shared value remats in the dominator, not a branch block),
3-def web (init+else re-def), switch (emits beq->case+b->default trampoline, not
bne->default), param reassign (success=0/7), calls-in-arms (no tail merge),
u8 err. Decoded real wins kept: `callback` local removed (kbdLCBuf[index] direct
indexing produces orig's lwzx r12 cbAddress), still selects. Remaining fuzzy
delta = the ~2-insn select-vs-branch shape + arg reg r3-vs-r0. UNSOLVED.
## KBDSetLedsAsync/KBDSetLeds loop decode (partial win)
Orig's cmdbuf scan loop uses `base + byteOfs` indexed lwzx/stwx
(`lwzx r0,r6,r4` / `stwx r0,r6,r4`, r6=&kbdCmdBuf const, r4=ofs +=0x20),
NOT a walked pointer. Reproduced EXACTLY in KBDSetLedsAsync via
`*(u32*)&((u8*)kbdCmdBuf)[index * sizeof(KBDLEDCommand)]` with
`for (index = 0, ofs = 0; index < 12; index++, ofs += sizeof(...))` —
the unused-in-body `ofs` header tracker steers MWCC's IV choice.
In KBDSetLeds the same source gives ptr-walk + slwi-at-store instead
(different reg pressure / no r31 data-base pooling) — near-equal 78v79.
`u32 index` (not s32) produces orig's `cmplwi` post-loop check.
## channel-keep-vs-product-remat wall (both SetLeds fns)
Orig parks `channel` (mr r31/r26,r3) and REMATERIALIZES `channel*0x268`
at every `kbdData[channel]` site (flags check → temp mulli r0/r3,
found-branch → mulli r5,r26, call-arg → mulli r3,r26). Mine CSEs the
product into one callee web (mulli r30,r3 keep). Tried: kbdChannelFlags
inline vs direct .flags reads, flags local, data=&kbdData[channel]
local (keeps PTR — worse), byte-view u32 access (normalizes & CSEs
identically), decl reorder — all keep-product. The remat choice is
MWCC's x*K-address rematerialization heuristic; the product web spans
two calls so cost is identical — allocator tie. UNSOLVED, ~2 insns.
## Session w1009-b: kbd_led_handler select + IV walls, zprepare flag decode
- kbd_led_handler (25-insn fn): decoded to 24v25. Base = `kbdCmdBuf[index].device = 0` unconditional
store + `kbdLCBuf[index].callbackAddress == 0` early-ret + `cmpwi r3,1; bne -> li7-far; li0-inline`
err select + `bctr` tail-call. The `if (success==TRUE) err=0 else err=7` if/else + ternary + goto
+ switch forms all give either branchless select (subfic/nor/srawi/andc) or `beq -> li0` (wrong
polarity). Two-calls form gives the right `bne -> else` layout but MWCC won't tail-merge the calls
(emits 2 bctr). Base also remats `index*8` + reloads callbackAddress after the select (vs cached).
UNSOLVED: MWCC select-vs-branch heuristic — same family as the beq+b wall.
- kbdCmdBuf scan loops (KBDSetLeds + KBDSetLedsAsync): base uses byte-IV `li r4,0`/`addi r4,0x20` +
`lwzx r0,r6,r4`/`stwx` where r6 = invariant &kbdCmdBuf. ~14 source forms tried incl. micro-tests:
ptr-walk always wins for the read side (`lwz 0(r4)` + separate ofs IV for the stwx write). MWCC
strength-reduction always introduces a secondary walked pointer for the load. UNSOLVED.
- Zi8PrepareMatch: DECODED a write-only flag byte at r1+0xf — init `componentFlag = 0` after
Zi8Memset, set `componentFlag = 1` inside the `if (Zi8IsComponent(element))` block after
elementIndex++. MWCC lays u8 stack slots in REVERSE declaration order — declaring it before
elementCount lands it at 0xf exactly. Both stores byte-match; fn 939->943 vs base 940 (+3 sched).
- Reg-rotation wall (whole clib pool): single-web-pair swap r27/r28, r30/r31 etc. Tried: decl order,
decl-init, register keyword (no-op), type width (u8/u32/u16), first-use reorder. MWCC web
numbering order is internal — not reachable from source. ~10 fns gated on this.

View File

@@ -0,0 +1,7 @@
## Session w1009-c (Zi8_81480224)
- `priority` compare polarity decode: orig emits `cmplw r3=candidate.prio, r0=word.prio; bgt` — source is `candidate->priority > word->priority` (descending insert), not `<` (fixed, -1 diff).
- Residual: 8 count-equal r26<->r28 web swaps (word param vs candidate ptr). Levers tried and dead: decl-order swap of candidate/added (neutral), candidate inline into conditions (120v116 regression, savegpr_22), loop-scoped `ziUserWord* w = word` copy (regression, extra web), statement reorder (neutral). Same MWCC web-numbering wall as the rest of the clib pool.
- KBDSetModState tail: `add/lwz/rlwimi/stw` temp-pair swap (r4 vs r5) — named `KBDChannel* data` local regressed 164v168; reverted. kbdEventHandler 5-diff lis/lbz temp ordering — `data = &kbdData[channel]` single-expr and status-before-data reorder both neutral-ish (6 diffs), reverted.
- Zi8_814834AC (zkokeyp): base shares ONE `li 0` web across `stw firstWord + stb bytes[4]` inits; every source form either emits two `li`s (separate stmts, comma-expr, reversed order) or adds a `clrlwi` conversion mask (chained `a = b = 0` both directions, u8 temp, u32 temp `j`). Constant-pooling granularity wall — kept chained form (344v343, -1 clrlwi).
- Zi8AlphaGetCandidates: all calls align; the -1 insn is a frame slot-order swap (a `= 0` int local claims the top slot in mine vs a param park in base — same slot set, same frame size). ~150 reg/sched ties otherwise.