Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion core/best-practices/align-copy-destination.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ origin: ai-assisted
basis: [core-developer, measured, official]
components: [cpu-68080]
applies_to:
core: "Core 12841"
core: "Core 12841-12870"
os: [any]
tags: [68080, alignment, copy, blit, ammx, move16]
related:
Expand All @@ -19,6 +19,7 @@ sources:
- "Gunnar (core developer), answers to questions on the guidelines, 2026-11-03"
- "Gunnar (core developer), Simply 68080 coding guidelines, version of 2026-11-23"
- "Gunnar (core developer), answers on the guidelines, 2026-11-24"
- "ApolloOS-Port test/tools/CopyBench.c and docs/perf/plan-wb-backingstore.md (a), 2026-11-27 (Core 12870)"
---

## Goal
Expand Down Expand Up @@ -48,6 +49,20 @@ Copy of a 156 x 2464-byte shape (M, Core 12841):
| `move16`, 16-byte aligned | 3.1–3.2 | Core 12841 | Same |
| `move16`, misaligned | About 1.75 | Core 12841 | Same |

Rows of 800 bytes x 120 (a 200x120 window at 32 bits), fast RAM, best of
7, D-cache flushed (M, Core 12870, ApolloOS-Port C:CopyBench, 2026-11-27):

| Variant | Measurement | Core | Test setup |
|---|---|---|---|
| fused `move.l` pairs, destination 8-byte aligned | 409 us, 2.3 bytes/cycle | Core 12870 | CCC |
| AMMX `load`/`store`, destination 8-byte aligned | 295 us, 3.2 bytes/cycle | Core 12870 | Same |
| AMMX `load`/`store`, destination 4 mod 8 | 318 us, 3.0 bytes/cycle | Core 12870 | Same |
| AMMX `load`/`store`, source 2 or 4 mod 8 | 350-364 us, the same as aligned in that run | Core 12870 | Same |
| one `move.l` to align the destination to 8, then AMMX (warm) | 534 us, slower than the plain C loop (448 us) | Core 12870 | Same, in one boot |
| `move16`, 16-byte aligned | 428 us cold, 275 us warm | Core 12870 | Same |
| AMMX vs `move.l`, 160-byte rows | 98 vs 113 us | Core 12870 | Same |
| AMMX vs `move.l`, 48-byte rows | 218 vs 210 us | Core 12870 | Same |

## When not to use

- Copies are memory-bound at about 3 bytes per cycle: beyond alignment,
Expand All @@ -62,5 +77,11 @@ Copy of a 156 x 2464-byte shape (M, Core 12841):
measured 1.7–1.8x slower on 2464-byte rows (M), so on cores before 13000,
align the destination of large copies and fills. To be re-measured on
Core 13000+.
- **On Core 12870 the AMMX copy no longer needs it (M):** an AMMX loop
storing to a destination 4 mod 8 was as fast as an aligned one (318 vs
295 us), and copying one long first to align the destination was
*slower* than not aligning (534 vs 348 us). On 12870, use plain AMMX
load/store on 4-byte-aligned data, without alignment code. Not
measured there: misaligned fills, and alignments other than 4.
- Tiny shapes: for rows of 64 bytes or less, plain 68k code wins (see
[ammx-where-it-wins.md](ammx-where-it-wins.md)).