# compare/ — backend output side-by-side with Calypsi 5.16

Each test case lives as three files:

- `<name>.c`           — the C source.
- `<name>.ours.s`      — our backend's assembly (`clang --target=w65816 -O2 -S`).
- `<name>.calypsi.lst` — Calypsi's listing file with source, hex bytes, and asm
                         in one document (`cc65816 --speed -O 2 --64bit-doubles`).

Calypsi's `--output` flag emits an ELF object, not text — its `--list-file` is the
human-readable artifact. (32-bit-doubles is Calypsi's default; we pass
`--64bit-doubles` so FP-heavy tests compare apples to apples against our IEEE-754
`double` ABI.)

## Regenerating

```
bash compare/regen.sh
```

Recompiles every `*.c` in this directory under both compilers and prints an
instruction-count summary:

```
test                          ours  calypsi    ratio
----                          ----  -------    -----
evalAt                         472      254    1.86x
mul16to32                        1        4    0.25x
sumSquares                      26       31    0.84x
```

(Numbers above are current as of 2026-05-20 — re-run for latest.)

## Adding a new comparison

Drop a `<name>.c` in this directory and run `regen.sh`. No other wiring needed.

## Counting methodology

The summary counts asm-line opcodes (lda/sta/jsl/...) on our side and listing
lines that begin with a hex byte (Calypsi's emit-byte column) on theirs.
Both metrics are static instruction counts, NOT bytes. They underestimate
calls-to-runtime (each libcall counts as one `jsl`, not the body it expands to).
For cycle counts, use `scripts/benchCycles.sh`.
