diff --git a/libs/RevoEX/src/net/md5.c b/libs/RevoEX/src/net/md5.c index 4a910aff..0d3dfad8 100644 --- a/libs/RevoEX/src/net/md5.c +++ b/libs/RevoEX/src/net/md5.c @@ -71,10 +71,12 @@ void NETMD5GetDigest(NETMD5Context* context, void* digest) { #define ROTATE(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) #define STEP(a, b, c, d, f, word, n) \ do { \ - u32 _xw = __lwbrx((word), 0); \ - u32 _wc = __lwbrx((word), 0) + *constant; \ + u32* _p = (word); \ + u32 _k = *constant; \ + u32 _xw = __lwbrx(_p, 0); \ + u32 _wc = __lwbrx(_p, 0) + _k; \ (a) += (f); \ - (a) = (b) + (((a) + _wc) << (n) | (_xw + (*constant + (a))) >> (32 - (n))); \ + (a) = (b) + ((_wc + (a)) << (n) | (_xw + (_k + (a))) >> (32 - (n))); \ ++constant; \ } while (0) @@ -85,36 +87,35 @@ static void ProcessBlock(NETMD5Context* context) { u32* word; u32* constant; u32* index; - u32* wptr; int round; u32* block; block = context->buffer32; word = block; constant = constants; for (round = 0; round < 4; ++round) { - STEP(a,b,c,d,(b & c) | (~b & d),word,7); ++word; - STEP(d,a,b,c,(a & b) | (~a & c),word,12); ++word; - STEP(c,d,a,b,(d & a) | (~d & b),word,17); ++word; - STEP(b,c,d,a,(c & d) | (~c & a),word,22); ++word; + STEP(a,b,c,d,(b & c) | (~b & d),word++,7); + STEP(d,a,b,c,(a & b) | (~a & c),word++,12); + STEP(c,d,a,b,(d & a) | (~d & b),word++,17); + STEP(b,c,d,a,(c & d) | (~c & a),word++,22); } index = indices; for (round = 0; round < 4; ++round) { - wptr = block + *index; STEP(a,b,c,d,(b & d) | (c & ~d),wptr,5); ++index; - wptr = block + *index; STEP(d,a,b,c,(a & c) | (b & ~c),wptr,9); ++index; - wptr = block + *index; STEP(c,d,a,b,(d & b) | (a & ~b),wptr,14); ++index; - wptr = block + *index; STEP(b,c,d,a,(c & a) | (d & ~a),wptr,20); ++index; + STEP(a,b,c,d,(b & d) | (c & ~d),block + *index++,5); + STEP(d,a,b,c,(a & c) | (b & ~c),block + *index++,9); + STEP(c,d,a,b,(d & b) | (a & ~b),block + *index++,14); + STEP(b,c,d,a,(c & a) | (d & ~a),block + *index++,20); } for (round = 0; round < 4; ++round) { - wptr = block + *index; STEP(a,b,c,d,d ^ b ^ c,wptr,4); ++index; - wptr = block + *index; STEP(d,a,b,c,c ^ a ^ b,wptr,11); ++index; - wptr = block + *index; STEP(c,d,a,b,b ^ d ^ a,wptr,16); ++index; - wptr = block + *index; STEP(b,c,d,a,a ^ c ^ d,wptr,23); ++index; + STEP(a,b,c,d,d ^ b ^ c,block + *index++,4); + STEP(d,a,b,c,c ^ a ^ b,block + *index++,11); + STEP(c,d,a,b,b ^ d ^ a,block + *index++,16); + STEP(b,c,d,a,a ^ c ^ d,block + *index++,23); } for (round = 0; round < 4; ++round) { - wptr = block + *index; STEP(a,b,c,d,c ^ (b | ~d),wptr,6); ++index; - wptr = block + *index; STEP(d,a,b,c,b ^ (a | ~c),wptr,10); ++index; - wptr = block + *index; STEP(c,d,a,b,a ^ (d | ~b),wptr,15); ++index; - wptr = block + *index; STEP(b,c,d,a,d ^ (c | ~a),wptr,21); ++index; + STEP(a,b,c,d,c ^ (b | ~d),block + *index++,6); + STEP(d,a,b,c,b ^ (a | ~c),block + *index++,10); + STEP(c,d,a,b,a ^ (d | ~b),block + *index++,15); + STEP(b,c,d,a,d ^ (c | ~a),block + *index++,21); } context->a += a; context->b += b; diff --git a/tools/decomp-assist/netlib.attempts.md b/tools/decomp-assist/netlib.attempts.md index 21fd62b7..06d20a2b 100644 --- a/tools/decomp-assist/netlib.attempts.md +++ b/tools/decomp-assist/netlib.attempts.md @@ -101,3 +101,25 @@ normalize to in-line `bge`. Same wall as BufFull alloc block. Orig rematerializes the `*colon=0`/`*end=0` store-zero fresh after memcpy (web-split); mine shares headerCopy's NULL web. `'\0'` literal + late-init headerCopy inert — allocator-internal. Documented tie. + +## Pass 6 — md5 ProcessBlock 74.14 -> 81.68/81.71 + +Two decodes landed: +- `_k = *constant` as a separate temp BEFORE the lwbrx pair (orig emits `lwz const` + first, then the two word loads — a distinct constant web vs folding `*constant` + into the _wc expression). 74.14 -> 80.86. +- `_p` pointer capture inside STEP + post-increment args at call sites + (`STEP(..., word++, 7)` and `STEP(..., block + *index++, 5)`). The `word++` + evaluates once into `_p`, so both lwbrx see the same address while the pointer + walks in place — reproduces orig's `addi r4,r4,4` per-step in-place walk + (vs MWCC's `base+offset` temps from `++word` statements). `wptr` local deleted. + index++ likewise folds to orig's stride-16/offset form. -> 81.68. +- `(_wc + (a))` operand order -> 81.71. + +Rejected: `++(word)` inside shared macro tail (no-op; semantically wrong for +rounds 2-4 anyway), `word[i]` args (type error), xw-before-k decl order (74.13), +(a)+=(f) before loads (buildfix attempt broke), shift-assoc `((_xw + _k) + a)` (79.5). + +Residual (32 diff blocks): pure scheduler micro-order — orig prefetches +next-step `lwz const`/`lwz idx`/`lwbrx` into the current step's tail; insn count +306 = 306. Documented pipelining wall.