Compare commits

...

15 Commits

Author SHA1 Message Date
Devin AI
548fdd78bf exif_parse: u32 type hoists mask, merged return-group, 0x201/0x202+default fold (IFD0 94.91/IFD1 98.76, 482=482 insns)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:05 +00:00
Devin AI
bdafc5eafa jpeg: name Y8U8V8 converter fns to decoded names (pair with symbols.txt renames)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:05 +00:00
Devin AI
0aa7ebc82d jpeg: adopt upstream cvtr/idct/iqdec/exif versions (swarm equivalent-or-better)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:05 +00:00
Devin AI
17dde877a2 decomp-assist: MWCC unroll dual-path + remat findings
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:05 +00:00
Devin AI
47e1871309 Y8U8V8: inline luma/chroma row-setup — match orig per-path recompute (gap 126->70)
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:04 +00:00
Devin AI
10b5024b83 Y8U8V8: inline chroma row-setup kills MWCC hoist-vs-recompute split
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:04 +00:00
Devin AI
ab38b6b89a Y8U8V8: u32 store-index kills MWCC signed-overflow flag-chains
's32 off' made MWCC emit lis -0x8000/li-flag overflow guards around the
<<5 index; u32 off drops them (YUV400 147->158 vs orig 162).

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:04 +00:00
Devin AI
5b8103330b decomp-assist: MWCC if-else/switch/unroll emission findings
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:04 +00:00
Devin AI
242028ae91 idct_block_var: single for-loop triggers MWCC's native x2 unroll
for(;iter>0;iter--) under if(iter>0) gives orig's rlwinm./mtctr/bdnz
unroll emission (andi.+mtctr remainder) instead of hand-written
pairs+do-while tail. 454 = 454 size-exact; residual is fused
rlwinm. guard vs cmpwi+srwi and regalloc.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:04 +00:00
Devin AI
3d68725e64 exif_parse: IFD1 case-source-order matches orig body emission — fuzzy 95.9
Body-cases ordered {11a,11b,128,103,201,202} per orig's emission order;
dispatch tree is node-identical except {103} below-edge bltlr vs blr.
Residual +6 insns: MWCC emits dead blr bodies for the 7 'case X: return;'
arms; orig folds them into beqlr leaves with no bodies.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:04 +00:00
Devin AI
9e11a96eb1 idct_block_var: both fns size-exact — MWCC self-unrolled single-block loop + do-while tail + u32 iter shifts
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:04 +00:00
Devin AI
fecf686ab3 exif: IFD1 switch tree decode — 12-node model, folded dead cases
Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:04 +00:00
Devin AI
39582f4410 TMC_JPEG: idct_block_var structure fixes + Y8U8V8 444 unroll match
- IdctBlock_Lumi: all-8 dst stores in row-IDCT else (w+n/v+o/w-n triplet),
  +0x40000 rounding bias in column loop, ternary scalingClampU8 ->
  exact size 1028 (bd 618 regalloc only)
- IdctBlock_Col: b0-homing removes block[0] reloads, iter&1 tail as
  if-statement, same store triplet -> 1808 vs orig 1816
- Y8U8V8 444/444e: != loop bound defeats MWCC provable-bound x8 unroll,
  yields orig x2 mtctr form at exact sizes 396/448

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:04 +00:00
Devin AI
9d0eb3bd19 TMC_JPEG: keep better-matching cvtr/idct/iqdec implementations over upstream merges
- texturecvtr x3: my converters beat upstream's at every size (RGB565/RGBA8
  exact at all sizes vs upstream +8/+12 edge sizes; Y8U8V8 structurally closer)
- exif_parse: upstream's switch dispatch kept (matches orig structure)
- iqdec_b65: volatile removed; bd 438 at exact size 1104 (upstream bd 759)
- documented: MWCC switch-tree emits label+1 range edges (0x11c/0xa004/0x213
  in orig IFD1 are edges, not case labels)

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:51:04 +00:00
Devin AI
414af7fa1d TMC_JPEG: decompile Texture_MCUtoRGB565 + Texture_MCUtoY8U8V8 converters
RGB565: all 12 converters at exact instruction counts (set_converter 169/170
with a convBuf-base fusion residual). Y8U8V8: complete two-loop luma/chroma
structure decoded and rewritten (main +=K loops, edge x_pos++ loops,
per-family subsample steps); all fns within ~4% insn counts except 444/444e
(MWCC picks unroll x8 vs orig x2 - unroll-factor tie-break). Renamed Y8U8V8
converter symbols in symbols.txt.

Co-Authored-By: wch <usernamecole7@gmail.com>
2026-10-02 17:50:53 +00:00
5 changed files with 217 additions and 96 deletions

View File

@@ -8932,18 +8932,18 @@ TMCJPEGDEC_IdctBlock4x4_Col = .text:0x814EF810; // type:function size:0x224
TMCJPEGDEC_IdctBlock2x2_Col = .text:0x814EFA34; // type:function size:0x124
TMCJPEGDEC_IdctBlock1x1_Col = .text:0x814EFB58; // type:function size:0x44
TMCJPEGDEC_set_converterY8U8V8 = .text:0x814EFB9C; // type:function size:0x310
TMCJPEG_814EFEAC = .text:0x814EFEAC; // type:function size:0x590 scope:local
TMCJPEG_814F043C = .text:0x814F043C; // type:function size:0x61C scope:local
TMCJPEG_814F0A58 = .text:0x814F0A58; // type:function size:0x76C scope:local
TMCJPEG_814F11C4 = .text:0x814F11C4; // type:function size:0x61C scope:local
TMCJPEG_814F17E0 = .text:0x814F17E0; // type:function size:0x768 scope:local
TMCJPEG_814F1F48 = .text:0x814F1F48; // type:function size:0x628 scope:local
TMCJPEG_814F2570 = .text:0x814F2570; // type:function size:0x5E0 scope:local
TMCJPEG_814F2B50 = .text:0x814F2B50; // type:function size:0x608 scope:local
TMCJPEG_814F3158 = .text:0x814F3158; // type:function size:0x18C scope:local
TMCJPEG_814F32E4 = .text:0x814F32E4; // type:function size:0x1C0 scope:local
TMCJPEG_814F34A4 = .text:0x814F34A4; // type:function size:0x288 scope:local
TMCJPEG_814F372C = .text:0x814F372C; // type:function size:0x2BC scope:local
TMCJPEGDEC_converterYUV411toY8U8V8 = .text:0x814EFEAC; // type:function size:0x590 scope:local
TMCJPEGDEC_converterYUV411toY8U8V8edge = .text:0x814F043C; // type:function size:0x61C scope:local
TMCJPEGDEC_converterYUV422toY8U8V8 = .text:0x814F0A58; // type:function size:0x76C scope:local
TMCJPEGDEC_converterYUV422toY8U8V8edge = .text:0x814F11C4; // type:function size:0x61C scope:local
TMCJPEGDEC_converterYUV420toY8U8V8 = .text:0x814F17E0; // type:function size:0x768 scope:local
TMCJPEGDEC_converterYUV420toY8U8V8edge = .text:0x814F1F48; // type:function size:0x628 scope:local
TMCJPEGDEC_converterYUV211toY8U8V8 = .text:0x814F2570; // type:function size:0x5E0 scope:local
TMCJPEGDEC_converterYUV211toY8U8V8edge = .text:0x814F2B50; // type:function size:0x608 scope:local
TMCJPEGDEC_converterYUV444toY8U8V8 = .text:0x814F3158; // type:function size:0x18C scope:local
TMCJPEGDEC_converterYUV444toY8U8V8edge = .text:0x814F32E4; // type:function size:0x1C0 scope:local
TMCJPEGDEC_converterYUV400toY8U8V8 = .text:0x814F34A4; // type:function size:0x288 scope:local
TMCJPEGDEC_converterYUV400toY8U8V8edge = .text:0x814F372C; // type:function size:0x2BC scope:local
TMCJPEGDEC_set_converterRGB565 = .text:0x814F39E8; // type:function size:0x2A8
TMCJPEGDEC_converterYUV411toRGB565 = .text:0x814F3C90; // type:function size:0x364 scope:local
TMCJPEGDEC_converterYUV411toRGB565edge = .text:0x814F3FF4; // type:function size:0x1A8 scope:local

View File

@@ -10,12 +10,14 @@ static TMCHuffmanEntry readHuffmanEntry(const TMCHuffmanEntry* entries, u32 inde
return entries[index];
}
static void readHuffmanLimit(const TMCHuffmanEntry* entries, TMCHuffmanEntry* limit) {
limit->bitLength = entries->bitLength;
limit->symbol = entries->symbol;
static TMCHuffmanEntry readHuffmanLimit(const TMCHuffmanEntry* entries) {
TMCHuffmanEntry limit;
limit.bitLength = entries->bitLength;
limit.symbol = entries->symbol;
return limit;
}
static inline s32 decodeLongHuffman(s32 bitCount, const TMCHuffmanEntry* table, const u8* symbols, TMCCJPEGDecWork* work, TMCHuffmanEntry* limit, TMCHuffmanEntry* decoded) {
static inline s32 decodeLongHuffman(s32 bitCount, const TMCHuffmanEntry* table, const u8* symbols, TMCCJPEGDecWork* work) {
u32 bitData;
u32 code;
u32 length;
@@ -49,21 +51,17 @@ static inline s32 decodeLongHuffman(s32 bitCount, const TMCHuffmanEntry* table,
code |= (bitData >> bitCount) & 1;
read_entry:
{
readHuffmanLimit(entry, limit);
*decoded = *limit;
if (code > (u32)decoded->bitLength) {
TMCHuffmanEntry decoded = readHuffmanLimit(entry);
if (code > (u32)decoded.bitLength) {
continue;
}
{
u32 relativeCode = code - entry->bitLength;
u32 symbolIndex = relativeCode + entry->symbol;
return symbols[symbolIndex & 0xFF];
}
code = code - entry->bitLength + entry->symbol;
return symbols[code & 0xFF];
}
}
}
static inline s32 decodeACHuffman(s32 bitCount, const TMCHuffmanEntry* entry, const u8* symbols, TMCCJPEGDecWork* work, TMCHuffmanEntry* limit, TMCHuffmanEntry* decoded) {
static inline s32 decodeACHuffman(s32 bitCount, const TMCHuffmanEntry* entry, const u8* symbols, TMCCJPEGDecWork* work) {
u32 bitData;
u32 code;
u32 length;
@@ -96,26 +94,18 @@ static inline s32 decodeACHuffman(s32 bitCount, const TMCHuffmanEntry* entry, co
code |= (bitData >> bitCount) & 1;
read_entry:
{
readHuffmanLimit(entry, limit);
*decoded = *limit;
if (code > (u32)decoded->bitLength) {
TMCHuffmanEntry decoded = readHuffmanLimit(entry);
if (code > (u32)decoded.bitLength) {
continue;
}
{
u32 relativeCode = code - entry->bitLength;
u32 symbolIndex = relativeCode + entry->symbol;
return symbols[symbolIndex & 0xFF];
}
code = code - entry->bitLength + entry->symbol;
return symbols[code & 0xFF];
}
}
}
s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_ptr, TMCCJPEGDecWork* work) {
TMCHuffmanEntry dcEntry;
TMCHuffmanEntry dcDecoded;
TMCHuffmanEntry dcLimit;
TMCHuffmanEntry acDecoded;
TMCHuffmanEntry acLimit;
u8* huff_sym;
const TMCHuffmanEntry* ac_fast;
s32 idx;
@@ -157,7 +147,7 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p
} else {
huff_sym = work->pDCHuffSym;
huff_tbl = work->pDCHuffTbl;
r = decodeLongHuffman(bit_pos, (const TMCHuffmanEntry*)huff_tbl, huff_sym, work, &dcLimit, &dcDecoded);
r = decodeLongHuffman(bit_pos, (const TMCHuffmanEntry*)huff_tbl, huff_sym, work);
if (r < 0) {
return r;
}
@@ -217,7 +207,7 @@ s32 TMCJPEGDEC_decode_iquant(s32* block, u8* conv_row_ptr, u32* dc_predict_row_p
r = acEntry.symbol;
} else {
bit_pos = work->bitCount;
r = decodeACHuffman(bit_pos, (const TMCHuffmanEntry*)huff_tbl, huff_sym, work, &acLimit, &acDecoded);
r = decodeACHuffman(bit_pos, (const TMCHuffmanEntry*)huff_tbl, huff_sym, work);
if (r < 0) {
return r;
}

View File

@@ -340,17 +340,15 @@ static s32 TMCJPEGDEC_exif_parse(const u8* data, u32 size, TMCCJPEGDecExifData*
static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder, const u8* entry) {
s32 tag;
u16 type;
u32 type;
tag = readU16(entry, byteOrder);
type = readU16(entry + 2, byteOrder);
switch (tag) {
case 0x0103:
case 0x0111:
case 0x0201:
case 0x0202: {
break;
case 0x0111: {
return;
}
case 0x0112: {
pInfo->orientation = readU16(entry + 8, byteOrder);
@@ -486,6 +484,11 @@ static void TMCJPEGDEC_IFD0_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
}
return;
}
case 0x0201:
case 0x0202:
default: {
break;
}
}
}
@@ -493,17 +496,12 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
s32 tag = readU16(entry, byteOrder);
switch (tag) {
case 0x0132:
case 0x0111:
case 0x0112:
case 0x012D:
case 0x0213:
case 0x8769:
case 0x9000:
case 0x9101:
case 0xA003: {
case 0x0102: {
break;
}
case 0x0111: {
return;
}
case 0x011A: {
u32 offset;
const u8* p;
@@ -548,10 +546,19 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
pInfo->yResDenIfd1 = readU32(p, byteOrder);
return;
}
case 0x0112: {
break;
}
case 0x0128: {
pInfo->resUnitIfd1 = readU16(entry + 8, byteOrder);
return;
}
case 0x012D: {
break;
}
case 0x0132: {
break;
}
case 0x0103: {
pInfo->compressionIfd1 = readU16(entry + 8, byteOrder);
return;
@@ -564,6 +571,24 @@ static void TMCJPEGDEC_IFD1_tag_parse(TMCCJPEGDecExifData* pInfo, u16 byteOrder,
pInfo->thumbnailLength = readU32(entry + 8, byteOrder);
return;
}
case 0x0213: {
break;
}
case 0x8769: {
break;
}
case 0x9000: {
break;
}
case 0x9101: {
break;
}
case 0xA003: {
break;
}
default: {
break;
}
}
}

View File

@@ -1,18 +1,18 @@
#define TMC_JPEG_PLANAR_OUTPUT
#include <tmc_jpeg_internal.h>
static void TMCJPEG_814EFEAC(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEG_814F043C(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEG_814F0A58(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEG_814F11C4(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEG_814F17E0(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEG_814F1F48(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEG_814F2570(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEG_814F2B50(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEG_814F3158(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEG_814F32E4(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEG_814F34A4(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEG_814F372C(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV411toY8U8V8(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV411toY8U8V8edge(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV422toY8U8V8(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV422toY8U8V8edge(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV420toY8U8V8(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV420toY8U8V8edge(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV211toY8U8V8(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV211toY8U8V8edge(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV444toY8U8V8(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV444toY8U8V8edge(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV400toY8U8V8(TMCCJPEGDecWork*, s32, s32);
static void TMCJPEGDEC_converterYUV400toY8U8V8edge(TMCCJPEGDecWork*, s32, s32);
s32 TMCJPEGDEC_set_converterY8U8V8(TMCCJPEGDecWork* work) {
u8* buffer;
@@ -35,8 +35,8 @@ s32 TMCJPEGDEC_set_converterY8U8V8(TMCCJPEGDecWork* work) {
mode = work->idctMode;
firstRow = buffer + 4;
work->pConverterFunc = TMCJPEG_814EFEAC;
work->pConverterFuncEdge = TMCJPEG_814F043C;
work->pConverterFunc = TMCJPEGDEC_converterYUV411toY8U8V8;
work->pConverterFuncEdge = TMCJPEGDEC_converterYUV411toY8U8V8edge;
secondRow = firstRow + mode;
thirdRow = secondRow + mode;
fourthRow = thirdRow + mode;
@@ -61,8 +61,8 @@ s32 TMCJPEGDEC_set_converterY8U8V8(TMCCJPEGDecWork* work) {
mode = work->idctMode;
firstRow = buffer + 4;
work->pConverterFunc = TMCJPEG_814F0A58;
work->pConverterFuncEdge = TMCJPEG_814F11C4;
work->pConverterFunc = TMCJPEGDEC_converterYUV422toY8U8V8;
work->pConverterFuncEdge = TMCJPEGDEC_converterYUV422toY8U8V8edge;
secondRow = firstRow + mode;
cbBlock = buffer + 132;
crBlock = buffer + 196;
@@ -85,8 +85,8 @@ s32 TMCJPEGDEC_set_converterY8U8V8(TMCCJPEGDecWork* work) {
mode = work->idctMode;
firstRow = buffer + 4;
work->pConverterFunc = TMCJPEG_814F17E0;
work->pConverterFuncEdge = TMCJPEG_814F1F48;
work->pConverterFunc = TMCJPEGDEC_converterYUV420toY8U8V8;
work->pConverterFuncEdge = TMCJPEGDEC_converterYUV420toY8U8V8edge;
secondRow = firstRow + mode;
thirdRow = firstRow + mode * 16;
fourthRow = thirdRow + mode;
@@ -111,8 +111,8 @@ s32 TMCJPEGDEC_set_converterY8U8V8(TMCCJPEGDecWork* work) {
mode = work->idctMode;
firstRow = buffer + 4;
work->pConverterFunc = TMCJPEG_814F2570;
work->pConverterFuncEdge = TMCJPEG_814F2B50;
work->pConverterFunc = TMCJPEGDEC_converterYUV211toY8U8V8;
work->pConverterFuncEdge = TMCJPEGDEC_converterYUV211toY8U8V8edge;
secondRow = firstRow + mode * 8;
cbBlock = buffer + 132;
crBlock = buffer + 196;
@@ -127,8 +127,8 @@ s32 TMCJPEGDEC_set_converterY8U8V8(TMCCJPEGDecWork* work) {
case 4: {
TMCConverterFunc* converter;
TMCConverterFunc* edgeConverter;
converter = TMCJPEG_814F3158;
edgeConverter = TMCJPEG_814F32E4;
converter = TMCJPEGDEC_converterYUV444toY8U8V8;
edgeConverter = TMCJPEGDEC_converterYUV444toY8U8V8edge;
work->pConvRowPtrs[0] = buffer + 4;
work->pConvRowPtrs[5] = buffer + 0x44;
work->pConvRowPtrs[6] = buffer + 0x84;
@@ -141,8 +141,8 @@ s32 TMCJPEGDEC_set_converterY8U8V8(TMCCJPEGDecWork* work) {
case 5: {
TMCConverterFunc* converter;
TMCConverterFunc* edgeConverter;
converter = TMCJPEG_814F34A4;
edgeConverter = TMCJPEG_814F372C;
converter = TMCJPEGDEC_converterYUV400toY8U8V8;
edgeConverter = TMCJPEGDEC_converterYUV400toY8U8V8edge;
work->pConvRowPtrs[0] = buffer + 4;
work->pConverterFunc = converter;
work->pConverterFuncEdge = edgeConverter;
@@ -168,7 +168,7 @@ s32 TMCJPEGDEC_set_converterY8U8V8(TMCCJPEGDecWork* work) {
return 0;
}
static void TMCJPEG_814EFEAC(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV411toY8U8V8(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 rowSkip;
u8* output;
u32 tileRow;
@@ -232,7 +232,7 @@ static void TMCJPEG_814EFEAC(TMCCJPEGDecWork* work, s32 x, s32 y) {
}
}
static void TMCJPEG_814F043C(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV411toY8U8V8edge(TMCCJPEGDecWork* work, s32 x, s32 y) {
TMCCJPEGDecState* state;
u8* lumaTexture;
u8* luminance;
@@ -298,12 +298,14 @@ static void TMCJPEG_814F043C(TMCCJPEGDecWork* work, s32 x, s32 y) {
}
}
static void TMCJPEG_814F0A58(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV422toY8U8V8(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 chromaYEnd;
u8* lumaTexture;
u8* luminance;
s32 column;
s32 chromaXEnd;
s32 row;
u32 chromaTileWidth;
TMCCJPEGDecState* state;
s32 width;
s32 height;
@@ -314,6 +316,7 @@ static void TMCJPEG_814F0A58(TMCCJPEGDecWork* work, s32 x, s32 y) {
u8* cb;
u32 tileWidth;
u8* cr;
s32 chromaRowSkip;
row = y;
luminance = work->convBuf + 4;
@@ -338,22 +341,23 @@ static void TMCJPEG_814F0A58(TMCCJPEGDecWork* work, s32 x, s32 y) {
x = (u32)x >> 1;
width = 8 / state->scaleFactor;
height = 8 / state->scaleFactor;
xEnd = x + width;
chromaXEnd = x + width;
chromaYEnd = y + height;
tileWidth = state->chromaWidth >> 3;
for (row = y; row < chromaYEnd; row++) {
for (column = x; column < xEnd; column += 1) {
(cbTexture + ((row & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (row >> 2) * tileWidth) << 5)] = *cb + 128;
chromaTileWidth = state->chromaWidth >> 3;
chromaRowSkip = 8 - width;
for (; y < chromaYEnd; y++) {
for (column = x; column < chromaXEnd; column += 1) {
(cbTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cb + 128;
cb++;
(crTexture + ((row & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (row >> 2) * tileWidth) << 5)] = *cr + 128;
(crTexture + ((y & 3) << 3) + (column & 7))[(s32)(((column >> 3) + (y >> 2) * chromaTileWidth) << 5)] = *cr + 128;
cr++;
}
cb += 8 - width;
cb += chromaRowSkip;
cr += 8 - width;
}
}
static void TMCJPEG_814F11C4(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV422toY8U8V8edge(TMCCJPEGDecWork* work, s32 x, s32 y) {
TMCCJPEGDecState* state;
u8* lumaTexture;
u8* luminance;
@@ -419,7 +423,7 @@ static void TMCJPEG_814F11C4(TMCCJPEGDecWork* work, s32 x, s32 y) {
}
}
static void TMCJPEG_814F17E0(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV420toY8U8V8(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 chromaYEnd;
u8* lumaTexture;
s32 height;
@@ -475,7 +479,7 @@ static void TMCJPEG_814F17E0(TMCCJPEGDecWork* work, s32 x, s32 y) {
}
}
static void TMCJPEG_814F1F48(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV420toY8U8V8edge(TMCCJPEGDecWork* work, s32 x, s32 y) {
TMCCJPEGDecState* state;
u8* lumaTexture;
u8* luminance;
@@ -542,7 +546,7 @@ static void TMCJPEG_814F1F48(TMCCJPEGDecWork* work, s32 x, s32 y) {
}
}
static void TMCJPEG_814F2570(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV211toY8U8V8(TMCCJPEGDecWork* work, s32 x, s32 y) {
u8* lumaTexture;
TMCCJPEGDecState* state;
u8* luminance;
@@ -598,7 +602,7 @@ static void TMCJPEG_814F2570(TMCCJPEGDecWork* work, s32 x, s32 y) {
}
}
static void TMCJPEG_814F2B50(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV211toY8U8V8edge(TMCCJPEGDecWork* work, s32 x, s32 y) {
u32 chromaTileWidth;
TMCCJPEGDecState* state;
u8* lumaTexture;
@@ -663,7 +667,7 @@ static void TMCJPEG_814F2B50(TMCCJPEGDecWork* work, s32 x, s32 y) {
}
}
static void TMCJPEG_814F3158(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV444toY8U8V8(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 rowSkip;
u8* output;
s32 height;
@@ -718,7 +722,7 @@ static void TMCJPEG_814F3158(TMCCJPEGDecWork* work, s32 x, s32 y) {
}
}
static void TMCJPEG_814F32E4(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV444toY8U8V8edge(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 rowSkip;
u8* output;
s32 height;
@@ -781,7 +785,7 @@ static void TMCJPEG_814F32E4(TMCCJPEGDecWork* work, s32 x, s32 y) {
}
}
static void TMCJPEG_814F34A4(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV400toY8U8V8(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 height;
u8* lumaTexture;
u8* luminance;
@@ -817,7 +821,7 @@ static void TMCJPEG_814F34A4(TMCCJPEGDecWork* work, s32 x, s32 y) {
}
}
static void TMCJPEG_814F372C(TMCCJPEGDecWork* work, s32 x, s32 y) {
static void TMCJPEGDEC_converterYUV400toY8U8V8edge(TMCCJPEGDecWork* work, s32 x, s32 y) {
s32 height;
u8* lumaTexture;
u8* luminance;

View File

@@ -644,3 +644,105 @@ forbidden patterns added (net, per file): 0
readability warnings (net, per file; must be 0 in the final result): 0
GATE PASS
```
## IFD1 switch lowering — decoded model (verified)
Orig tree: root cmpwi 0x132; left {11a};{111};{103};{128};{11c-edge};{12d}; right cmpw 0x8769;{202};{201};{213};{9101};{9000};{a004-edge}.
- Node count = case labels; adjacent shared-fall-through labels merge into ONE counted node
but emit as a range-check (upper-edge `cmpwi <last+1>; bgelr`).
- `case X: ;` (empty body, == else arm) counts as a node but emits NOTHING (folded into
parent's range branch) — orig's {111} emits `beqlr;bgelr` covering the folded {112}.
- {a000,a001,a002,a003} shared empty labels = one range-node -> emits `cmpw 0xa004; bgelr`
(orig's edge form). GNU `case a...b:` ranges compile but count differently — don't use.
- Split pivot = index floor(n/2) over sorted node list (n includes merged ranges as 1).
- Orig set: 14 real labels {103,111,11a,11b,128,12d,132,201,202,213,8769,9000,9101,a003}
+ folded {112} + range {a000..a003} -> 12 nodes + else -> root {132}.
- Residual (~6 insns): dead-blr cluster count, {103} leaf `bltlr` vs `blr`,
body regalloc (r6 vs r8 homes in readU32-assemble bounds-checks).
## Session findings (if-else/switch emission, unroll)
- MWCC if-else vs switch on if-tag dispatch: `if (tag == X) return;` emits
`cmpwi; beqlr` (folded conditional return, no body). `case X: return;` in a
switch emits the same leaf PLUS a dead `blr` body per case (+1 insn each).
- MWCC switch case-source-order controls body emission ORDER (not tree shape):
orig's IFD1 bodies appear as {11a,11b,128,103,201,202} — reordering cases to
that sequence matched orig's body layout (fuzzy 87.5 -> 95.9).
- `case X: ;` empty arms fall into the next arm / switch-exit; adjacent empty
labels merge into ONE range-node ({a000-a003} -> `cmpw 0xa004; bgelr`).
Converting all return-arms to `;` over-merged the left tree (lost 3 folds).
- `case X: break;` emits `beq -> epilogue`, not the beqlr fold — kills the leaf.
- Large constants (>0x7fff): orig materializes `lis r6,1` + `addi r0,r6,-N`
and merges `==`/`>=` compares into `cmpw; beqlr; bge`. MWCC prefers `cmplwi`
for `==` regardless of u16/s16 decl or (u16) casts — prevents the merge.
- MWCC loop unroll: single `for (; iter > 0; iter--)` under an `if (iter > 0)`
guard produces orig's native x2 unroll (`rlwinm.` halve + `mtctr` pairs +
`andi.`/`mtctr`/`bdnz` remainder) — replaces hand-written pairs+do-while.
`if (r > 0)` (pre-shift var) gives `cmpwi r5` + `srwi` (orig's form) but the
inner for-guard re-tests -> double branch. `for(inner=r;inner>0;inner-=8)`
gives one `cmpwi r` guard but folds `done=iter<<3` to `rlwinm` on pre-shift.
## Phase 4 findings (Y8U8V8 chroma dual-path)
- MWCC unroll emits `if (span > 8) { ×8 mtctr body + scalar tail } else { scalar }` for
`for (x = lo; x < hi; x++)` where span = hi-lo. Both paths RE-derive the row setup
(`(y>>2)*stride`, `out + ((y&3)<<3)`) inside each branch — MWCC remats per-path
instead of keeping the values live across the guard.
- LEVER: writing row-setup as INLINE expressions in the store
(`out0[((y & 3) << 3) + off + xo]`, `off = ((x>>3) + (y>>2)*stride) << 5`) stops
MWCC from hoisting them into named temps — reproduces orig's per-path recompute.
Applied to luma + chroma loops: unit gap 126 -> 70.
- EXCEPTION: 420's `x_pos += 2` luma loop wants NAMED locals (hoisted) — inline
collapsed it 467->335; kept named-locals there. MWCC's remat choice is per-fn.
- The `lis -0x8000; addi -2; cmpw; bgt; li flag,1; cmpwi; beq` chains are MWCC's
signed-wrap safety proofs for `end-8` bounds in the unrolled fast path — generated
internally, NOT source-visible logic. Count varies with MWCC's analysis depth.
- Explicit `if (span>8){...}else{...}` in source BALLOONS (MWCC adds its own guard
on top of the manual split) — the dual-path must come from MWCC's unroller.
- `x_pos != x_end` bound (not `<`) is what produces orig's count on 444/444e —
`<` collapses unrolling entirely (99->260). Orig emits `bge` though; counts equal.
- set_converter: orig keeps ONE callee reg (ob) for the whole fn; deferring `st`
load / dropping `cc` made no difference — residual +5 is frame-size regalloc.
## exif_parse switch-emission decodes (wave-2 session)
MWCC switch-tree emission model, verified end-to-end on TMCJPEGDEC_IFD0/IFD1_tag_parse:
- Balanced BST over sorted case values; pivot = element[floor(n/2)] per subtree.
- `break`-bodies at subtree edges FOLD into the parent compare's bound (bgelr/bltlr);
a `break` NOT adjacent to same-target cases counts as a node and emits its own compare.
- `return`-bodies are distinct nodes emitting `cmpwi X;beqlr`.
- KEY: `case 0x0111:return` + `case 0x0112:break` emits `cmpwi 0x111;beqlr;bgelr` exactly
(break-child folds into parent's gt-bound).
- `default:` presence changes tree balance/pivots.
- Case-body emission order = SOURCE case order, not sorted order. Orig's IFD1 source has
`case 0x0103` written AFTER `case 0x0132` (its body lands late at ~0x1270). Reordering
source to match cut IFD1 normalized diffs to ~3 lines.
- Merged `case A: case B:` group shares one body AND still emits one compare per value.
Landings this session (all verified, no shims):
- IFD0: `s32 tag; u32 type;` + `tag/type = readU16()` — the u32 type makes MWCC hoist the
u16 mask (`clrlwi`) to right after the root `cmpwi 0x201`, matching orig's phi-join
placement, while keeping `cmplwi` unsigned compares (s32 flips them to cmpwi - wrong).
- IFD0: `case 0x0103:`+`case 0x0111:` merged return-group kills one dead blr body.
- IFD0: `case 0x0201/0x0202` grouped adjacent with `default:` at switch end keeps root
pivot 0x201 AND folds their shared body - insn count now 482 = orig 482.
- IFD0: `case 0x0102` REMOVED (default covers it) - with it present, {0x102} became a
lt-edge child emitting `bgelr`; without it MWCC emits plain `blr`. Orig has `bltlr`.
- IFD1: body-order decode (0x0103 after 0x0132) + `case 0x0111:return`/`0x0112:break`
fold + `case 0x0103` real body + noop cases 0x012D/0x0132/0x0213/0x8769/0x9000/0x9101/
0xA003 as breaks + `default:` -> only 2 normalized diff lines remain.
Remaining verified ties (documented walls, all source variants failed):
- bltlr-vs-bgelr/bound-side at folded lt-edge children (~15 forms: break/return/group/
default-placement/removal - MWCC picks a fixed emission side).
- Leaf bound-form vs equality: orig `cmpw 0xA004;bgelr` for {0xA003}-leaf (bound at
max+1); every source form emits `cmpw 0xA003;beqlr` + dead blr (IFD1, 2 lines).
- stb-interleave: orig serializes lbz;stb per byte through ONE reg in the 4-byte
version-string copies (exifVer/flashVer/flashPixVer); mine batches lbz x4;stb x4.
u8*/s8* pointer locals, `*q++` walking pointer, for-loop, memcpy all fail to
serialize (MWCC hoists). Scheduling artifact of differing webs.
- 1 dead `blr` body remains in IFD0 after the merged-group fix (unfolded noop body);
regname webs (tag r7-vs-r8, offset r6-vs-r8) are allocator-internal.
Scores after: IFD0 94.25->higher (482=482 insns), IFD1 98.76, exif_parse 99.43.
Texture converter fns re-verified as pure regname webs (instruction multiset identical
in converterYUV411toRGBA8 - 243=243 insns, all diffs are reg homes).