benchmark/: three-way RE-tool comparison + first real C-lift

Three small functions extracted from the v1.19 conservative blob with
ground-truth C and per-tool (Ghidra / retdec / decomp.me) docs:
  01_memset        — byte memset, 28 B
  02_memcpy32      — word-aligned memcpy, 36 B
  03_magic_memset  — magic check + tail-call to memset, 40 B
  04_train_phy_block — first real poll-site function (104 B, 26 insts),
                       contains poll sites 12-15

Results in RESULTS.md:
  - Ghidra: A on all four. Auto-decompile is close to final.
  - retdec: A on #3, F on #1 and #2 (no register-arg inference on raw),
    C on #4 (mistakes & 0xF0000000 for < 0x10000000).

GRIND_LOG.md (in 04_train_phy_block/) records the matching-decomp
iteration: 116-byte candidate.c at -Os vs vendor 104 bytes = 89.7%
size match on first real iteration. Remaining gap is GCC's choice of
`cmp w, w_const; b.ls` over vendor's `tst w, #imm; b.eq` for the
mask tests.

gdb_debug/ holds a native-aarch64 GDB single-stepper for the three
benchmark functions — boltzmann smoke test passed (memset:
buf[10] 0x00→0xab).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-15 07:26:23 +02:00
parent 694be88964
commit 00d655187a
32 changed files with 1113 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
/* Ground-truth C for FUN_00001200 @ blob offset 0x1200 (36 bytes / 9 insts).
*
* Pattern: word-aligned memcpy; length rounded down to word multiple.
* Signature: void memcpy32(uint32_t *dst, const uint32_t *src, size_t len_bytes);
*
* AArch64 ABI: X0 = dst, X1 = src, X2 = len (in bytes, rounded down to 4)
* Scratch: X3 = byte index i, W4 = word register for transfer
*
* Notes the decompiler should ideally recover:
* - `AND x2, x2, #0xFFFFFFFC` is `len &= ~3` — mask-out low 2 bits.
* (Tools often render as `len & 0xFFFFFFFC` or `len & ~3`.)
* - Inner loop reads/writes 4 bytes at a time — tools should recognise
* uint32_t pointers, or at least `*(u32*)(x0+i) = *(u32*)(x1+i)`.
* - Addressing is byte-indexed with a step of 4 — some tools may emit
* `for (i = 0; i < len; i += 4)` in bytes; others may normalise into
* an index-based word loop.
*/
#include <stddef.h>
#include <stdint.h>
void memcpy32(uint32_t *dst, const uint32_t *src, size_t len_bytes) {
len_bytes &= ~(size_t)3; /* round down to 4 */
size_t i = 0;
while (i != len_bytes) {
*(uint32_t *)((uint8_t *)dst + i) =
*(const uint32_t *)((const uint8_t *)src + i);
i += 4;
}
}