Skip to content

Core content from Gunnar's coding guidelines - #15

Merged
WDrijver merged 1 commit into
mainfrom
content-gunnar-guidelines
Nov 4, 2026
Merged

WDrijver merged 1 commit into
mainfrom
content-gunnar-guidelines

Conversation

@WDrijver

@WDrijver WDrijver commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Gunnar's draft "Simply 68080 coding guidelines" and his answers of 2026-11-03, split into the knowledge base. Every fact from him is tagged (G). Gunnar has no GitHub account, so new files have owner WDrijver; changed files keep their owner. All files are draft.

New files

  • core/cpu-68080/execution-units.md:
    • the branch path (I-cache and branch target cache);
    • two EA units that own the 16 address registers;
    • the ALUs that own the data registers;
    • instruction groups of at most 16 bytes;
    • memory accesses per cycle.
  • core/best-practices/fewer-and-shorter-instructions.md: fewer instructions even if longer, then the shortest encoding.
  • core/pitfalls/double-memory-indirect.md: memory indirect blocks the core, except in JMP/JSR.

Corrections to existing files

Was Now (G, 2026-11-03) Files
"32 bytes fetched per cycle", a pair "fits in one 32-byte fetch" Decoders get 16 bytes per cycle; a group is at most 16 bytes (18 on some I-cache variants) core-at-a-glance, superscalar-issue
D-cache: "1 read, or 1 write, or 1 read-modify-write" per cycle 1 read and 1 write per cycle; one memory address per cycle core-at-a-glance, pipeline-15-stages
Close 32-bit loops with subq.l + bne.s dbra.l; Gunnar does not recommend subq.l + bne (loop size limit) close-loops-with-dbra, branches-and-prediction
ALU-to-EA bubble "more than 2" 2 cycles by Gunnar's count; may grow in future cores alu-to-ea-bubble, pipeline-15-stages

In close-loops-with-dbra.md, TuKo's example with the loop counter in An and subq/move/bne is replaced by Gunnar's pattern: the index in An, stepped with addq, and the counter in Dn with dbra.l. TuKo's measurements stay.

Additions

  • caches-and-memory: what a miss costs depends on several factors: burst, row/page/bank, read after write, other memory users, and the memory controller per model. The measured 27 cycles is one case.
  • memory-access-patterns:
    • don't use a table for anything you can compute in 16 cycles or less;
    • -(An) is predicted less well than (An)+;
    • parallel streams can confuse the prefetcher;
    • the cache is write-through with write combining.
  • code-size-and-placement: code and constants in two blocks per 4 KB page; no writable data in a code page; limited copy unrolling.
  • fpu-performance-model: Gunnar's rule of thumb: about 6 cycles latency, 32 registers for FPU work.
  • align-copy-destination: Gunnar expects write combining to soften misaligned writes. The measured 1.7–1.8x stays.
  • interleave-dependency-chains: Gunnar's good/bad dependency example.
  • Terms: "write-through cache" and "write combining" written in full, as Gunnar asked.

Open

  • Memory counter loop: Gunnar expects add.l #1,memcounter + dbra to run at about 1 iteration per cycle. TuKo's notes say a counter in memory serialises. Both are recorded; a measurement would settle it.
  • 3 pipes: Gunnar will update his guidelines when cores with 3 pipes are produced.
  • ApolloCrossDev: Gunnar confirms GCC may generate JMP/JSR through memory indirect. That is relevant for double-indirect-fix.patch and the suspected crash on computed gotos (ApolloCrossDev commit ea05a70).

Knowledge base files relied on

  • The changed files listed above
  • core/cpu-68080/prm/integer/dbcc-l.md, core/cpu-68080/prm/integer/bcc-s-plus.md, core/cpu-68080/prm/integer/moviw.md

🤖 Generated with Claude Code

Gunnar's "Simply 68080 coding guidelines" draft and his answers of
2026-11-03, split into the knowledge base (owner WDrijver for new files).

New:
- core/cpu-68080/execution-units.md: branch path, two EA units, ALUs,
  16-byte instruction groups, memory per cycle.
- core/best-practices/fewer-and-shorter-instructions.md
- core/pitfalls/double-memory-indirect.md (fine in JMP/JSR only)

Corrected:
- Instruction groups are at most 16 bytes; the decoders get 16 bytes
  per cycle (was "32-byte fetch").
- The data cache does 1 read and 1 write per cycle (was "1 read, or 1
  write, or 1 read-modify-write").
- Loops: dbra, dbra.l for 32-bit counters; subq.l + bne is not
  recommended.
- ALU-to-EA bubble: 2 cycles by Gunnar's count, may grow.

Added: cache-miss factors, the 16-cycle table rule, prefetch and
write combining notes, code and data placement, limited copy unrolling,
FPU rule of thumb, write alignment note, dependency example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@WDrijver
WDrijver requested a review from TuKo1982 as a code owner November 3, 2026 17:42
@WDrijver
WDrijver merged commit 01cb0a6 into main Nov 4, 2026
2 checks passed
@WDrijver
WDrijver deleted the content-gunnar-guidelines branch November 4, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant