diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2553550..431de18 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -390,7 +390,7 @@ ApolloCrossDev, copies it to a V4 with ApolloExplorer (`acp`), runs it there (`ash`), and stores the output, the serial log and optionally a screenshot or video in `build/v4/`. A test prints `PASS`, `FAIL` and `VALUE` lines (see `tools/v4/tests/akbtest.h`). Variants of one test (`v4:variant`) run -alternately, as `guides/benchmark-method.md` asks. The script's header lists +alternately. The script's header lists the environment variables for the V4's address, serial port, capture device and power plug. diff --git a/core/best-practices/align-copy-destination.md b/core/best-practices/align-copy-destination.md deleted file mode 100644 index bedb6f7..0000000 --- a/core/best-practices/align-copy-destination.md +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: Align the destination of copies and fills -type: best-practice -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [core-developer, measured, official] -components: [cpu-68080] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, alignment, copy, blit, ammx, move16] -related: - - core/cpu-68080/caches-and-memory.md - - core/best-practices/ammx-where-it-wins.md - - core/pitfalls/fused-copy-overlap.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 0 (rules 12-13), 5.1 and 12" - - "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" ---- - -## Goal - -Bandwidth: about 3.2–3.5 bytes per cycle for copies, instead of about 1.8. - -## Technique - -- Align the **destination** to 8 bytes (quad). A misaligned source costs only - 0–13 %; a misaligned destination 1.7–1.8x. -- Use aligned AMMX `load`/`store`, or fused quad moves - (`move.l (a0)+,(a1)+` twice), for the bulk. Handle the misaligned head and - tail separately. -- Use AMMX `storem` (masked store) for the edges: about 1.85 cycles per quad, - whatever the alignment. -- Remember that P96 `AllocBitMap` bases are only 4-byte aligned. - -## Evidence - -Copy of a 156 x 2464-byte shape (M, Core 12841): - -| Variant | Measurement | Core | Test setup | -|---|---|---|---| -| `move.l` loop | 1.7–2.0 bytes/cycle | Core 12841 | CCC | -| AMMX `load`/`store`, misaligned | About 1.8 | Core 12841 | Same | -| AMMX `load`/`store`, 8-byte aligned | 3.2–3.5 | Core 12841 | Same | -| `move16`, 16-byte aligned | 3.1–3.2 | Core 12841 | Same | -| `move16`, misaligned | About 1.75 | Core 12841 | Same | - -## When not to use - -- Copies are memory-bound at about 3 bytes per cycle: beyond alignment, - optimising a blit copy gained only 3–10 %. -- `move16` is never faster than aligned AMMX or fused quad moves, so it is - not worth the extra alignment work. -- Copies under 1 KB: don't add code to align the pointers; use a simple copy - loop (G, 2026-11-23). -- Gunnar states that the CPU reads and writes misaligned without penalty and - combines writes into 16-byte chunks (G, 2026-11-23). This applies to - **Core 13000+** (G, 2026-11-24). On Core 12841 a misaligned destination - 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+. -- Tiny shapes: for rows of 64 bytes or less, plain 68k code wins (see - [ammx-where-it-wins.md](ammx-where-it-wins.md)). diff --git a/core/best-practices/ammx-where-it-wins.md b/core/best-practices/ammx-where-it-wins.md deleted file mode 100644 index 3873995..0000000 --- a/core/best-practices/ammx-where-it-wins.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: Use AMMX where it wins -type: best-practice -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [core-developer, measured] -components: [cpu-68080, saga-video-isabelle] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, ammx, simd, blit, fill, p96] -related: - - core/pitfalls/ammx-separate-load-and-store.md - - core/cpu-68080/prm/ammx-unit.md - - core/best-practices/align-copy-destination.md - - core/pitfalls/ammx-pc-relative-source.md - - core/pitfalls/ammx-upper-32-bits.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 6, 11 and 12" ---- - -## Goal - -Speed for fills, masked stores, pattern fills, format conversion and -decimation, where AMMX gives 1.8x to 11x. - -## Technique - -- Use aligned AMMX stores for fills, `storem` masked stores for template - (text) blits, and preload pattern rows into registers for pattern fills. -- Use AMMX for byte and word lanes: format conversion and decimation. -- Keep a plain 68k path for tiny shapes: - - EOR invert for rows of 64 bytes or less; - - a dedicated column path for widths of 8 pixels or less. -- Record the real call shapes before optimising: in real GUI FillRects, 86 % - of rows were 1–4 pixels wide (M). -- Prefer arithmetic over lookup tables: a table that wins in a hot benchmark - can lose when the real workload evicts it. -- Enable AMMX register saving with the Apollo bit: `ori #$800,sr` / - `andi #$f7ff,sr` (about 8 cycles for the pair, user mode). The OS - `V_EnableAMMX` pair cost 248 cycles (M). - -## Evidence - -| Variant | Measurement | Core | Test setup | -|---|---|---|---| -| Aligned fills | x1.84 | Core 12841 | CCC (M) | -| P96 FillRect, real workload | 1.80 M → 0.60 M cycles | Core 12841 | Aligned AMMX stores + 68k column path | -| P96 BlitTemplate (text) | 2.38 M → 1.59 M cycles | Core 12841 | AMMX `storem` | -| P96 BlitPattern | 307 K → 28 K cycles | Core 12841 | AMMX, two pattern rows preloaded | -| 1-pixel rows, generic vs column path | 14.6 → 2.25 cycles | Core 12841 | Same | -| 6 KB colour lookup table | 1.4x faster in the benchmark, 3–10 % slower on the real console | Core 12841 | Real workload | - -## When not to use - -- **Lanes are bytes or words only.** `pmul*` is 4 x 16x16 (high, low or bits - 23..8); there is no 32-bit add and no MAC. AMMX does not suit 24/32-bit - audio maths: FLAC LPC, Rice decoding, or lossless MP3 synthesis (a 16-bit - window gave 46 dB SNR). -- There is one AMMX unit, so the floor is about IPC 1.0; the second pipe - accepts AMMX stores only. -- A 128-bit AMMX unit is in development (G, 2026-10-29); released cores - (12841) have the 64-bit unit. diff --git a/core/best-practices/close-loops-with-dbra.md b/core/best-practices/close-loops-with-dbra.md index 357477e..9b35109 100644 --- a/core/best-practices/close-loops-with-dbra.md +++ b/core/best-practices/close-loops-with-dbra.md @@ -4,7 +4,7 @@ type: best-practice owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured] +basis: [core-developer] components: [cpu-68080] applies_to: core: "Core 12841" @@ -22,15 +22,13 @@ sources: ## Goal -Speed: loop overhead of 1 cycle instead of 3. "Loops can often be free, or -very low cost" (G). +Speed: "Loops can often be free, or very low cost" (G). ## Technique `dbra` is the best loop instruction (G). Use `dbra` for a 16-bit counter and the 080 encoding `dbra.l` for a 32-bit counter (see -[prm/integer/dbcc-l.md](../cpu-68080/prm/integer/dbcc-l.md)). A -`bne.w` is not an accelerated branch. +[prm/integer/dbcc-l.md](../cpu-68080/prm/integer/dbcc-l.md)).. A good general-purpose loop (G): @@ -72,14 +70,10 @@ most 256 bytes back (`bcc.s+`), while `dbra` has a 16-bit displacement. | Variant | Measurement | Core | Test setup | |---|---|---|---| -| Loop closed with a `bne.w` that does not fuse | 3 cycles overhead | Core 12841 | CCC counter (M) | -| Loop closed with `dbra` or `subq.l` + `bne.s` | 1 cycle overhead | Core 12841 | Same | | `subq.l` + `bne` | Not recommended, partly for the loop size limit | any | Statement (G, 2026-11-03) | -`subq.l #1,dn` + `bne.s/.s+/.w` fuses; `subq` + `bpl` does not (M). Gunnar: -"DBRA is fast and nearly free" (G). +Gunnar: "DBRA is fast and nearly free" (G). ## When not to use -- Very short loops (1–4 turns) are expensive whatever the closing branch: one - turn cost about 12 cycles, each extra turn 3 (M). Special-case them. +No limits known beyond the core developer's statements above. diff --git a/core/best-practices/code-size-and-placement.md b/core/best-practices/code-size-and-placement.md index 8c5c927..6d9bb77 100644 --- a/core/best-practices/code-size-and-placement.md +++ b/core/best-practices/code-size-and-placement.md @@ -4,7 +4,7 @@ type: best-practice owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured] +basis: [core-developer] components: [cpu-68080, toolchain] applies_to: core: "Core 12841" @@ -23,7 +23,7 @@ sources: ## Goal Speed of the whole program: hot code that stays in the I-cache. Fat code -evicts other code, and reloading it costs hundreds of cycles. +evicts other code. ## Technique @@ -36,12 +36,7 @@ evicts other code, and reloading it costs hundreds of cycles. - **Keep code and data apart** (G). Code and read-only constants may share a 4 KB page, in two blocks: 2 KB code, then 2 KB constants is fine. Finely interleaved code and constants (20 bytes of code, 16 bytes of constants, - 50 bytes of code, ...) is bad. Never put writable data in a code page (see - [self-modifying-code-and-caches.md](../pitfalls/self-modifying-code-and-caches.md)). -- **Keep hot code contiguous.** Link the assembler routine right after the C - code that calls it, and put cold objects first. Profile builds must keep - the release link order: use `-fno-toplevel-reorder` and the same object - order. + 50 bytes of code, ...) is bad. Never put writable data in a code page. - **Read memory in address order through `(An)+`** (G). Re-lay tables in the order you read them instead of keeping a C layout; `d16(An)` everywhere makes code fat. @@ -51,24 +46,8 @@ evicts other code, and reloading it costs hundreds of cycles. ## Evidence -| Variant | Measurement | Core | Test setup | -|---|---|---|---| -| Six IMDCT copies (12.9 KB) | Baseline | Core 12841 | Full MP3 decode, CCC (M) | -| One shared transform + 3 short windows (3.8 KB) | Full decode 0.2–0.6 % faster | Core 12841 | Same | -| Profile build with default link order | Synthesis 10.1 % of time | Core 12841 | Same | -| Profile build with release link order | Synthesis 7.3 % of time | Core 12841 | Same | -| Same binary, different load addresses | Up to about 5 % apart (41.6–49.9 cycles on one loop) | Core 12841 | Same | - -- Unrolled variants that won alone (an 8 KB FPU window, a 15-row integer - window) lost in the full decoder (M). -- Shrinking one 2.4 KB routine moved the code linked after it and cost 1.7 % - on the full decode, while the routine itself got 2 % faster (M). +No evidence beyond the core developer's statements above. ## When not to use -- A short scheduled tail can still win: turning a **multiply-bound** - scheduled tail into a dbra loop cost about 30 % per element (14 vs 11 - cycles per sample). "Never unroll" holds for duplicated copies. -- Measure any unrolling in the full program, never in a microbenchmark. -- Core 12841 has an I-cache with few ways; 1-way builds alias code bigger - than the cache by design. Note the core build with every measurement. +No limits known beyond the core developer's statements above. diff --git a/core/best-practices/fixed-point-and-bitstreams.md b/core/best-practices/fixed-point-and-bitstreams.md deleted file mode 100644 index dab2000..0000000 --- a/core/best-practices/fixed-point-and-bitstreams.md +++ /dev/null @@ -1,68 +0,0 @@ ---- -title: Fixed-point multiplies and bitstream decoding on the 68080 -type: best-practice -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [cpu-68080] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, fixed-point, muls, bfextu, bfffo, huffman, codecs] -related: - - core/cpu-68080/measured-instruction-costs.md - - core/pitfalls/multiply-and-bfffo-block-both-pipes.md - - core/pitfalls/alu-to-ea-bubble.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 10 and 11" ---- - -## Goal - -Speed in codecs (MP3, FLAC) and other fixed-point or bitstream code. - -## Technique - -### Fixed point - -- Keep only the high longword of a 64-bit `muls.l` (Q30/Q31 coefficients). -- For rounding, split a constant c = m + c' with |c'| ≤ 0.5 in Q32. Rounding - then costs `add.l lo,lo` / `addx.l d7,hi` (2 instructions instead of 4) and - stays exact. -- Keep 64-bit sums in a register pair with `add`/`addx`. Plain 68020 - assembler with unrolled blocks and a computed entry beat GCC, which spills - every 64-bit product in multiply-heavy loops. - -### Bitstreams - -- Use `bfextu` at a bit position, and `bfffo` for unary codes. -- Memory bitfields cost the same as register bitfields on the 68080. Keeping - a 32-bit window in a register was slower. -- `bfextu` width 0 means 32: guard it. -- Put the sign in the table row index: it removes a dependent smi/eor/sub - chain. -- Read table fields as bytes with `moveq #0` + `move.b` (a fused zero-extending - load), and write both outputs adjacent (a fused quad store). - -## Evidence - -| Variant | Measurement | Core | Test setup | -|---|---|---|---| -| Huffman pair, sign handled with smi/eor/sub | 34.6 cycles per pair | Core 12841 | CCC, MP3 decode (M) | -| Sign in the table row index | 22 cycles per pair | Core 12841 | Same | -| Plus byte fields with fused movz and adjacent outputs | 15.8 cycles per pair | Core 12841 | Same | -| A 256-byte lookup table instead of `bfffo` for Rice unary codes | Slower | Core 12841 | FLAC decode (M) | - -Results in context: MP3 decode went from 23.2 % to 15.7 % of real time at -258 kbps, FLAC 96/24 decode from 30.3 % to about 12–14 % CPU (M, V4 at -99 MHz). - -## When not to use - -- `bfffo` costs 3 cycles and blocks both pipes; `bfextu` runs in pipe 1 - only. In an offset chain they add latency (4 and 6 cycles): see - [multiply-and-bfffo-block-both-pipes.md](../pitfalls/multiply-and-bfffo-block-both-pipes.md). -- A bit position that feeds the next address hits the ALU-to-EA bubble: - `bfextu` → `move.b 2(a1,d5*4)` → `add` took 7.4 cycles per link, 9.1 when - the bit position advances. diff --git a/core/best-practices/fpu-schedule-by-completion-slot.md b/core/best-practices/fpu-schedule-by-completion-slot.md deleted file mode 100644 index 101e36c..0000000 --- a/core/best-practices/fpu-schedule-by-completion-slot.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: Schedule FPU code by completion slot -type: best-practice -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [core-developer, measured] -components: [cpu-68080] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, fpu, scheduling, mac, latency] -related: - - core/cpu-68080/fpu-performance-model.md - - core/best-practices/fpu-when-it-pays.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 0 (rules 8-9) and 4.1" ---- - -## Goal - -Speed: one FPU instruction per cycle. The FPU is pipelined, but it has one -result-write port and needs enough independent chains in flight. - -## Technique - -- Keep at least 5 independent chains for fmul and 6 for fadd (their - latencies). -- Schedule by completion slot (issue cycle + latency): two instructions that - would finish in the same cycle collide, and the second stalls. - Alternating fmul/fadd costs 1.5 cycles per instruction. -- Mix in loads and stores: `fmove.s`/`.d` stores write no FP register and - never collide; patterns LMA, ALM and MAL run at 1.0 cycle per instruction. -- For a multiply-accumulate, use this term order: - -```asm - fmove.s (a0)+,fp1 ; coefficient - fmul.s (a1)+,fp1 ; times sample - fadd.x fp1,fp0 ; accumulate -``` - -- Let integer work run alongside: integer instructions pair with FPU - instructions in pipe 2 for free. - -## Evidence - -| Variant | Measurement | Core | Test setup | -|---|---|---|---| -| MAC term, best order (above) | 3.13 cycles per term | Core 12841 | CCC, 25 patterns fitted (M) | -| MAC term, other orders | 3.5–4.5 | Core 12841 | Same | -| MAC term with an integer operand (`fmove.l`/`fmul.l`) | 4.0–5.1 | Core 12841 | Same | -| Integer MAC (`muls.l` + add/addx) | 4.27 (floor 4.0) | Core 12841 | Same | -| 24 fmul + 24 add.l | 26 cycles | Core 12841 | Same | - -Gunnar's rule (G): a pipelined unit that shows more than 1 cycle per -instruction has a wrong schedule. - -## When not to use - -- A greedy list scheduler on the FPU model did worse than a hand-designed - modulo rhythm (2222 vs 1644 cycles, M). Use the model to check a schedule, - not only to search for one. -- With only 8 FP registers and 2-address code, wide schedules spill: a - 32-point DCT on the FPU lost to integer code. diff --git a/core/best-practices/fpu-when-it-pays.md b/core/best-practices/fpu-when-it-pays.md deleted file mode 100644 index 45057ae..0000000 --- a/core/best-practices/fpu-when-it-pays.md +++ /dev/null @@ -1,59 +0,0 @@ ---- -title: Use the FPU when results stay floating point -type: best-practice -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [cpu-68080] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, fpu, integer, dsp, audio, mac] -related: - - core/best-practices/fpu-schedule-by-completion-slot.md - - core/pitfalls/fpu-float-to-integer-conversion.md - - core/pitfalls/fpu-47-bit-context-save.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 4.3 and 12" ---- - -## Goal - -Speed in DSP-style code (filters, synthesis windows, prediction): a -well-scheduled float MAC beats the integer one, as long as the values do not -have to become integers often. - -## Technique - -- Move multiply-accumulate loops to the FPU when the inputs can be stored as - floats (coefficient streams as `.s`) and the output stays float, or becomes - an integer only once per many operations. -- Use doubles for exact integer arithmetic only up to 47 significant bits - (see [fpu-47-bit-context-save.md](../pitfalls/fpu-47-bit-context-save.md)). -- For 16-bit output, convert with `fmove.w` straight from the FPU: it - saturates and follows the rounding mode - (see [fpu-float-to-integer-conversion.md](../pitfalls/fpu-float-to-integer-conversion.md)). - -## Evidence - -| Variant | Measurement | Core | Test setup | -|---|---|---|---| -| MP3 synthesis window (512 terms), integer `muls.l` | 2185 cycles (4.27 per term) | Core 12841 | CCC (M) | -| Same, FPU with float coefficient streams | 1729 cycles; full decode 5 % faster, quality within dither | Core 12841 | Same | -| FLAC LPC order 8, integer | 46 cycles per sample | Core 12841 | Same | -| FLAC LPC order 8, FPU doubles (values ≤ 44 bits) | 35.5 cycles per sample; full decode 10 % faster | Core 12841 | Same | - -## When not to use - -- When every output must become an integer: each FP-to-integer conversion - costs 3 cycles and blocks both pipes. That rules out IMDCT outputs. -- A 32-point DCT gains at most about 1.7 %: 2-address code and 8 registers - force about 100 spills. -- A hybrid integer + FPU window was worse than either: each FPU term costs - about as much as an integer term once operands come from memory, plus about - 4 cycles of conversion per sample. -- Interleaving float-to-integer conversion with FPU instructions that use - `(An)+` operands cost 320–440 extra cycles: they did not pair for free. -- Converting through the `1.5*2^52` magic number: +250 cycles, and unsafe - because of the 47-bit context save. diff --git a/core/best-practices/interleave-dependency-chains.md b/core/best-practices/interleave-dependency-chains.md index b2bd146..2ca5544 100644 --- a/core/best-practices/interleave-dependency-chains.md +++ b/core/best-practices/interleave-dependency-chains.md @@ -4,7 +4,7 @@ type: best-practice owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured] +basis: [core-developer] components: [cpu-68080] applies_to: core: "Core 12841" @@ -64,18 +64,8 @@ loop: ## Evidence -| Variant | Measurement | Core | Test setup | -|---|---|---|---| -| CRC, one chain | 178 cycles | Core 12841 | CCC counter, trained loop (M) | -| CRC, two interleaved chains | 89 cycles | Core 12841 | Same | -| SHA-256, one chain | 660 cycles | Core 12841 | Same | -| SHA-256, two interleaved chains | 464 cycles | Core 12841 | Same | - -This was the biggest single win in the guide's projects. +No evidence beyond the core developer's statement above. ## When not to use -- When the loop is already issue-bound (every slot filled), software - pipelining or interleaving gains nothing: it did not help BlitTemplate, - Huffman or Rice decoding (M). - When the second chain needs extra registers that force spills to memory. diff --git a/core/best-practices/memory-access-patterns.md b/core/best-practices/memory-access-patterns.md index 6d79c4e..4e98e86 100644 --- a/core/best-practices/memory-access-patterns.md +++ b/core/best-practices/memory-access-patterns.md @@ -4,7 +4,7 @@ type: best-practice owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured] +basis: [core-developer] components: [cpu-68080] applies_to: core: "Core 12841" @@ -24,9 +24,8 @@ sources: ## Goal -Memory throughput: sequential reads are prefetched and cost almost nothing -extra; every random cache miss costs about 27 cycles, and misses do not -overlap. +Memory throughput: the prefetcher predicts increasing addresses best, and +random access is very bad (G). ## Technique @@ -40,15 +39,12 @@ overlap. 2026-11-03). MUL and DIV beat a table; a SIN table makes sense. Keep the tables you do use small and hot. A typical table miss costs about 16 cycles of stall; use 16 as the reference (G, 2026-11-24). So 10 cycles of - arithmetic can beat a table access (G, 2026-11-23). The 27 measured below - is a bad case: dependent random reads over 4 MB (M). -- Avoid rows exactly 64 KB apart: they alias in the cache. -- Use `touch d8(An,Dn)` 12–15 cycles ahead only for random accesses, never - on a sequential stream. -- Don't keep a loop counter or accumulator in memory with read-modify-write: - store-to-load forwarding works, but it serialises (M). Gunnar expects such a - loop to run at about 1 iteration per cycle (G); this is still to be - measured. + arithmetic can beat a table access (G, 2026-11-23). +- Use `touch d8(An,Dn)` only for random accesses, never on a sequential + stream. +- A loop that keeps its counter or accumulator in memory with + read-modify-write: Gunnar expects it to run at about 1 iteration per cycle + (G). - Write in address order too. The cache is write-through with write combining: the CPU collects writes for a few cycles and combines them into 16-byte chunks before committing them, which makes memclr and memcopy @@ -58,17 +54,8 @@ overlap. | Variant | Measurement | Core | Test setup | |---|---|---|---| -| Cold sequential read of every long | 10.2 cycles per 64-byte line | Core 12841 | CCC (M) | -| Warm sequential read of every long | 9.1 cycles per line | Core 12841 | Same | -| One read per 64-byte line | 14.4 cycles per line | Core 12841 | Same | -| One read per 128 bytes | 27.2 cycles | Core 12841 | Same | -| Random miss (dependent load) | About 30 cycles total, 27 more than a hit | Core 12841 | Pointer chase over 4 MB | -| Rows 64 KB apart | About 10 % slower | Core 12841 | Same | -| A 256-byte lookup table instead of `bfffo` for Rice codes | Slower | Core 12841 | Real decode | | Table against computation | Compute anything that takes 16 cycles or less | any | Statement (G, 2026-11-03) | ## When not to use -- A hot-cache microbenchmark of table-driven code does not predict the real - program: confirm on the real workload, three times (real-workload noise is - about ±10 %). +No limits known beyond the core developer's statements above. diff --git a/core/best-practices/predicated-bcc-over-one-instruction.md b/core/best-practices/predicated-bcc-over-one-instruction.md index c7379e6..0b79b8d 100644 --- a/core/best-practices/predicated-bcc-over-one-instruction.md +++ b/core/best-practices/predicated-bcc-over-one-instruction.md @@ -4,7 +4,7 @@ type: best-practice owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, official] +basis: [official] components: [cpu-68080] applies_to: core: "Core 12841" @@ -19,17 +19,14 @@ sources: ## Goal -Speed: a conditional operation that is never mispredicted, at the cost of a -correctly predicted branch. +Speed: a faster way to execute a single instruction that follows a `bcc.s` +(official). ## Technique Branch with `bcc.s` over exactly one instruction. The 68080 executes the pair -as a conditional instruction when the skipped instruction: - -- is at most 8 bytes long; -- is single-cycle; -- does not change an An (so not `(An)+`, `-(An)`, `addq An` or `lea`). +as a conditional instruction (official, see +[prm/optimizing.md](../cpu-68080/prm/optimizing.md)). ```asm cmp.l d1,d0 @@ -40,19 +37,9 @@ as a conditional instruction when the skipped instruction: ## Evidence -| Variant | Measurement | Core | Test setup | -|---|---|---|---| -| `beq.s`/`beq.w` over 2 instructions, random pattern | 7.0 cycles per turn | Core 12841 | 65536 branches, CCC, median of 7 (M) | -| `beq.w`/`beq.s` over 2 instructions, alternating | 10.5 | Core 12841 | Same | -| `beq.s` over 1 instruction, any pattern | 3.0 | Core 12841 | Same | -| No branch | 2.0 | Core 12841 | Same | +No evidence beyond the PRM's statement above. ## When not to use -- When the skipped code is more than one instruction, or changes an An: then - it is an ordinary branch and can be mispredicted. -- Don't insert other instructions between the `bcc.s` and the skipped - instruction when you interleave code. An FPU instruction placed there made - the branch land inside it ("CHK instruction error") (M). -- Don't replace the pattern with Scc + mask: the predicated branch is as fast - and simpler. +- When the skipped code is more than one instruction: then it is an ordinary + branch. diff --git a/core/best-practices/use-fusable-pairs.md b/core/best-practices/use-fusable-pairs.md index d070f7c..16910a4 100644 --- a/core/best-practices/use-fusable-pairs.md +++ b/core/best-practices/use-fusable-pairs.md @@ -4,7 +4,7 @@ type: best-practice owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, official] +basis: [official] components: [cpu-68080] applies_to: core: "Core 12841" @@ -43,12 +43,8 @@ copy. ## Evidence -| Variant | Measurement | Core | Test setup | -|---|---|---|---| -| 16 x (`move.l dn,dm` + `add.l`), split apart | 9.1 cycles | Core 12841 | CCC (M) | -| Same, adjacent | 5.1 cycles | Core 12841 | Same | -| Same with E registers, adjacent | 1 pair per cycle | Core 12841 | Same | -| `fmove.x` + `fmul.x`, independent pairs, split / adjacent | 2.25 / 1.12 cycles per pair | Core 12841 | fpu3 test (M) | +The PRM's fusing table (official): a fused pair is treated by the core as a +single instruction. ## When not to use @@ -56,5 +52,3 @@ copy. them for a forward copy whose destination is less than 8 bytes ahead of the source. See [fused-copy-overlap.md](../pitfalls/fused-copy-overlap.md). - `subq.l #1,dn` + `bpl` does not fuse; `fsub` does not fuse. -- Fused FPU pairs count as 2 instructions in IEP1/IEP2: measure them with - CCC. diff --git a/core/cpu-68080/bank-prefix.md b/core/cpu-68080/bank-prefix.md index 58323d4..673078a 100644 --- a/core/cpu-68080/bank-prefix.md +++ b/core/cpu-68080/bank-prefix.md @@ -1,10 +1,10 @@ --- -title: 68080 BANK prefix and register naming (measured) +title: 68080 BANK prefix and register naming type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, official] +basis: [core-developer, official] components: [cpu-68080] applies_to: core: "Core 12841" @@ -21,8 +21,7 @@ sources: ## Summary The BANK prefix (`$71xx`) gives legacy instructions access to E0–E23. On a -single-register operand both bank fields must be set. Banking works for a -list of instructions and is still wrong for another list. +single-register operand both bank fields must be set. ## Details @@ -38,41 +37,20 @@ list of instructions and is still wrong for another list. - AA banks the register **source**, BB the register **destination**: `01` = E0–E7, `10` = E8–E15, `11` = E16–E23. - `$71xx` with SS ≠ 0 is illegal. -- BANK runs in pipe 2 at full speed and fuses. It counts as one instruction - in IEP1/IEP2 (M). ### Single register operand For instructions with one register operand (tst, clr, neg, not, ext, swap, scc, bitfields, the dbcc counter) and for `#imm,Rn`: **AA must equal BB**, -for example `$7105`, `$710A`, `$710F` (official, M). +for example `$7105`, `$710A`, `$710F` (official). - AA alone: the plain Dn is used. -- BB alone: looks right on a cold pass, but in a trained loop pipe 2 reads the - plain Dn (M). - -### What works and what does not (Core 12830–12841, M) - -| Banking works | Banking does not work yet | -|---|---| -| move, moveq, addi, subi, eor, eori, ori, andi, not, neg, negx, btst, tst, bclr, clr, bset, bchg, swap, scc, bfclr, bfset, bftst, bfchg, bfffo, ext, extu, cmpi, shifts and rotates (a banked shift count too), moviw.l, perm | add, sub, and, or, cmp, addx, subx, mul, div, abcd, sbcd, pack, unpk, exg, bfextu, bfexts, bfins | - -Examples of the failures: - -- `add.l e6,d1` computed d6 + d6. -- `exg Dn,En` writes En, but Dn gets the plain register. -- `cmp.l En,Dn` (`$7104`, AA = source) uses the plain Dn on the first two - passes and the right En from the third pass on (Core 12841). -- `add.l #imm,En` works with AA = BB (`$7105`, `$D2BC`) on every pass. ### B registers - Supported forms: `movea.l ,Bn`, `move.l Bn,` (ea not An/Bn), `lea ,Bn`, `lea (Bn),An`, `addq/subq #,Bn` (CCR unchanged) and `cmp.l Bn,Dn`. B registers are fully usable as AMMX address registers. -- On Core 12841 all these forms give the right result on every pass of a - 5-pass loop, including `addq` after `movea.l` or `lea`, and AMMX - `load (Bn)` (M). - `add.l Bn,Dn` and `move.l An,Bn` are not supported. ### Task switches @@ -95,6 +73,4 @@ The team has decided: **no BANK prefix on FPU instructions** in future cores ## Do / Don't - DO set AA = BB for single-register operands and `#imm,Rn`. -- DON'T bank the instructions in the "does not work yet" column. Do the - arithmetic in a plain Dn. - DON'T put a BANK prefix on FPU instructions in new code. diff --git a/core/cpu-68080/branches-and-prediction.md b/core/cpu-68080/branches-and-prediction.md index 963dc85..1b3dbeb 100644 --- a/core/cpu-68080/branches-and-prediction.md +++ b/core/cpu-68080/branches-and-prediction.md @@ -1,10 +1,10 @@ --- -title: 68080 branch costs and prediction (measured) +title: 68080 branches and prediction type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, official] +basis: [core-developer, official] components: [cpu-68080] applies_to: core: "Core 12841" @@ -13,8 +13,6 @@ tags: [68080, branches, prediction, btc, rts, predication] related: - core/best-practices/predicated-bcc-over-one-instruction.md - core/best-practices/close-loops-with-dbra.md - - core/pitfalls/alternating-branch-mispredicted.md - - core/pitfalls/return-address-patching.md - core/cpu-68080/prm/integer/bcc-s-plus.md - core/cpu-68080/prm/integer/dbcc-l.md sources: @@ -24,50 +22,21 @@ sources: ## Summary -A mispredicted Bcc costs about 7 cycles, a mispredicted RTS about 9.5. The -predictor does not learn a strict alternation. A `bcc.s` over one -single-cycle instruction is executed as a conditional instruction and is -never mispredicted. +A branch misprediction is detected after the ALU stage (G). A `bcc.s` over +one instruction is executed as a conditional instruction (official). The 080 +adds the branch sizes `bcc.s+` and `dbcc.l`. ## Details -### Costs +### Misprediction -Test: forward `beq` over 2 instructions, flag from `tst.b (a0)+` on a table, -65536 branches, CCC counter, median of 7 (M, Core 12841, 2026-10-29). - -| Direction pattern | `beq.w` / `beq.s` over 2 instructions | `beq.s` over 1 instruction | No branch | -|---|---|---|---| -| Always taken | 3.0 cycles per turn | 3.0 | 2.0 | -| Never taken | 4.0 | 3.0 | 2.0 | -| Random (50 %) | 7.0 (+3.5 = half of 7) | 3.0 | 2.0 | -| Alternating T/N/T/N | **10.5** (+7: every one mispredicted) | 3.0 | 2.0 | - -- `.w` and `.s` cost the same here. - A misprediction is detected after the ALU stage (G); a mispredicted RTS is caught there too. -- **Mispredicted RTS: about 9.5 cycles.** A `bsr` + `rts` turn took 4.6 - cycles normally and 14.0 when the routine moved its return address - (`addq.l #2,(sp)`) (M). -- An inner `dbra` loop of random length 1–4 cost no more than the average of - the fixed lengths. But each extra turn of such a tiny loop cost 3 cycles, - and one turn about 12 (M). -- `rtd` used as a jump cost about 45 cycles (M). -- Computed and indirect jumps mispredict more. A table of `bra.s` through - `jmp (table,pc,dn.w)`, or an address read from memory, is predicted; - compute the index early. ### Predication A `bcc.s` over **one** instruction is executed as a conditional instruction -when the skipped instruction: - -- is at most 8 bytes long; -- is single-cycle; -- does not change an An. So `(An)+`, `-(An)`, `addq An` and `lea` are not - predicated. - -Measured: 3.0 cycles whatever the pattern, never mispredicted (M). +(official, see [prm/optimizing.md](prm/optimizing.md)). ### 080 branch sizes @@ -79,25 +48,11 @@ Measured: 3.0 cycles whatever the pattern, never mispredicted (M). ## Differences from AmigaOS / AROS / 68060 -- A loop closed with `bne.w` is not accelerated on the 68080. Close loops - with `dbra` (`dbra.l` for a 32-bit counter): loop overhead goes from 3 - cycles to 1 (M). Gunnar does not recommend `subq.l` + `bne` (G). Do not - carry over 68060 loop-closing habits unmeasured. +- Close loops with `dbra` (`dbra.l` for a 32-bit counter). Gunnar does not + recommend `subq.l` + `bne` (G). - A `bcc.s` over one instruction becoming a conditional instruction is 68080 specific. -- The return cache makes RTS cheap only when the return address is not - changed. ## Do / Don't -- DO leave a `bcc.s` over one single-cycle instruction alone: do not replace - it with Scc + mask. -- DO keep a `bcc.s *+4` and its skipped instruction adjacent when you - interleave code. An FPU instruction inserted between them made the branch - land inside it ("CHK instruction error"). -- DON'T write branches that flip every iteration: unroll by 2, or compute the - value without a branch. -- DON'T patch return addresses, `pea` + `rts`, or use `rtd` as a jump. To fall - back to an original routine, use `jmp ([ptr,pc])`, which is predicted. -- DO special-case very short loops (1–4 turns) and pull small cases out of - size-dispatch code: benchmark with random sizes. +- DON'T close loops with `subq.l #1,Dn` + `bne`; use `dbra` or `dbra.l` (G). diff --git a/core/cpu-68080/caches-and-memory.md b/core/cpu-68080/caches-and-memory.md index 1fb2077..21fb83d 100644 --- a/core/cpu-68080/caches-and-memory.md +++ b/core/cpu-68080/caches-and-memory.md @@ -1,10 +1,10 @@ --- -title: 68080 caches and memory access (measured) +title: 68080 caches and memory access type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, official] +basis: [core-developer, official] components: [cpu-68080] applies_to: core: "Core 12841" @@ -13,8 +13,6 @@ tags: [68080, cache, line-size, prefetch, alignment, miss] related: - core/cpu-68080/prm/specs.md - core/best-practices/memory-access-patterns.md - - core/best-practices/align-copy-destination.md - - core/pitfalls/self-modifying-code-and-caches.md - core/pitfalls/touch-misuse.md sources: - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 5.1 and 5.2" @@ -27,47 +25,18 @@ sources: ## Summary -Cache lines are 64 bytes. The data cache serves one 8-byte access per cycle. -Sequential reads are prefetched and nearly as fast as warm data; a random -miss costs about 27 extra cycles and misses do not overlap. Misaligned reads -are nearly free; misaligned writes are not. +A cache miss loads a 64-byte burst (G). The data cache serves one 8-byte +access per cycle. Misaligned reads that hit the cache are free (official). +The typical miss costs about 16 cycles of stall (G). ## Details -### Line size - -Measured with a random-order pointer chase over 4 MB, 8192 blocks, CCC -counter, median of 7, two identical runs (M, Core 12841, 2026-10-29): - -| Block | 1st read (offset 0) | 2nd read (offset block/2) | Means | -|---|---|---|---| -| 32 B | 30.3 cycles | +3.0 (hit) | Same line | -| 64 B | 30.6 | +3.0 (hit) | Same line: **the line is 64 bytes** | -| 128 B | 30.6 | +16.5 | Next line, already partly on its way | -| 256 B | 30.6 | +29.4 | Full miss | - -- A miss on one line seems to bring the next 64-byte line in early: reading - it right after cost about half a miss. -- Two lines 128 bytes or more apart are fully independent misses. -- Older notes (Core 12798–12824) gave "sequential about 2 cycles per line, - random about 60". They assumed 32-byte lines and their method is lost; the - figures here replace them. - ### Streaming and random access -- Reading every long of cold memory: about 10.2 cycles per line, nearly the - warm speed (9.1). -- One long per line: 14.4 cycles per line. One per 128 bytes: 27.2. -- Random access: about 27 cycles per new line, and misses do not overlap. -- Aliasing: rows exactly 64 KB apart cost about 10 %, and 8 lookups 64 KB - apart gave 8 misses. -- Store-to-load forwarding works, but a counter kept in memory with - read-modify-write in a loop serialises (M). Gunnar expects a loop of - `add.l #1,memcounter` + `dbra` to run at about 1 iteration per cycle (G, - 2026-11-03). Measured on Core 12556, the loop takes 2 cycles per - iteration, and 20–23 when the counter is in the same 64-byte line as the - loop code; `dbra` alone and `addq.l #1,Dn` + `dbra` take 1 cycle - (M, Core 12556, V4 UniCorn, `tools/v4/tests/add-mem-dbra`, 2026-11-09). Not yet measured on Core 12841. +- The prefetcher predicts increasing addresses best; `-(An)` is less good, + and random access (pointer chasing) is very bad (G). +- Gunnar expects a loop of `add.l #1,memcounter` + `dbra` to run at about 1 + iteration per cycle (G, 2026-11-03). ### What a miss costs (G, 2026-11-03) @@ -87,63 +56,35 @@ The memory controller is part of the core, so it is the same on every V4 model that runs the same core (see [hardware/index.md](../../hardware/index.md)). -The 27 cycles above are one case: dependent random reads over 4 MB. The -typical miss, to use as the reference, is about 16 cycles of stall (G, -2026-11-24). When you measure a miss, state these conditions. +The typical miss, to use as the reference, is about 16 cycles of stall (G, +2026-11-24). -Memory-bound measurements from a core before 12600 (64-bit controller) are -not comparable with those from Core 12600 and later. All measurements in -this knowledge base are from Core 12798 or later. +Memory-bound timings from a core before 12600 (64-bit controller) are not +comparable with those from Core 12600 and later. ### Alignment -Copy of a 156 x 2464-byte shape (M): - -| Method | Aligned | Misaligned | -|---|---|---| -| AMMX `load`/`store` | 3.2–3.5 bytes/cycle (8-byte aligned) | About 1.8 | -| `move16` | 3.1–3.2 (16-byte aligned) | About 1.75 | -| `move.l` loop | 1.7–2.0 | | -| AMMX `storem` (masked) | About 1.85 cycles per quad, whatever the alignment | | - - Alignment is not needed for correctness: misaligned reads that hit the cache are free (official). -- A misaligned **destination** costs 1.7–1.8x; a misaligned source only - 0–13 %. - Gunnar (G, 2026-11-23): misaligned reads and writes have no penalty, a read may span two cache lines, writes are combined into 16-byte chunks, and copies under 1 KB need no alignment code. This applies to Core 13000+ - (G, 2026-11-24); on Core 12841 the 1.7–1.8x above stands (M). To be - re-measured on Core 13000+. -- Copies are memory-bound at about 3 bytes per cycle: optimising a blit copy - gained only 3–10 %. + (G, 2026-11-24). - A `.b`/`.w` write into a register also reads its old value: an extra dependency. Prefer `.l` or quad register updates. -### Cache control - -- `CacheClearU`/`CacheClearE` do nothing on the 68080 under AmigaOS; see - [self-modifying-code-and-caches.md](../pitfalls/self-modifying-code-and-caches.md). -- Evicting the D-cache takes 128–256 KB of reads. - ## Differences from AmigaOS / AROS / 68060 -- 64-byte lines instead of 16 bytes on the 68040/68060. Data used together - should sit in the same 64-byte line. -- On the 68080 a misaligned read that hits the cache is free; only the write - side needs alignment for speed. +- 64-byte memory bursts instead of 16-byte lines on the 68040/68060. Data + used together should sit in the same 64-byte line. +- On the 68080 a misaligned read that hits the cache is free (official). ## Do / Don't -- DO align the destination of copies and fills of 1 KB or more (under 1 KB, - use a simple loop, G). -- DO read memory densely and in address order. +- DON'T add alignment code to copies under 1 KB: use a simple loop (G). +- DO read memory densely and in address order (G). - DON'T chase pointers over large data, or use big lookup tables read at - random. + random (G). - DON'T use a table for anything you can compute in 16 cycles or less (G). -- DON'T keep a loop counter in memory. -- DON'T write data in a loop that sits in the same 64-byte line as the - loop's code: a read-modify-write there cost 10 times as much (M, Core - 12556). - DON'T compare memory-bound timings across Core 12600: the memory - controller doubled from 64 to 128 bits there. + controller doubled from 64 to 128 bits there (G). diff --git a/core/cpu-68080/core-at-a-glance.md b/core/cpu-68080/core-at-a-glance.md index f648945..2fde5ee 100644 --- a/core/cpu-68080/core-at-a-glance.md +++ b/core/cpu-68080/core-at-a-glance.md @@ -1,10 +1,10 @@ --- -title: 68080 core at a glance (measured) +title: 68080 core at a glance type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, official] +basis: [core-developer, official] components: [cpu-68080] applies_to: core: "Core 12798-12847" @@ -15,19 +15,16 @@ related: - core/cpu-68080/superscalar-issue.md - core/cpu-68080/caches-and-memory.md - core/cpu-68080/prm/specs.md - - core/pitfalls/turtle-mode-counters.md sources: - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 1" - "Gunnar (core developer), answers to questions on the guidelines, 2026-11-03" - "Gunnar (core developer), memory controller width, 2026-11-04" - - "lessons/2026-11-v4-turtle-mode.md" --- ## Summary -The key numbers of the 68080 as measured on V4 cores 12798 to 12847. Where -they differ from the PRM, the measured value or the core developer's -statement wins. +The key numbers of the 68080 on V4 cores 12798 to 12847. Where they differ +from the PRM, the core developer's statement wins. ## Details @@ -35,25 +32,22 @@ statement wins. |---|---| | Clock (V4) | 14 x 7.09379 MHz = 99.31 MHz. The PAL colour clock of 3546895 Hz drives the Paula/ARNE periods | | Pipeline | The PRM summarizes it in 7 steps (I-fetch, decode, register fetch, EA, D-cache, ALU, write back). The real depth is 15 stages, see [pipeline-15-stages.md](pipeline-15-stages.md) | -| Pipes | PRM: 3 (Anton, Bruno, Cesar). **2 enabled on Core 12798-12841** (M): IEP3 always reads 0. A third pipe comes in a future core (G) | +| Pipes | PRM: 3 (Anton, Bruno, Cesar). A third pipe comes in a future core (G) | | Decoders | 3. Only the first takes multi-cycle instructions (mul, div, movem, bitfields, FPU) and addx/subx/negx, which need the flags of the previous instruction | -| I-cache | 32 KB, **64-byte line** (G, 2026-10-29). Feeds the decoders **16 bytes per cycle**; a group of instructions that run together is at most 16 bytes (some I-cache variants: 18) (G, 2026-11-03), see [execution-units.md](execution-units.md). Few ways on Core 12841 (G); the number of ways is a build option: 4, 2 or 1 (G, 2026-10-30). Note the core build with every measurement | -| D-cache | 128 KB, **64-byte line** (G, 2026-10-29; M). **1 read and 1 write per cycle** (G, 2026-11-03): `add.l #1,mem` runs at about 1 per cycle; measured with `dbra` on Core 12556: 2 cycles per iteration (M). One memory address per cycle, so an instruction with two memory operands needs more than one | -| Bus and memory | Memory controller 128-bit from Core 12600, 64-bit before (G, 2026-11-04). 64-byte bursts (one cache line), about 12 cycles latency, automatic prefetch of sequential streams | +| I-cache | 32 KB, **64-byte line** (G, 2026-10-29). Feeds the decoders **16 bytes per cycle**; a group of instructions that run together is at most 16 bytes (some I-cache variants: 18) (G, 2026-11-03), see [execution-units.md](execution-units.md). Few ways on Core 12841 (G); the number of ways is a build option: 4, 2 or 1 (G, 2026-10-30) | +| D-cache | 128 KB, **64-byte line** (G, 2026-10-29). **1 read and 1 write per cycle** (G, 2026-11-03): `add.l #1,mem` runs at about 1 per cycle. One memory address per cycle, so an instruction with two memory operands needs more than one | +| Bus and memory | Memory controller 128-bit from Core 12600, 64-bit before (G, 2026-11-04). 64-byte bursts (one cache line), automatic prefetch of sequential streams | | Branch cache | 1024-entry BTC, a loop predictor, and a return cache for rts/rtd/rtr | | MMU | None. PMMU and cp4–cp6 opcodes are illegal (`lpstop` remains) | -| FPU | 64-bit (double) internally, pipelined. Microcoded functions (trig, log, exp, fmod, frem, fscale, fgetexp/fgetman) take 100–200+ cycles and clobber E23 | -| AttnFlags | `$847f` with the FPU on, `$040f` with it off. **Bit 10 = 68080** | -| Context frames | AMMX 256 bytes, FPU 116 bytes | -| Turtle mode | `ApolloControl TU=1/2/3` (A500/A1200/A4000). Same clock (CCC 99.3 MHz), one pipe issues, code 177x / 89x / 4.5x slower on Core 12856 (M). PCR bits 7-6 show it, see [turtle-mode-counters.md](../pitfalls/turtle-mode-counters.md) | +| FPU | 64-bit (double) internally, pipelined | +| AttnFlags | **Bit 10 = 68080** | Older notes and processor.resource up to version 44.6 give a 32-byte D-cache -line; 44.7 gives 64 bytes, which matches the measurement. +line; 44.7 gives 64 bytes. ## Differences from AmigaOS / AROS / 68060 -- The 68060 has two pipes and an MMU. Released V4 cores also run two pipes, - but have no MMU: PMMU instructions are illegal. +- The 68060 has an MMU. The 68080 has none: PMMU instructions are illegal. - The cache lines are 64 bytes, not 16 as on the 68040/68060. - 68080 detection uses AttnFlags bit 10, which classic AmigaOS does not define. @@ -62,7 +56,6 @@ line; 44.7 gives 64 bytes, which matches the measurement. - DO gate 68080 code paths on AttnFlags bit 10, and FPU paths on the 68881 flag at run time: the FPU can be switched off. -- DON'T assume three pipes because the PRM says so: measure IEP3 on your core. -- DON'T benchmark in Turtle mode: check PCR bits 7-6, or set - `ApolloControl TU=0`, first. +- DON'T assume three pipes because the PRM says so: a third pipe comes in a + future core (G). - DON'T use MMU instructions on the 68080. diff --git a/core/cpu-68080/core-bugs-by-revision.md b/core/cpu-68080/core-bugs-by-revision.md deleted file mode 100644 index 91a389e..0000000 --- a/core/cpu-68080/core-bugs-by-revision.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: 68080 core bugs by core revision -type: reference -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [cpu-68080, saga-3d-maggie] -applies_to: - core: "Core 12001-12847" - os: [any] -tags: [68080, bugs, core-revision, regression] -related: - - core/pitfalls/fpu-broken-instructions.md - - core/pitfalls/ammx-pc-relative-source.md - - core/pitfalls/ammx-upper-32-bits.md - - core/pitfalls/bank-prefix-pitfalls.md - - core/pitfalls/tex-does-not-match-prm.md - - core/pitfalls/maggie-depth-test-colour-write.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 4.2, 6, 7.3 and 15.7" ---- - -## Summary - -Core bugs seen on V4 cores 12001 to 12847, and which are fixed. Each open bug -has its own pitfall file. Check this list against your core: a new core can -fix or add bugs. - -## Details - -### Fixed - -| Bug | Fixed in | -|---|---| -| `cmp.l Bn,Dn` ignored Bn | Core 12840 | -| `move En,Dn` in pipe 2 paired with a pipe-1 instruction writing the same register | Fixed (core not recorded) | -| `FDBcc` never decremented and always branched (Core 12830/12840) | Core 12841 | -| `move2.l (An),Dx:Dy` loaded the second register wrong (Core 12001) | Checked fixed on Core 12841 | -| `addq.l #n,Bn` added to a hidden register (Core 12001) | Checked fixed on Core 12841 | -| `lea (Bn),An`, AMMX `(Bn)` wrong (Core 12001) | Checked fixed on Core 12841 | - -### Still wrong on Core 12841 - -| Area | Bug | Pitfall | -|---|---|---| -| FPU | FScc to `d16(An)`/`d8(An,Xn)`, FTRAPcc, `flognp1`, dynamic `fmovem` list, `fmove.x` memory operands | [fpu-broken-instructions.md](../pitfalls/fpu-broken-instructions.md) | -| FPU | Transcendental, `fdiv` and `fsqrt` precision; `fadd` rounds toward zero; FPCR precision ignored; `fint` ties | [fpu-precision-and-rounding.md](../pitfalls/fpu-precision-and-rounding.md) | -| FPU | FPSR exception bytes and traps never set | [fpu-exceptions-never-trap.md](../pitfalls/fpu-exceptions-never-trap.md) | -| AMMX | PC-relative sources read 2 bytes early | [ammx-pc-relative-source.md](../pitfalls/ammx-pc-relative-source.md) | -| AMMX | `move.l #imm` clears the upper 32 bits on trained passes | [ammx-upper-32-bits.md](../pitfalls/ammx-upper-32-bits.md) | -| BANK | `cmp.l En,Dn` uses the plain Dn on cold passes | [bank-prefix-pitfalls.md](../pitfalls/bank-prefix-pitfalls.md) | -| TEX | Does not match the PRM's byte form (Core 12846) | [tex-does-not-match-prm.md](../pitfalls/tex-does-not-match-prm.md) | -| Maggie | Depth test does not gate the colour write; the last 8 bytes of a span stay in the unit (Core 12847) | [maggie-depth-test-colour-write.md](../pitfalls/maggie-depth-test-colour-write.md), [maggie-span-tail.md](../pitfalls/maggie-span-tail.md) | - -## Differences from AmigaOS / AROS / 68060 - -These are 68080 core bugs. The same code runs correctly on a 68060; do not -work around them on other CPUs. - -## Do / Don't - -- DO note the core revision with every measurement and bug report. -- DO recheck this list when you move to a new core. -- DON'T rely on a fix from a core you have not tested on. diff --git a/core/cpu-68080/execution-units.md b/core/cpu-68080/execution-units.md index 17ee2b5..08acd0f 100644 --- a/core/cpu-68080/execution-units.md +++ b/core/cpu-68080/execution-units.md @@ -4,7 +4,7 @@ type: reference owner: WDrijver status: reviewed origin: ai-assisted -basis: [core-developer, measured] +basis: [core-developer] components: [cpu-68080] applies_to: core: "any" @@ -67,9 +67,6 @@ the ALUs that own the data registers. Most cores run 2 pipes; 3 are planned. [close-loops-with-dbra.md](../best-practices/close-loops-with-dbra.md). - `jmp (An)` is computed by the EA unit and takes much longer than the branches in the first row. -- `rts` is very fast as long as the return address on the stack is not - overwritten (see - [return-address-patching.md](../pitfalls/return-address-patching.md)). - The core does some EA updates for free each clock: `(An)+` and `-(An)` cost nothing extra and encode short. - A data register that the ALU writes and an EA unit then reads costs a @@ -80,8 +77,7 @@ the ALUs that own the data registers. Most cores run 2 pipes; 3 are planned. - The data cache does one read and one write per cycle. A loop of `add.l #1,memcounter` + `dbra` should run about 100 million times a second at 100 MHz: 100 million reads and 100 million writes, here to the same - address. Measured on Core 12556: 2 cycles per iteration, see - [caches-and-memory.md](caches-and-memory.md) (M, Core 12556, V4 UniCorn, `tools/v4/tests/add-mem-dbra`, 2026-11-09). + address. - One memory address is computed per cycle (one EAMEM in [pipeline-15-stages.md](pipeline-15-stages.md)). An instruction with two memory operands, such as `move.l (a0)+,(a1)+`, needs two addresses. A diff --git a/core/cpu-68080/fpu-performance-model.md b/core/cpu-68080/fpu-performance-model.md index 85da66e..49ab6c9 100644 --- a/core/cpu-68080/fpu-performance-model.md +++ b/core/cpu-68080/fpu-performance-model.md @@ -1,10 +1,10 @@ --- -title: 68080 FPU performance model (measured) +title: 68080 FPU performance model type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured] +basis: [core-developer] components: [cpu-68080] applies_to: core: "Core 12841" @@ -12,49 +12,22 @@ applies_to: tags: [68080, fpu, latency, throughput, scheduling, mac] related: - core/cpu-68080/prm/fpu-unit.md - - core/best-practices/fpu-schedule-by-completion-slot.md - - core/best-practices/fpu-when-it-pays.md sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 4.1" - "Gunnar (core developer), Simply 68080 coding guidelines, draft (2026-11-03)" - "Gunnar (core developer), answers on the guidelines, 2026-11-24" --- ## Summary -The FPU issues in order, one instruction per cycle, in pipe 1 only, and has -one result-write port. fmul has latency 5, fadd/fsub 6. The model below -predicted all 25 measured patterns exactly. +The 68080 FPU is pipelined. Expect about 6 cycles latency for fadd and fmul, +and unroll FPU code to cover it (G). ## Details -- Issue is in order, 1 FPU instruction per cycle, pipe 1 only. Integer - instructions pair in pipe 2 for free: 24 fmul + 24 add.l = 26 cycles (M). -- **One FP register write per cycle.** An instruction whose completion cycle - (issue + latency) is already taken stalls. -- Latencies: fmul 5, fadd/fsub 6, fmove load 1, fmove.x copy 1. `fmove.s`/`.d` - stores write no FP register and never collide. -- So the mix matters, not only the dependencies. Alternating fmul/fadd costs - 1.5 cycles per instruction. -- Measured patterns (L = load, M = mul, A = add), cycles per instruction: - - | Pattern | Cycles | - |---|---| - | MMA | 1.33 | - | LA | 1.17 | - | LMA, ALM, MAL | 1.0 | - | AML, MLA | 1.33 | - -- Best multiply-accumulate term order: `fmove.s coef,fpT` / `fmul.s mem,fpT` / - `fadd fpT,acc` = **3.13 cycles per term**. Other orders cost 3.5–4.5. An - integer operand (`fmove.l` / `fmul.l`) costs 4.0–5.1. -- The float MAC floor is 3 FPU instructions per term (about 33 M MAC/s at - 99 MHz). The integer MAC (`muls.l` + add/addx) measured 4.27 per term, with - a floor of 4.0. - Gunnar's rule (G): **a pipelined unit showing more than 1 cycle per instruction means the schedule is wrong.** - Gunnar's rule of thumb (G): expect about 6 cycles latency for fadd and - fmul, and unroll FPU code to cover it. The measured fmul latency is 5. + fmul, and unroll FPU code to cover it. - Current cores have the 8 FPU registers of the 68K (FP0–FP7), and FPU code is normal 68K code. Later cores will let the FPU use all 32 registers (G, 2026-11-24). This corrects an earlier note here that FPU work could @@ -62,16 +35,9 @@ predicted all 25 measured patterns exactly. ## Differences from AmigaOS / AROS / 68060 -- The 68881/68882 are not pipelined. The 68080 FPU accepts one instruction - per cycle, but only if enough independent chains are in flight (at least - 5 for fmul, 6 for fadd). -- The single write port is 68080 specific: instructions with different - latencies can collide even when they are independent. +- The 68881/68882 are not pipelined. The 68080 FPU is, so independent chains + in flight keep it busy. ## Do / Don't -- DO benchmark latency with 1 chain and throughput with at least "latency" - chains, and report both. -- DO schedule by completion slot, not only by dependency. -- DON'T expect FPU instructions to pair with each other: only integer - instructions pair with them. +- DO unroll FPU code into independent chains to cover the latency (G). diff --git a/core/cpu-68080/index.md b/core/cpu-68080/index.md index 69132ae..a1d1dc0 100644 --- a/core/cpu-68080/index.md +++ b/core/cpu-68080/index.md @@ -43,15 +43,13 @@ converted in [prm/](prm/index.md). | Key numbers: clock, pipes, caches, AttnFlags | [core-at-a-glance.md](core-at-a-glance.md) | | The real 15-stage pipeline | [pipeline-15-stages.md](pipeline-15-stages.md) | | Execution units (branch path, EA units, ALUs), 16-byte instruction groups | [execution-units.md](execution-units.md) | -| Second pipe, pairing, learning, fusing measured | [superscalar-issue.md](superscalar-issue.md) | +| Second pipe, pairing, learning | [superscalar-issue.md](superscalar-issue.md) | | Branch costs, prediction, predication | [branches-and-prediction.md](branches-and-prediction.md) | -| Cycle costs per instruction | [measured-instruction-costs.md](measured-instruction-costs.md) | | FPU performance model | [fpu-performance-model.md](fpu-performance-model.md) | | Cache lines, streaming, misses, alignment | [caches-and-memory.md](caches-and-memory.md) | | BANK prefix, E and B registers | [bank-prefix.md](bank-prefix.md) | | ISA notes beyond the PRM | [isa-notes-measured.md](isa-notes-measured.md) | | CCC and IEP counters | [performance-counters.md](performance-counters.md) | -| Core bugs, by core revision | [core-bugs-by-revision.md](core-bugs-by-revision.md) | Best practices and pitfalls for the 68080 are in `core/best-practices/` and `core/pitfalls/`. diff --git a/core/cpu-68080/isa-notes-measured.md b/core/cpu-68080/isa-notes-measured.md index e088e56..1e5725f 100644 --- a/core/cpu-68080/isa-notes-measured.md +++ b/core/cpu-68080/isa-notes-measured.md @@ -1,10 +1,10 @@ --- -title: 68080 ISA notes beyond the PRM (measured) +title: 68080 ISA notes beyond the PRM type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, official] +basis: [core-developer, official] components: [cpu-68080] applies_to: core: "Core 12841" @@ -23,7 +23,7 @@ sources: What the 68080 instruction set does in practice, where it adds to or corrects the PRM: no 64-bit integer arithmetic, no explicit 3-operand -integer form, instructions that do nothing, and 68060-style exception frames. +integer form, and 68060-style exception frames. ## Details @@ -32,24 +32,17 @@ integer form, instructions that do nothing, and 68060-style exception frames. `extub.l`/`extuw.l`, `move2`/`movz2 ,Da:Db` (memory only; movz2 is not on the V2), `movex`, `moveh`, `perm`, `touch`, `bcc.s+`, `dbcc.l`, `tex`, `rex`. -- `move2.l (An),Dx:Dy` loads both registers correctly on Core 12841 (on Core - 12001 the second was wrong) (M). - **LineA instructions** (`clr.q`, `mov3q`, `movs`, `movz`) are not yet implemented in any released core: don't use them. The manual lists them for cores 10280–10904 (official); those were a few unreleased test cores, for test purposes only (WDrijver). Use the fused pairs instead (`moveq #0` + `move.b`, `move.w` + `ext.l`). -- **abs/min/max/andn** (`$0E81 $20xx`) do nothing and raise no exception - (M). vasm still assembles them. - **No 64-bit integer arithmetic.** The "quad" add/sub described on the website does not exist. For 64-bit work, use AMMX or the 64-bit multiply. - **No explicit 3-operand integer form yet.** You get 3-operand behaviour through fusing. - `move sr,` and `movec Rc,Rn` (reads) work in user mode. A `movec` read does not sync the pipeline; a write waits. -- **PC-relative destination:** PC = the address of the destination's - extension word. It is computed wrongly after a full-extension-format - source, see [pc-relative-destination.md](../pitfalls/pc-relative-destination.md). - Shift and rotate register counts are taken modulo 64. - Exceptions use 68060-style frames. For divide by zero and `chk`, the frame PC points to the next instruction. @@ -60,12 +53,9 @@ integer form, instructions that do nothing, and 68060-style exception frames. - The 68000–68060 have no 64-bit integer arithmetic either; the 68080 does not add it, despite what some web pages suggest. -- abs/min/max/andn are accepted by vasm but have no effect: a silent bug, not - an illegal instruction trap. ## Do / Don't -- DON'T use LineA instructions, abs/min/max/andn, or the website's "quad" - add/sub. +- DON'T use LineA instructions or the website's "quad" add/sub. - DON'T rely on an emulator to test 68080-specific code. - DO expect 68060-style exception frames in handlers. diff --git a/core/cpu-68080/measured-instruction-costs.md b/core/cpu-68080/measured-instruction-costs.md deleted file mode 100644 index 94fd861..0000000 --- a/core/cpu-68080/measured-instruction-costs.md +++ /dev/null @@ -1,74 +0,0 @@ ---- -title: 68080 instruction costs measured on Core 12841 -type: reference -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured, official] -components: [cpu-68080] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, timing, cycles, multiply, bitfield, cache] -related: - - core/cpu-68080/prm/instruction-timing.md - - core/cpu-68080/prm/instruction-efficiency.md - - core/cpu-68080/fpu-performance-model.md - - core/pitfalls/multiply-and-bfffo-block-both-pipes.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 3" ---- - -## Summary - -Cycle costs measured with the CPU counters on trained loops. Several are -higher than the PRM states: multiply is about 3 cycles and blocks both pipes, -FP-to-integer conversion 3 cycles, a random cache miss about 27 extra cycles. - -## Details - -Method (M): `movec` CCC/IEP1/IEP2 in user mode, under `Disable()`, trained -loops, best of 5, Core 12841. - -| Operation | Cost | -|---|---| -| Simple ALU/EA operations | Up to 2 per cycle (2 pipes) | -| add/addx pairs (64-bit sums) | About 1 per cycle (addx in pipe 1 only) | -| `muls.l`/`mulu.l` 32 and 64-bit, `muls.w`, `mulu.w` | **3.04–3.13 cycles each, issue-bound** (same with 1 or 7 independent chains). Nothing pairs with it: mul + an independent op = 4.0–4.08. Result usable about 3 cycles later | -| mul + add/addx rounding chain | About 5–6 cycles per product | -| `bfextu` (memory or register) | 1.5 cycles throughput, pipe 1 only, latency 4 in an offset chain | -| `bfffo` (memory or register) | 3 cycles and **blocks both pipes**, latency 6 when it feeds the next offset | -| Mispredicted Bcc / RTS | About 7 / about 9.5 cycles (see [branches-and-prediction.md](branches-and-prediction.md)) | -| `bcc.s` over 1 instruction (predicated) | No penalty, whatever the pattern | -| Dependent indexed loads | About 4 cycles each | -| One memory access per cycle | 16 x `add.l d16(sp),Dn` = 15 cycles | -| Store then reload of the same slot | No extra penalty | -| `move2.l (An)+,d0:d4` in a muls-bound loop | 11 % slower than two `move.l (An)+` | -| fmul / fadd | Latency 5 / 6; 1 per cycle with at least 5 / 6 independent chains | -| FPU source conversion | Free for .s/.d/.x; about +1 latency for integer sizes (.l/.w) | -| `fmove.s`/`.d` FP to memory | 1 per cycle, pairs with integer instructions | -| `fmove.l`/`.w` FP to integer | 3.08 cycles, blocks both pipes | -| `movem` | 1 + n/2 (official) | -| `div` | Under 18 cycles (official). Divide by zero traps unless a NoMoreDiv0 patch is loaded | -| `move16` | 4 cycles, no alignment required (official). Never faster than aligned AMMX or quad moves (M) | -| `ori/andi #$800,sr` (Apollo bit, user mode) | About 8 cycles for the pair | -| D-cache hit (dependent load) | About 3.6–3.7 cycles | -| D-cache miss, random line (dependent load) | About 30 cycles in total, about 27 more than a hit. Independent random misses do not overlap: also 27 extra cycles each | -| Streaming cold reads, every long | 10.2 cycles per 64-byte line (about 6.2 bytes per cycle), about 1.2 cycles more than the same loop on warm data | -| One read per 64-byte line, sequential | 14.4 cycles (the prefetcher helps less with sparse reads) | -| One read per 128 bytes, sequential | 27.2 cycles, almost a random miss | - -## Differences from AmigaOS / AROS / 68060 - -- The PRM gives MUL = 2 or 3 cycles ([prm/instruction-timing.md](prm/instruction-timing.md)). - Measured: 3.04–3.13, and it blocks both pipes. -- The 68060 emulates 64-bit `muls.l`/`mulu.l` in software; the 68080 runs them - in hardware at the same cost as 32-bit. - -## Do / Don't - -- DO count multiply, `bfffo` and FP-to-integer conversion as about 3 cycles - that nothing pairs with. -- DO keep data that is read at random small and hot: every new line costs - about 27 cycles. -- DON'T use `move2` or `move16` for speed without measuring. diff --git a/core/cpu-68080/performance-counters.md b/core/cpu-68080/performance-counters.md index 488e4b6..66b8e3d 100644 --- a/core/cpu-68080/performance-counters.md +++ b/core/cpu-68080/performance-counters.md @@ -4,7 +4,7 @@ type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, official] +basis: [official, source-code] components: [cpu-68080] applies_to: core: "Core 12830-12841" @@ -13,18 +13,14 @@ tags: [68080, counters, ccc, iep, movec, benchmark] related: - core/cpu-68080/prm/integer/movec.md - core/cpu-68080/prm/optimizing.md - - core/pitfalls/turtle-mode-counters.md sources: - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 7.3 and 8.1" - - "lessons/2026-11-akb-verification.md" - - "lessons/2026-11-v4-turtle-mode.md" --- ## Summary The clock cycle counter (CCC, `$809`) and the per-pipe instruction counters -(IEP1–IEP3) are readable with `movec` in user mode. They are the most -reliable way to time code. The other event counters read 0 on release cores. +(IEP1–IEP3) are readable with `movec` in user mode. ## Details @@ -36,12 +32,7 @@ reliable way to time code. The other event counters read 0 on release cores. | `$80A` | IEP1 | Instructions issued in pipe 1 | | `$80B` | IEP2 | Instructions issued in pipe 2 | | `$00C` | IEP3 | Instructions issued in pipe 3 (0 on cores with 2 pipes) | -| `$808` | PCR | id `$0440`. Bit 0 = second pipe, bit 1 = FPU off. The core ignores PCR's ESS bit (M). Bits 7-6 = Turtle mode on Core 12856 (M), see below | - -- The debug and event counters (BPC/BPW, DCH/DCM `$80E/$80F`, - STR/STC/STB/MWR) read 0 on release cores (M). -- On Core 12830–12841 the counters are readable with `movec` in user mode. - CCC is too on Core 12556 (M, V4 UniCorn, `tools/v4/tests/`, 2026-11-09). +| `$808` | PCR | id `$0440`. Bit 0 = second pipe, bit 1 = FPU off | ### Reading the cycle counter @@ -49,7 +40,7 @@ reliable way to time code. The other event counters read 0 on release cores. movec ccc,a6 ; CCC ($809) before ; ... code to time ... movec ccc,d7 - sub.l a6,d7 ; cycles, stable to less than 1 % + sub.l a6,d7 ; cycles ``` vasm accepts the counter only by name: `movec ccc,d7` assembles to @@ -59,7 +50,6 @@ ApolloLib writes the instruction as `dc.w $4E7A,$x809` (SRC). - Measure under exec `Disable()`. - For whole-program timing, sum CCC deltas around each call in 64 bits: 32 bits wrap after about 43 s at 99 MHz. -- CCC was more reliable than EClock for benchmarks (M). - From GCC inline assembler, use GNU syntax: `.short 0x4e7a,0x0809` (`movec ccc,d0`), not `dc.w`. @@ -71,41 +61,14 @@ Run 6 independent `addq`/`subq` + `dbf`, 32001 turns (n instructions): - IEP3 ≥ n/16 and IEP1 + IEP2 < 7/8 n: 3 pipes. - Otherwise: 2 pipes. -In Turtle mode this test answers 1 pipe, see the next section. - -### In Turtle mode - -Measured on Core 12856 (M, V4 UniCorn, ApolloOS R10, 2026-11-25), with -`ApolloControl TU=n` set after a power cycle: - -| | TU=0 (off) | TU=3 (A4000) | TU=2 (A1200) | TU=1 (A500) | -|---|---|---|---|---| -| PCR | `$04400101` | `$04400141` | `$044001C1` | `$04400181` | -| CCC rate | 99.3 MHz | 99.3 MHz | 99.3 MHz | 99.3 MHz | -| IEP2 | counts | 0 | 0 | 0 | -| IEP1 per instruction | about 0.57 | 2.5 | 48 | 96 | -| Counted ALU loop, CCC | 1x | 4.5x | 89x | 177x | - -- CCC still counts time; Turtle makes each instruction take more cycles. -- Only one pipe issues, while PCR bit 0 stays 1. -- IEP1 counts about one per cycle (94-97 % of CCC), not instructions. -- Details and the Wrong/Right code: - [turtle-mode-counters.md](../pitfalls/turtle-mode-counters.md). - ## Differences from AmigaOS / AROS / 68060 - These counters are 68080 specific. `movec` reads of them work in user mode, unlike classic control registers. -- The PRM lists event counters (BPC, BPW, DCH, DCM, STR, STC, STB, MWR) that - read 0 on release cores. ## Do / Don't - DO time code with CCC, on trained loops, under `Disable()`. -- DO check PCR bits 7-6 (Turtle mode) before a benchmark, and log PCR with - the result. DON'T read IEP1 as an instruction count in Turtle mode. - DON'T measure in supervisor mode with interrupts off: a fault there gurus. -- DON'T write a register the loop uses while under `Disable()`: this hung the - V4 once. - DO probe an unknown core safely: install a temporary illegal-instruction trap first. Reading 0 means no counters. diff --git a/core/cpu-68080/pipeline-15-stages.md b/core/cpu-68080/pipeline-15-stages.md index 6c7f359..3f7f57a 100644 --- a/core/cpu-68080/pipeline-15-stages.md +++ b/core/cpu-68080/pipeline-15-stages.md @@ -4,7 +4,7 @@ type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, official] +basis: [core-developer, official] components: [cpu-68080] applies_to: core: "Core 12841" @@ -57,21 +57,16 @@ hazard unit, the D-cache read and the write FIFO. - **One memory address per cycle.** There is one EAMEM, shared by all pipes. Two loads in one cycle are impossible by design. The data cache does one read and one write per cycle, so a read-modify-write such as - `add.l #1,mem` runs at about 1 per cycle (G, 2026-11-03). Measured with - `dbra` on Core 12556: 2 cycles per iteration (M, see - [caches-and-memory.md](caches-and-memory.md)). + `add.l #1,mem` runs at about 1 per cycle (G, 2026-11-03). - **The ALU-to-EA bubble.** Addresses are computed at stage 8; an ALU result arrives at stage 11/12. A Dn produced by the ALU and used for an address by - a following instruction arrives 3–4 stages too late (M: write it about 4 - cycles earlier). A load into An used as an address waits the same way - (D-cache read at 10, register write at 12): load → indexed load measured - about 4 cycles (M). See [alu-to-ea-bubble.md](../pitfalls/alu-to-ea-bubble.md). + a following instruction arrives 3–4 stages too late. A load into An used + as an address waits the same way (D-cache read at 10, register write at + 12). See [alu-to-ea-bubble.md](../pitfalls/alu-to-ea-bubble.md). - **Load then use is cheap.** The D-cache read (10) sits right before the ALU (11), so a loaded value feeds the ALU without a bubble. -- **FPU and AMMX only in pipe 1.** Only decoder 1 feeds the FPU and AMMX. This - matches the counters: every FPU instruction counts in IEP1 (M). -- **Three ALUs, three EA units.** The hardware for 3 pipes is drawn; Core - 12798–12841 enables 2 (IEP3 = 0, M). +- **FPU and AMMX only in pipe 1.** Only decoder 1 feeds the FPU and AMMX. +- **Three ALUs, three EA units.** The hardware for 3 pipes is drawn. - **Write-through cache with write combining** (G). Writes go to memory through write combining and a write FIFO: for a few cycles the CPU collects writes, then commits them to the memory controller. That makes loops such @@ -95,13 +90,13 @@ hazard unit, the D-cache read and the write FIFO. - The PRM ([prm/pipeline.md](prm/pipeline.md)) lists 7 stages and a 2-cycle ALU-to-EA bubble. The diagram shows 15 stages. Gunnar counts the bubble as - 2 cycles and says it may grow in future cores (G, 2026-11-03); to hide it - fully, the measurements needed the Dn written about 4 cycles earlier (M). + 2 cycles and says it may grow in future cores (G, 2026-11-03). - The 68060's pipelines are not a model for the 68080: its EA and ALU stages and its memory port differ. ## Do / Don't -- DO compute addresses at least 4 cycles before use, or keep them in An. +- DO compute addresses well before use (the bubble is 2 cycles and may + grow, G), or keep them in An. - DON'T plan for two memory accesses in one cycle. - DON'T expect FPU or AMMX instructions in pipe 2. diff --git a/core/cpu-68080/superscalar-issue.md b/core/cpu-68080/superscalar-issue.md index 6e3afa6..8bfa225 100644 --- a/core/cpu-68080/superscalar-issue.md +++ b/core/cpu-68080/superscalar-issue.md @@ -1,10 +1,10 @@ --- -title: 68080 superscalar issue and pairing (measured) +title: 68080 superscalar issue and pairing type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, official] +basis: [core-developer, official] components: [cpu-68080] applies_to: core: "Core 12841" @@ -22,8 +22,8 @@ sources: ## Summary -On released V4 cores, two pipes issue instructions. The second pipe takes -short single-cycle instructions only, two instructions pair only when they +The second pipe takes short single-cycle instructions only, two +instructions pair only when they are independent (or fuse) and need at most one data-cache access, and pairing only starts on the second pass over the code. @@ -40,11 +40,7 @@ only starts on the second pass over the code. - Never in pipe 2: - addx, subx, negx (they need the flags from pipe 1, not ready mid-cycle); - bitfields; - - memory-indirect modes `([bd,An],Xn,od)`; - - all FPU instructions (M) and all AMMX instructions except stores (M). -- `jmp`/`jsr` to a PC-relative or abs.l target go to pipe 2. Through `(An)`, - `d16(An)` or `(d8,An,Xn)` they stay in pipe 1 and cost about +5 cycles (+6 - on Core 12840); `([An])` costs +7 (M). + - memory-indirect modes `([bd,An],Xn,od)`. ### Pairing conditions @@ -53,10 +49,6 @@ only starts on the second pass over the code. - Together they fit in one group of at most 16 bytes (some I-cache variants: 18) (G, 2026-11-03). See [execution-units.md](execution-units.md). - Together they need at most one data-cache access. -- Measured pairs with an independent `add.l` (M): `smi`, `extb.l`, `ext.l`, - `swap`, `asr/lsr #n`, `rol.l`, `move.w`, `move.b`, `eor`, `tst.b`, - `and.l #imm`, `moveq`, `neg`, `addq`, `cmp.l An,Dn`, indexed loads, - `move.l Dn,(An)+`. - `nop` is a pipeline barrier. ### Learning @@ -65,39 +57,12 @@ only starts on the second pass over the code. pass of a loop, the other pipe is used. - Straight-line code that runs once (init code, a single table pass) never pairs. -- Routines called many times pair fine: 2048 straight `add`s, called - repeatedly, ran at about 1.9 IPC (M). - -### Fusing, measured - -The PRM's fusing table holds, with these measurements (M, Core 12841): - -- 16 instructions of `move.l dn,dm` + `add.l` ran in 5.1 cycles when adjacent - and 9.1 cycles when split apart. The same pair with E registers fused at 1 - per cycle. -- `subq.l #1,dn` + `bne.s/.s+/.w` fuses; `bpl` does not. -- `moveq #0,dn` + `move.b/w (ea),dn` fuses into a zero-extending load. -- FPU: `fmove.x fpn,fpm` + `fmul.x`/`fadd.x fpx,fpm` fuses (registers only) - with correct values and FPSR flags. Cycles per pair, adjacent / split: - - | | Independent pairs | Dependent chain | - |---|---|---| - | fmul | 1.12 / 2.25 | 5.00 / 6.00 (fuses) | - | fadd | 1.12 / 2.62 | 6.00 / 7.00 (fuses) | - | fsub | 2.62 / 2.62 | 7.00 / 7.00 (does not fuse; results still right) | - -- IEP1/IEP2 count a fused FPU pair as 2 instructions: detect FPU fusing with - CCC, not with IEP. -- Two fused `move.l (an)+,(am)+` read 8 bytes before writing. See - [fused-copy-overlap.md](../pitfalls/fused-copy-overlap.md). ## Differences from AmigaOS / AROS / 68060 - The PRM ([prm/superscalar.md](prm/superscalar.md)) describes three pipes - (Anton, Bruno, Cesar). Released cores up to 12841 enable two (M). + (Anton, Bruno, Cesar). - Unlike the 68060, the 68080 pairs only after it has seen the code once. -- `fsub` does not fuse, although it is an FPU arithmetic instruction like - fadd and fmul. ## Do / Don't @@ -105,7 +70,3 @@ The PRM's fusing table holds, with these measurements (M, Core 12841): - DO write the copy and the operation next to each other (`move.l d0,d1` + `add.l d2,d1`): they fuse into one 3-operand instruction. - DON'T put `nop` in hot code: it is a pipeline barrier. -- DON'T call through `(An)` or `d16(An)` in hot code when a PC-relative or - absolute target works: it costs about 5 cycles more. -- DON'T use `fsub` in a 3-operand fused pair: negate the operand and use - `fadd`. diff --git a/core/pitfalls/alternating-branch-mispredicted.md b/core/pitfalls/alternating-branch-mispredicted.md deleted file mode 100644 index e01ecf4..0000000 --- a/core/pitfalls/alternating-branch-mispredicted.md +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: A branch that alternates every iteration is always mispredicted -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [cpu-68080] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, branches, prediction, misprediction] -related: - - core/cpu-68080/branches-and-prediction.md - - core/best-practices/predicated-bcc-over-one-instruction.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 0 (rule 5) and 2.6" ---- - -## Symptom - -A loop with a branch that goes taken, not taken, taken, not taken runs -slower than the same loop with random branch directions: about 7 extra -cycles per iteration. - -## Cause - -The 68080 branch predictor does not learn a strict alternation: it -mispredicts it every time. A mispredicted Bcc costs about 7 cycles. - -Loop benchmarks hide a related problem: a size-dispatch branch is -unpredictable when the sizes in real use are random, but predictable in a -benchmark with a fixed size. - -## Wrong - -```asm -loop: - btst #0,d7 ; flips every iteration - beq.s .even - ; ... odd case, more than one instruction ... - bra.s .next -.even: - ; ... even case ... -.next: - dbra d7,loop -``` - -## Right - -- Unroll by 2, so each copy handles one case without a branch. -- Or compute the value without a branch. -- Or, if one case is a single short single-cycle instruction, use a - predicated `bcc.s` over it (see - [predicated-bcc-over-one-instruction.md](../best-practices/predicated-bcc-over-one-instruction.md)). - -## Detection - -Look for branches on a loop counter bit or on toggling state. Benchmark -dispatch code with random sizes, and pull the small cases out first. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| Alternating pattern: 10.5 cycles per turn vs 3.0 always taken, 7.0 random | (M) | Core 12841 | `beq` over 2 instructions, 65536 branches, CCC, median of 7 | -| Mispredicted Bcc costs about 7 cycles | (M) | Core 12841 | Same | diff --git a/core/pitfalls/alu-to-ea-bubble.md b/core/pitfalls/alu-to-ea-bubble.md index 0fdc0ec..b632cfd 100644 --- a/core/pitfalls/alu-to-ea-bubble.md +++ b/core/pitfalls/alu-to-ea-bubble.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, official] +basis: [core-developer, official] components: [cpu-68080] applies_to: core: "Core 12841" @@ -23,7 +23,7 @@ sources: ## Symptom Code that computes an index or address in a data register and uses it right -away runs 2–3 cycles slower per use than expected, and the instructions +away runs about 2 cycles slower per use than expected (G, official), and the instructions paired with it wait too. It is the most common hidden cost on the 68080. ## Cause @@ -66,15 +66,15 @@ Other fixes: unit: then the mode is safe and good (G). Use an address register as the index counter and step it with `addq`, `adda` or `lea`. - Write `clr.l (a0)+`, or use `(a0,a1)` + `addq.l #4,a1`. -- Compute offsets at least 4 cycles (about 8 paired instructions) before - use, or have the caller pass ready-made pointers loaded straight into An. +- Compute offsets well before use (at least 2 cycles; up to 12 instructions + on a core with 3 pipes and fusing, G), or have the caller pass ready-made + pointers loaded straight into An. - Test an An with `tst.l An` or `move.l An,Dn`. ## Detection Look for a Dn written by an ALU instruction and used as an index, base or -bitfield offset within the next few instructions. Measure with CCC: a chain -that costs 3 or more cycles per link instead of 1 points here. +bitfield offset within the next few instructions. ## Evidence @@ -83,9 +83,3 @@ that costs 3 or more cycles per link instead of 1 points here. | ALU to EA costs a bubble of 2 cycles | (official) PRM pipeline page | any | Manual | | A Dn written 3 cycles before the EA use gives a 2-cycle bubble; future cores may make it longer, so always avoid it | (G) | any | Statement, 2026-11-03 | | An indexed mode is safe when the ALU last changed its registers 2 cycles ago (up to 12 instructions on a core with 3 pipes and fusing) | (G) | any | Coding guidelines draft | -| Adjacent: +2 to 3 cycles; 4 paired fillers: +2; 6: +1; 8 or more: 0 | (M) | Core 12841 | Producer + consumer with fillers, CCC | -| add → `(a,d0)` load → add: 3 cycles per link | (M) | Core 12841 | Chain, CCC | -| load → indexed load: 4 cycles per link | (M) | Core 12841 | Chain, CCC | -| add d0 → `bfextu (a0){d0:w}` → add: 5 cycles per link | (M) | Core 12841 | Chain, CCC | -| A table lookup whose index was just computed: about 5.4 cycles per iteration | (M) | Core 12841 | Hot loop, CCC | -| Keeping values in a3–a6 inside generated arithmetic code cost about 6 % (992 vs 931 cycles, IMDCT) | (M) | Core 12841 | CCC | diff --git a/core/pitfalls/ammx-pc-relative-source.md b/core/pitfalls/ammx-pc-relative-source.md deleted file mode 100644 index d4a1f65..0000000 --- a/core/pitfalls/ammx-pc-relative-source.md +++ /dev/null @@ -1,57 +0,0 @@ ---- -title: AMMX PC-relative sources read 2 bytes early -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [cpu-68080, toolchain] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, ammx, pc-relative, vasm, bug] -related: - - core/cpu-68080/prm/ammx/ammx-format.md - - core/cpu-68080/core-bugs-by-revision.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 6 and 9.4" ---- - -## Symptom - -An AMMX instruction with a PC-relative source (`load .k(pc),d0`, -`paddw .k(pc),...`) reads data 2 bytes before the label. - -## Cause - -vasm counts the displacement from the third word of the instruction; the -core counts it from the second word. The two disagree by 2 bytes. The bug is -open on Core 12841. - -## Wrong - -```asm - load .k(pc),d0 ; reads .k - 2 - ; ... -.k: dc.w $0001,$0002,$0003,$0004 -``` - -## Right - -Load the address into a register first: - -```asm - lea .k(pc),a0 - load (a0),d0 -``` - -## Detection - -Search for AMMX instructions with a `(pc)` source operand. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| PC-relative AMMX sources read 2 bytes early | (M) | Core 12841 | Test program, 2026-10-30 | -| vasm counts from the third word, the core from the second | (M) | Core 12841 | Comparing vasm output with core behaviour | diff --git a/core/pitfalls/ammx-separate-load-and-store.md b/core/pitfalls/ammx-separate-load-and-store.md index ea90ec9..fb22077 100644 --- a/core/pitfalls/ammx-separate-load-and-store.md +++ b/core/pitfalls/ammx-separate-load-and-store.md @@ -18,8 +18,6 @@ related: - core/cpu-68080/prm/ammx/pack3216.md - core/cpu-68080/prm/ammx/loadi.md - core/cpu-68080/prm/ammx/storei.md - - core/pitfalls/ammx-pc-relative-source.md - - core/best-practices/ammx-where-it-wins.md - core/best-practices/fewer-and-shorter-instructions.md - toolchain/pitfalls/vasm-68080-encoding-issues.md sources: @@ -88,9 +86,6 @@ An immediate is an operand too: ### Exceptions - **A value used by several instructions:** load it once into a register. -- **PC-relative sources** read 2 bytes early on Core 12841 (see - [ammx-pc-relative-source.md](ammx-pc-relative-source.md)): use - `lea .k(pc),a0` and an `(a0)` source. - **Immediates in vasm 2.0g:** the PRM's short form `#imm.W` (a word repeated into all four words, 6-byte instruction) is written with a `.w` suffix on the mnemonic: `paddb.w #$0101,d1,d2`. Without the suffix, diff --git a/core/pitfalls/ammx-upper-32-bits.md b/core/pitfalls/ammx-upper-32-bits.md deleted file mode 100644 index 08d6ef3..0000000 --- a/core/pitfalls/ammx-upper-32-bits.md +++ /dev/null @@ -1,68 +0,0 @@ ---- -title: 32-bit writes can clear the upper half of a 64-bit register -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [core-developer, measured] -components: [cpu-68080] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, ammx, e-registers, 64-bit, move, moveq, bug] -related: - - core/cpu-68080/prm/programming-model.md - - core/cpu-68080/bank-prefix.md - - core/cpu-68080/core-bugs-by-revision.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 6" - - "Gunnar (core developer), move.l must keep the upper 32 bits, 2026-10-30" ---- - -## Symptom - -An AMMX operation on a D or E register that was last written with -`move.l #imm` sees zeros in the upper 32 bits, but only on trained passes of -a loop. - -## Cause - -`move.l` must keep the upper 32 bits of a D or E register untouched (G, -2026-10-30). On Core 12841: - -- `move.l Dn,Dn` and `move.l (An),Dn` keep them; -- `move.l #imm` (D or E register) clears them on trained passes (bug, - regression test "test-upper"); -- `moveq`, `ext.l` and `extb.l` behave like `move.l #imm`, and a banked - `moveq` changes from pass to pass; -- `clr.l` always keeps them. - -Whether `moveq`, `ext` and `clr` should follow the `move.l` rule has been -asked of the core developer. - -## Wrong - -```asm - load.w #$1111,e0 ; e0 = $1111111111111111 - move.l #$22222222,e0 ; upper half may become 0 when trained - paddw e0,d1,d2 ; uses all 64 bits -``` - -## Right - -Write all 64 bits with an AMMX instruction (`load`, `peor`, or another AMMX -op) before any 64-bit use, and don't rely on a 32-bit write leaving the upper -half alone. - -## Detection - -Look for 32-bit writes (`move.l #imm`, `moveq`, `ext.l`, `extb.l`) to -registers that AMMX code later reads as 64 bits. Test over several passes: -the cold pass hides the bug. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| `move.l` must keep the upper 32 bits | (G, 2026-10-30) | any | Statement | -| `move.l #imm`, `moveq`, `ext.l`, `extb.l` clear them on trained passes; `clr.l` keeps them | (M) | Core 12841 | Regression test "test-upper" | diff --git a/core/pitfalls/bank-prefix-pitfalls.md b/core/pitfalls/bank-prefix-pitfalls.md index 6e71c69..6f6dfb0 100644 --- a/core/pitfalls/bank-prefix-pitfalls.md +++ b/core/pitfalls/bank-prefix-pitfalls.md @@ -1,10 +1,10 @@ --- -title: BANK prefix traps (single operands, unsupported instructions, B registers) +title: BANK prefix traps (single operands, unsupported instructions) type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, official] +basis: [official] components: [cpu-68080, toolchain] applies_to: core: "Core 12830-12841" @@ -20,35 +20,22 @@ sources: ## Symptom -Code with E registers silently uses a plain D register instead: `tst e6` -tests d6, `add.l e6,d1` computes d6 + d6, or a loop gives the right result on -its first pass and the wrong one when trained. +Code with E registers silently uses a plain D register instead, or gives a +wrong result. ## Cause - For a single-register operand (tst, clr, neg, not, ext, swap, scc, bitfields, the dbcc counter) and for `#imm,Rn`, both bank fields must be - set: AA = BB (official). With AA alone the plain Dn is used; with BB alone - the cold pass looks right, but in a trained loop pipe 2 reads the plain Dn. -- **vasm 2.0f/2.0g puts single operands in AA only**, so `tst e6` silently - becomes `tst d6`. For `add.l #imm,En` it sets BB only (`$7101`), which - writes plain Dn + imm into En. + set: AA = BB (official). - Banking does not work yet for add, sub, and, or, cmp, addx, subx, mul, - div, abcd, sbcd, pack, unpk, exg, bfextu, bfexts, bfins (official list, - confirmed on Core 12830/12840). -- `cmp.l En,Dn` uses the plain Dn on the first two passes and the right En - from the third pass on (Core 12841). -- `add.l Bn,Dn` and `move.l An,Bn` are not supported B-register forms. vasm - 2.0g rejects `move.l a0,b1` and turns `add.l b1,d0` into `$71F1`, a BANK - word with SS ≠ 0, which is illegal. + div, abcd, sbcd, pack, unpk, exg, bfextu, bfexts, bfins (official list). ## Wrong ```asm - tst.l e6 ; vasm: AA only -> tests d6 - add.l #1,e3 ; vasm: BB only -> e3 = d3 + 1 - add.l e6,d1 ; banking not supported -> d1 = d6 + d6 ... wrong - cmp.l e2,d0 ; plain d0 on cold passes + add.l e6,d1 ; banking not supported for add + cmp.l e2,d0 ; banking not supported for cmp ``` ## Right @@ -58,20 +45,15 @@ its first pass and the wrong one when trained. for `add.l #imm,En`. - Do arithmetic and compares in a plain Dn: move the E register into a Dn, operate, move it back. -- Use only the supported B-register forms (see - [bank-prefix.md](../cpu-68080/bank-prefix.md)). ## Detection Decode every hand-encoded `dc.w` with an 080-aware disassembler and check its length. Check vasm listings (`-L`) for BANK words on single-operand and -`#imm` instructions. Test banked code over several passes: the cold pass -hides the error. +`#imm` instructions. ## Evidence | Claim | Source | Core | Method | |---|---|---|---| | AA = BB for single operands; list of instructions where banking is not handled correctly | (official) PRM, BANK and integer-unit pages | any | Manual | -| BB alone fails in trained loops; `add.l e6,d1` = d6 + d6; `cmp.l En,Dn` wrong on cold passes | (M) | Core 12830-12841 | Regression tests, cold and trained passes | -| vasm 2.0f/2.0g encodes single operands with AA only, `add.l #imm,En` with BB only | (M) | any | vasm listings | diff --git a/core/pitfalls/cacr-data-cache-bit-ignored.md b/core/pitfalls/cacr-data-cache-bit-ignored.md deleted file mode 100644 index 3372b9b..0000000 --- a/core/pitfalls/cacr-data-cache-bit-ignored.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: Clearing the data-cache enable bit does not turn the data cache off -type: pitfall -owner: WDrijver -status: draft -origin: ai-assisted -basis: [measured] -components: [cpu-68080] -applies_to: - core: "Core 12856" - os: [any] -tags: [68080, cache, cacr, cachecontrol, enabled, data-cache] -related: - - core/cpu-68080/caches-and-memory.md - - core/pitfalls/self-modifying-code-and-caches.md -sources: - - "Hardware test tools/v4/tests/dcache-enable-bit, V4 UniCorn, Core 12856, ApolloOS R10, 2026-11-17" ---- - -## Symptom - -- Code clears the data-cache enable bit and expects uncached reads. Reads - still hit the cache and stay just as fast. -- Tools that show the data cache state from `CacheControl()` or CACR report - "data cache off" while the data cache is in use. - -## Cause - -- CACR bit 31 (DE, `CACRF_EnableD` through `CacheControl()`) can be written and - read back: the raw CACR changes from `$00008000` to `$80008000` and back. -- Load latency does not change with it. A dependent load that hits a 64 KB - buffer costs 3 cycles with the bit clear or set. A 4 MB buffer that cannot - fit costs about 28.6 cycles per load (M). -- So the core keeps its data cache on whatever the bit says. - -## Wrong - -```c -/* Read a buffer uncached, e.g. to see what a bus master wrote. */ -ULONG old = CacheControl(0, CACRF_EnableD); /* "data cache off" */ -check(buffer); /* may still read cached lines */ -CacheControl(old, CACRF_EnableD); -``` - -## Right - -Do not rely on the enable bit for uncached access or to slow a program -down. Assume the data cache is always on. Whether `CachePreDMA()` / -`CachePostDMA()` or `CacheClearE()` keep data written by other bus masters -coherent on the 68080 is not covered by this measurement. - -## Detection - -Search for `CACRF_EnableD`, `CacheControl(` with a mask that includes it, -and `movec` writes to `cacr` that clear bit 31. Measure with -`tools/v4/tests/dcache-enable-bit`. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| CACR bit 31 is writable and reads back | (M) 2026-11-17 | Core 12856, V4 UniCorn | `tools/v4/tests/dcache-enable-bit`: raw CACR found `$00008000`, after `CacheControl(CACRF_EnableD, CACRF_EnableD)` `$80008000`, restored `$00008000` | -| Bit 31 does not change data-load latency | (M) 2026-11-17 | Core 12856, V4 UniCorn | Same test, under `Disable()`: pointer chase, one load per 64-byte line in random order, 16384 loads, best of 8: 49161 cycles as found (bit clear), with `CacheControl(0, CACRF_EnableD)`, and with the bit set; 5 runs, identical | -| The test can see a cache miss | (M) 2026-11-17 | Core 12856, V4 UniCorn | Same chase over 4 MB: 468071–470680 cycles (about 28.6 per load against 3 per load in 64 KB) | -| A sequential sum is not a valid test | (M) 2026-11-17 | Core 12856, V4 UniCorn | A 4-long unrolled sum of 64 KB vs a 4 MB stream: 28702 vs 28680 cycles per 64 KB. Prefetch hides the misses, so equal timings there prove nothing about the cache | diff --git a/core/pitfalls/double-memory-indirect.md b/core/pitfalls/double-memory-indirect.md index 85e400b..34f6ce1 100644 --- a/core/pitfalls/double-memory-indirect.md +++ b/core/pitfalls/double-memory-indirect.md @@ -4,7 +4,7 @@ type: pitfall owner: WDrijver status: reviewed origin: ai-assisted -basis: [core-developer, measured, source-code] +basis: [core-developer, source-code] components: [cpu-68080] applies_to: core: "any" @@ -88,4 +88,3 @@ It was removed on 2026-11-04 (see | In instructions other than `jmp`/`jsr` it is an ALU-to-EA stall by definition | (G) | any | Statement, 2026-11-03 | | `jmp`/`jsr` through it are fine; GCC may generate them | (G) | any | Statement, 2026-11-03 | | GCC 6.5 `-O2` emits it in data accesses (28 of 110 in Lua's `lvm.c`) | (SRC) | any | Generated assembly, 2026-11-04 | -| `jmp`/`jsr ([An])` costs about +7 cycles against an absolute or PC-relative target | (M) | Core 12841 | CCC, see superscalar-issue.md | diff --git a/core/pitfalls/fpu-47-bit-context-save.md b/core/pitfalls/fpu-47-bit-context-save.md index 9facb06..a832312 100644 --- a/core/pitfalls/fpu-47-bit-context-save.md +++ b/core/pitfalls/fpu-47-bit-context-save.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, official] +basis: [core-developer, official] components: [cpu-68080] applies_to: core: "Core 12830-12841" @@ -12,7 +12,6 @@ applies_to: tags: [68080, fpu, fmovem, context-switch, precision, double] related: - core/cpu-68080/prm/fpu/fmovem.md - - core/best-practices/fpu-when-it-pays.md sources: - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 0 (rule 11) and 4.2" - "Gunnar (core developer), new FMOVEM encoding, 2026-10-30" @@ -43,8 +42,7 @@ Apollo extended layout ([prm/fpu/fmovem.md](../cpu-68080/prm/fpu/fmovem.md)). ## Right - Keep exact integer arithmetic in doubles at 47 significant bits or less. -- Don't use the `1.5*2^52` trick; convert with `fmove.l` in RZ mode instead - (see [fpu-float-to-integer-conversion.md](fpu-float-to-integer-conversion.md)). +- Don't use the `1.5*2^52` trick. - Exchange values through memory with `fmove.d`, which keeps all bits. Gunnar (G, 2026-10-30): a new `FMOVEM` in the 3-operand encoding will save @@ -62,5 +60,4 @@ significant bits. | Claim | Source | Core | Method | |---|---|---|---| | Apollo extended format in memory differs from Motorola's | (official) PRM, FMOVEM page | any | Manual | -| About 3150 changed values per 20 M checks in a busy loop; values of 47 bits or less never change | (M) | Core 12830-12841 | Busy-loop check | | New 64-bit FMOVEM in the 3-operand encoding planned | (G, 2026-10-30) | Future core | Statement | diff --git a/core/pitfalls/fpu-broken-instructions.md b/core/pitfalls/fpu-broken-instructions.md deleted file mode 100644 index dd5c19a..0000000 --- a/core/pitfalls/fpu-broken-instructions.md +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: FPU instructions that give wrong results on Core 12841 -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [core-developer, measured] -components: [cpu-68080] -applies_to: - core: "Core 12001-12841" - os: [any] -tags: [68080, fpu, fscc, ftrapcc, flognp1, fmovem, fmove, fdbcc, bugs] -related: - - core/cpu-68080/core-bugs-by-revision.md - - core/pitfalls/fpu-precision-and-rounding.md - - core/cpu-68080/prm/fpu/fdbcc-l.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 4.2 (bugs first reported by Morten on Core 12001, rechecked on Core 12841)" ---- - -## Symptom - -Some FPU instructions run without an exception but do the wrong thing: an -extension word runs as an instruction, a trap ignores the flags, a function -returns a different function, or memory operands are read partly. - -## Cause - -Core bugs or unsupported forms, still present on Core 12841 unless noted: - -| Instruction | What happens | -|---|---| -| `FScc` to `d16(An)` or `d8(An,Xn)` | The byte is stored, then the extension word runs as an instruction. `fst 95(a0)` leaves `$005F`, which runs as `ori.b #x,(a7)+` and hangs | -| `FTRAPcc` | Ignores the FPU flags: conditions 0, 3, 4, 7, 8, A, C and F always trap (vector 7), the others never do | -| `flognp1` | Returns ln(x), not ln(1+x): `flognp1 0.5` = −0.693 | -| `fmovem.x` with a dynamic list (`fmovem.x Dn,` / `,Dn`) | Not supported (G), as on the 68060. No exception: the store writes wrong values, the load leaves the registers unchanged | -| `fmove.x` load of a 12-byte Motorola value | Ignores the low long of the mantissa: about 32 bits (1+2^−40 loads as 1.0) | -| `fmove.x` store to memory | Writes only the first 8 bytes; the third long is left untouched | -| `FDBcc` (Core 12830 and 12840 only) | Never decremented and always branched. Fixed in Core 12841 | - -## Wrong - -```asm - fseq 95(a0) ; extension word runs as an instruction - ftrapeq ; trap decision ignores the compare - fmovem.x d0,-(sp) ; dynamic list: wrong values - fmove.x fp0,(a1) ; stores 8 of 12 bytes -``` - -## Right - -- `FScc` to `Dn`, `(An)`, `(An)+` or `-(An)`, which work. -- `FBcc` instead of `FTRAPcc` (FBcc is correct). -- `fadd #1` + `flogn` instead of `flognp1` (mind the precision). -- A static register list in `fmovem`. -- `fmove.d` to exchange values with memory. -- Avoid `FDBcc` on cores before 12841. - -## Detection - -Search the source and the disassembly for FScc with displacement modes, -FTRAPcc, flognp1, dynamic fmovem lists and `fmove.x` memory operands. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| Dynamic fmovem lists are not supported, as on the 68060 | (G) | any | Statement | -| FScc, FTRAPcc, fmove.x behaviour as in the table | (M) | Core 12001, rechecked Core 12841 | FPU test suite | -| `flognp1` returns ln(x) | (M) | Core 12841 | Found while rechecking | -| FDBcc fixed: word and long counters, all conditions | (M) | Core 12841 | FPU test suite | diff --git a/core/pitfalls/fpu-exceptions-never-trap.md b/core/pitfalls/fpu-exceptions-never-trap.md deleted file mode 100644 index 855fc7c..0000000 --- a/core/pitfalls/fpu-exceptions-never-trap.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: FPU exceptions never trap and FPSR exception bytes stay 0 -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [cpu-68080] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, fpu, exceptions, fpsr, fpcr, divide-by-zero] -related: - - core/pitfalls/fpu-broken-instructions.md - - core/pitfalls/fpu-precision-and-rounding.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 4.2" ---- - -## Symptom - -Code that enables FPU exception traps in FPCR (DZ, OPERR, INEX2) never sees -a trap, and code that checks the FPSR exception or accrued bytes never sees -an error. - -## Cause - -On Core 12841 FPU exceptions never trap, even with the FPCR enable bits set. -In FPSR, only the condition byte (N, Z, I, NAN) is ever set. The exception -byte, the accrued byte and the `fmod`/`frem` quotient byte stay 0. There is -no packed decimal format either. - -## Wrong - -```asm - fmove.l #$00000400,fpcr ; enable divide-by-zero trap - fdiv.x fp1,fp0 ; fp1 = 0: no trap - fmove.l fpsr,d0 - btst #4,d0 ; accrued DZ: always 0 -``` - -## Right - -Test the result itself with `fcmp`/`ftst` + `FBcc`: - -```asm - fdiv.x fp1,fp0 - fbun.w .nan ; NAN result (condition byte NAN bit) - fmove.l fpsr,d0 - btst #25,d0 ; condition byte I bit: result is infinity - bne.s .inf -``` - -## Detection - -Search for writes to FPCR enable bits, FPSR exception or accrued byte tests, -and uses of the `fmod`/`frem` quotient byte. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| DZ, OPERR and INEX2 traps never taken with the FPCR enable bits set | (M) | Core 12841 | FPU test suite | -| Only the FPSR condition byte is ever set | (M) | Core 12841 | Same | diff --git a/core/pitfalls/fpu-float-to-integer-conversion.md b/core/pitfalls/fpu-float-to-integer-conversion.md deleted file mode 100644 index d7c56a1..0000000 --- a/core/pitfalls/fpu-float-to-integer-conversion.md +++ /dev/null @@ -1,73 +0,0 @@ ---- -title: FP-to-integer conversion rounds wrongly except in RZ mode -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [cpu-68080] -applies_to: - core: "Core 12830-12841" - os: [any] -tags: [68080, fpu, fmove, rounding, conversion, fpcr] -related: - - core/cpu-68080/prm/fpu/fmove-dn.md - - core/cpu-68080/prm/fpu/fmoverz.md - - core/pitfalls/multiply-and-bfffo-block-both-pipes.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 4.2" ---- - -## Symptom - -`fmove.l` from FP to an integer gives off-by-one results in round-to-nearest, -round-down and round-up modes: 4678528.501 becomes 4678528 in RN, −0.1 -becomes 0 in RM, 0.1 becomes 0 in RP. - -## Cause - -`fmove.l` decides the rounding from only the 2 bits below the binary point; -the sticky bit is lost. RZ (round toward zero) is always right, and exact -integers always convert right. - -Related behaviour: - -- `fmove.w` FP to integer follows the FPCR rounding mode correctly (RN - half-even, RZ, RM, RP) and **saturates** to 32767/−32768 without OPERR. -- `fmoveurz.l` of 3000000000.75 gives `$FFFFFFFF`. -- `fmoverz`/`fmoveurz` do not exist on the V2. -- Default task FPCR seen: `$0` or `$10`. - -## Wrong - -```asm - fmove.l #0,fpcr ; RN - fmove.l fp0,d0 ; 4678528.501 -> 4678528 -``` - -## Right - -```asm - fmove.l #$10,fpcr ; RZ: always correct (floor for positive values) - fmove.l fp0,d0 -``` - -- Convert values that have a fraction only in RZ mode. For round-to-nearest, - add 0.5 first (positive values) and convert in RZ. -- For 16-bit PCM output, `fmove.w` with FPCR = 0 (RN) is correct and - saturates: handy, and set FPCR explicitly around the routine. -- Set FPCR explicitly when your routine depends on it; don't rely on the task - default. - -## Detection - -Test conversions of values just above .5 and small negative and positive -fractions in each rounding mode. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| RN 4678528.501 → 4678528; RM −0.1 → 0; RP 0.1 → 0; RZ always right | (M) | Core 12830-12841 | Conversion tests | -| `fmove.w` follows FPCR and saturates without OPERR | (M) | Core 12830-12841 | Same | -| `fmoveurz.l` 3000000000.75 → `$FFFFFFFF` | (M) | Core 12830-12841 | Same | diff --git a/core/pitfalls/fpu-precision-and-rounding.md b/core/pitfalls/fpu-precision-and-rounding.md index 643917f..e2adcab 100644 --- a/core/pitfalls/fpu-precision-and-rounding.md +++ b/core/pitfalls/fpu-precision-and-rounding.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, official] +basis: [core-developer, official] components: [cpu-68080] applies_to: core: "Core 12841" @@ -12,8 +12,6 @@ applies_to: tags: [68080, fpu, precision, rounding, fdiv, fsqrt, transcendental] related: - core/cpu-68080/prm/fpu-unit.md - - core/pitfalls/fpu-float-to-integer-conversion.md - - core/pitfalls/fpu-broken-instructions.md sources: - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 4.2" - "Gunnar (core developer), FPU precision targets, 2026-10-30" @@ -22,46 +20,27 @@ sources: ## Symptom Floating-point results differ from a 68881/68882 or from C on another -platform: transcendentals are accurate to about 32 bits, `fdiv` and `fsqrt` -to about 33–42 bits, `fadd` is 1 ulp low, single-precision instructions -return double results, and `fint` rounds ties away from zero. +platform: `fdiv` and `fsqrt` are less precise than a double. ## Cause Precision is a design choice (G, 2026-10-30): most games need 23 bits, and more precision costs cycles and FPGA space. The targets are full 64 bits on -`fmul` and `fadd`, and about 40 bits on `fsqrt` and `fdiv`. Measured on Core -12841: +`fmul` and `fadd`, and about 40 bits on `fsqrt` and `fdiv`. -| Operation | Behaviour | -|---|---| -| `fmul` | Correctly rounded | -| `fadd` | Rounds toward zero: 1 ulp low when the exact sum needs rounding up (0.1 + 0.2 = `...3333`, not `...3334`). Asked whether intended | -| FPU arithmetic and `fmove.s` stores | Truncate, whatever the FPCR mode. `fmove.s` differs from C round-to-nearest by 1 ulp | -| `fdiv` | 40.6–41.8 good bits (1/3 = `$3FD5555555555000`, about 1400 ulp) | -| `fsqrt` | 32.6–36.4 good bits (sqrt 2 = `$3FF6A09E66800000`); exact squares are exact | -| Transcendentals (fsin, fcos, ftan, fasin, facos, fatan, fsinh, fcosh, ftanh, fatanh, fetox, ftwotox, ftentox, flogn, flog10, flog2) | About 31–33 good bits (10^5 to 4x10^6 ulp) on ordinary arguments; only tiny arguments come out exact | -| FPCR rounding precision, and `fs*`/`fd*` (`fsmove`, `fsmul`, `fsadd`, `fsdiv`, `fssqrt`) | Ignored: all return the double result | -| `fint` in RN | Ties away from zero: 2.5 → 3, −2.5 → −3, 0.5 → 1 (68881: 2, −2, 0) | -| `fmovecr` | Within 1 ulp, truncated. 1e512 to 1e4096 (`$3C`–`$3F`) give +inf: they do not fit in a double | -| Older cores (official) | Older V4 cores use 11 nibbles of fraction; V2 core 2.17 about 8 | +Older V4 cores use 11 nibbles of fraction; V2 core 2.17 about 8 (official). ## Wrong ```asm fmove.d #2.0,fp0 fsqrt.x fp0 ; assumes 53 correct bits - fsmul.x fp1,fp0 ; assumes single-precision rounding ``` ## Right -- Add a Newton step after `fsqrt`/`fdiv` when you need more than about 33/40 +- Add a Newton step after `fsqrt`/`fdiv` when you need more than about 40 bits. -- Use your own polynomial or table for transcendentals when you need 53 - bits. -- Round to single with an `fmove.s` store and reload. -- Use your own rounding when `fint` ties matter. - Discuss precision requirements with the Apollo team (G). ## Detection @@ -75,5 +54,4 @@ code, bit-exact codecs). | Claim | Source | Core | Method | |---|---|---|---| | Precision targets: 64 bits on fmul/fadd, about 40 on fsqrt/fdiv | (G, 2026-10-30) | Core 12841 | Statement | -| The values in the table above | (M) | Core 12841 | FPU test suite, against reference values | | Older V4 cores 11 nibbles fraction, V2 2.17 about 8 | (official) PRM, FPU unit page | Older cores | Manual | diff --git a/core/pitfalls/fused-copy-overlap.md b/core/pitfalls/fused-copy-overlap.md index 338b3c1..e30bc36 100644 --- a/core/pitfalls/fused-copy-overlap.md +++ b/core/pitfalls/fused-copy-overlap.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured] +basis: [core-developer] components: [cpu-68080] applies_to: core: "Core 12841" @@ -63,4 +63,3 @@ bytes. Test copies over more than one pass: the cold pass hides the bug. | Claim | Source | Core | Method | |---|---|---|---| | Fused `move.l (an)+,(am)+` pairs read 8 bytes before writing, by design | (G) | Core 12841 | Statement | -| `dst = src + 4` gives L0,L0,L1 trained, L0,L0,L0 cold | (M) | Core 12841 | Loop test, cold vs trained pass | diff --git a/core/pitfalls/lowres-8-planes-ecsena-blank.md b/core/pitfalls/lowres-8-planes-ecsena-blank.md deleted file mode 100644 index 8117503..0000000 --- a/core/pitfalls/lowres-8-planes-ecsena-blank.md +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: LowRes with 8 bitplanes stays blank while BPLCON0 ECSENA is set -type: pitfall -owner: WDrijver -status: draft -origin: ai-assisted -basis: [measured] -components: [saga-video-isabelle] -applies_to: - core: "Core 12856" - os: [any] - mode: [any] - board: [v4-unicorn] -last_verified: 2026-11-24 -tags: [aga, bplcon0, ecsena, lowres, 256-colours, ham8, copper, planar] -related: - - core/saga-registers/chunky-plane.md -sources: - - "ApolloOS-Port, arch/m68k-amiga/hidd/amigavideo/amigavideo_chipset.c, commit f93703c1 (2026-11-24)" - - "Hardware test on a V4 Unicorn, Core 12856: BPLCON0 patched in the live copper list" ---- - -## Symptom - -An AGA LowRes screen with 8 bitplanes (256 colours or HAM8) shows only the -border colour: the whole display window is one flat colour (colour 0), -although the copper list, the bitplane pointers and the bitmap data are -right. The system keeps running. The same screen in HiRes or SuperHiRes -with 8 planes shows, and LowRes with 1 to 7 planes shows. - -## Cause - -On this core, BPLCON0 bit 0 (ECSENA, "enable BPLCON3 features") together -with BPU3 (bit 4, 8 planes) and HIRES/SHRES clear blanks the bitplane -display. The same value with ECSENA clear shows the picture. Classic AGA -(Lisa) shows both. The SAGA register documentation lists only the OCS bits -of BPLCON0 (no ECSENA, no BPU3), so this is not documented behaviour. - -The AROS-derived `amigavideo.hidd` sets ECSENA in every copper list -(`bplcon0_null = system_bplcon0 | 1`), which runs into this. - -## Wrong - -```c -/* copper list: LowRes, 8 planes, ECSENA set */ -COPPEROUT(c, 0x0100, 0x0211); /* BPU3 | COLOR | ECSENA: blank display */ -``` - -## Right - -```c -/* LowRes with 8 planes: leave ECSENA out of BPLCON0 */ -UWORD bplcon0 = 0x0210; /* BPU3 | COLOR: 256 colours show */ -if (depth > 7 && lowres) - bplcon0 &= ~0x0001; -``` - -## Detection - -A LowRes 256-colour or HAM8 screen that comes up as one flat colour while -`info screens` / the screen list shows it open with depth 8. Read the -copper list (GfxBase->LOFlist) and check BPLCON0 for `0x0211` (or -`0x0215` interlaced). - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| LowRes 8 planes with BPLCON0 `0x0211` shows only colour 0; the same copper list with `0x0210` shows the 256-colour Workbench | (M) 2026-11-24 | Core 12856 | Workbench on PAL:LowRes depth 8; one word of the live copper list in chip RAM poked with rxnet, screen captured after each value | -| LowRes 2, 6, 7 planes and HiRes 2, 8 planes show with ECSENA set | (M) 2026-11-24 | Core 12856 | Same Workbench, screen mode switched through ENV:Sys/screenmode.prefs | -| SAGA BPLCON0 documentation lists no ECSENA and no BPU3 | (official) sagadoc bplcon0.htm | any | Read | diff --git a/core/pitfalls/maggie-depth-test-colour-write.md b/core/pitfalls/maggie-depth-test-colour-write.md deleted file mode 100644 index 6d45164..0000000 --- a/core/pitfalls/maggie-depth-test-colour-write.md +++ /dev/null @@ -1,54 +0,0 @@ ---- -title: Maggie's depth test does not gate the colour write -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [saga-3d-maggie] -applies_to: - core: "Core 12847" - os: [any] -tags: [maggie, 3d, depth-buffer, z-buffer, bug] -related: - - core/saga-3d-maggie/registers.md - - core/cpu-68080/core-bugs-by-revision.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 15.7 (regression test test-maggiez, 2026-11-01)" ---- - -## Symptom - -Depth-buffered scenes drawn in arbitrary order show far polygons on top of -near ones: draw near, then far, and far wins. - -## Cause - -On Core 12847 the depth write is gated correctly (smaller = nearer wins), but -the colour is written on every pixel, whatever the depth test says. Core bug, -reported to the core developer. - -## Wrong - -```c -/* relies on the depth buffer for visibility */ -magSetDrawMode(MAG_DRAWMODE_DEPTHBUFFER); -draw_objects_in_any_order(); -``` - -## Right - -Until the bug is fixed, sort polygons back to front (painter's algorithm) so -that the colour of the nearest polygon is written last. This is a general -workaround, not tested in the guide. - -## Detection - -Draw a near quad, then a far quad over it, with the depth buffer on. If the -far quad is visible, the core has this bug. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| Depth write gated, colour write not | (M) | Core 12847 | Register-level test test-maggiez, 2026-11-01 | diff --git a/core/pitfalls/maggie-span-tail.md b/core/pitfalls/maggie-span-tail.md deleted file mode 100644 index 10aff1b..0000000 --- a/core/pitfalls/maggie-span-tail.md +++ /dev/null @@ -1,61 +0,0 @@ ---- -title: The last 8 bytes of a Maggie span stay in the unit -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [saga-3d-maggie] -applies_to: - core: "Core 12847" - os: [any] -tags: [maggie, 3d, span, flush, memory-corruption, bug] -related: - - core/saga-3d-maggie/registers.md - - core/pitfalls/maggie-span-usage.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 15.7 (regression test test-maggieend, 2026-11-01)" ---- - -## Symptom - -- A CPU read-back right after the last span misses up to 2 pixels (32-bit), - 4 pixels (16-bit) or 4 depth words. -- After a program that used Maggie exits, the next Maggie user's first span - writes 8 bytes into memory that may have been freed. On the V4 this - overwrote the next program's code. - -## Cause - -On Core 12847 the last 8-byte group of a span stays inside Maggie, separately -for the colour stream and the depth stream. It is written only when a later -span writes elsewhere; for depth, that must be a depth-mode span. Waiting -does not flush it, and neither does reading a register. - -## Wrong - -```c -draw_frame(); /* last span leaves 8 bytes in Maggie */ -FreeMem(target, size); /* the next user's first span writes into it */ -``` - -## Right - -Not yet tested; derived from the measured behaviour: - -- After the last real span, start a flush span to a small scratch buffer you - own: one with depth mode on if you used depth. Free that scratch buffer - only after the flush span. -- Before reading back a target, start such a flush span first. - -## Detection - -Read back the last pixels of a frame right after drawing. Check for memory -corruption after a Maggie program exits. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| The last 8-byte group stays in the unit; waiting or a register read does not flush it | (M) | Core 12847 | Register-level test test-maggieend, 2026-11-01 | -| The leftover bytes overwrote the next program's code | (M) | Core 12847 | Observed on the V4 | diff --git a/core/pitfalls/maggie-span-usage.md b/core/pitfalls/maggie-span-usage.md index 294068d..38a474e 100644 --- a/core/pitfalls/maggie-span-usage.md +++ b/core/pitfalls/maggie-span-usage.md @@ -1,73 +1,54 @@ --- -title: Maggie span traps (zero length, no cache snoop, one user, counters) +title: Maggie span traps (no cache snoop, one user) type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [saga-3d-maggie] applies_to: core: "Core 12847" os: [any] -tags: [maggie, 3d, span, cache, arbitration, counters] +tags: [maggie, 3d, span, cache, arbitration] related: - core/saga-3d-maggie/registers.md - - core/pitfalls/maggie-span-tail.md sources: - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 15.7" --- ## Symptom -- Memory gets overwritten after a span with length 0. - The CPU reads stale pixels or depth values from a buffer Maggie has just drawn. - Two programs drawing with Maggie at once spoil each other's spans. -- The performance counters at `$DFF300` never change. ## Cause -- A span with length 0 overwrote memory on the V4, probably as 65536 pixels - (M). - Maggie does not snoop the CPU data cache (SRC): a CPU read of the depth buffer or of a target Maggie has just drawn can hit stale cache lines. - There is one register set. Neither AmigaOS nor maggie.library arbitrates - between programs; the library's semaphore covers only its own callers. -- The counters at `$DFF300` read 0 on Core 12847 (M). + between programs; the library's semaphore covers only its own callers + (SRC). ## Wrong -```asm - move.w d0,14(a0) ; d0 may be 0: never start a span with length 0 -``` +Reading a Maggie target or the depth buffer with the CPU right after Maggie +drew it, through lines that may still be in the data cache. ## Right -```asm - tst.w d0 - beq.s .skip ; skip empty spans - move.w d0,14(a0) -.skip: -``` - - Make sure the CPU does not read a Maggie target or the depth buffer - through stale data-cache lines. The guide gives no tested method. Note that - `CacheClearU` does nothing on the 68080 (see - [self-modifying-code-and-caches.md](self-modifying-code-and-caches.md)) - and that evicting the data cache takes 128–256 KB of reads. + through stale data-cache lines. The guide gives no tested method. - Let one program at a time use Maggie. -- Don't use the counters as a sync source. ## Detection -Check every write to the start + length register for a possible 0. Look for -CPU reads of Maggie targets or the depth buffer without a cache flush. +Look for CPU reads of Maggie targets or the depth buffer without a cache +flush, and for more than one program using Maggie at once. ## Evidence | Claim | Source | Core | Method | |---|---|---|---| -| A length-0 span overwrote memory | (M) | Core 12847 | Observed on the V4 | | Maggie does not snoop the CPU data cache | (SRC) | any | maggie.library source and docs | -| Counters at `$DFF300` read 0 | (M) | Core 12847 | Register-level test test-maggiecnt, 2026-11-01 | -| No arbitration between programs | (SRC), (M) | Core 12847 | Library source; two programs observed | +| No arbitration between programs | (SRC) | any | Library source | diff --git a/core/pitfalls/multiply-and-bfffo-block-both-pipes.md b/core/pitfalls/multiply-and-bfffo-block-both-pipes.md deleted file mode 100644 index c830dfe..0000000 --- a/core/pitfalls/multiply-and-bfffo-block-both-pipes.md +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: Multiply, bfffo and FP-to-integer block both pipes -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured, official] -components: [cpu-68080] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, muls, mulu, bfffo, fmove, timing, pairing] -related: - - core/cpu-68080/measured-instruction-costs.md - - core/cpu-68080/prm/instruction-timing.md - - core/best-practices/fpu-when-it-pays.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 0 (rules 7 and 10) and 3" ---- - -## Symptom - -Multiply-heavy loops run slower than the PRM's timing predicts, and adding -independent integer work next to a multiply makes the loop longer instead of -filling a free slot. - -## Cause - -On Core 12841 these instructions issue in about 3 cycles each and block both -pipes, so nothing pairs with them: - -- `muls.l`/`mulu.l` (32 and 64-bit), `muls.w`, `mulu.w`: 3.04–3.13 cycles, - result usable about 3 cycles later; -- `bfffo`: 3 cycles, latency 6 when it feeds the next offset; -- `fmove.l`/`fmove.w` FP to integer: 3.08 cycles. - -The PRM gives MUL = 2 or 3 cycles. - -## Wrong - -```asm -loop: - muls.l (a0)+,d1 ; 3 cycles, blocks both pipes - addq.l #1,d5 ; does not pair: +1 cycle - add.l d1,d2 ; uses the product right away - dbra d0,loop -``` - -## Right - -- Count each of these as about 3 cycles that nothing pairs with; put - independent work before or after the run of multiplies, not between. -- Use the product at least 3 cycles later. -- Consider the FPU for long multiply-accumulate chains (see - [fpu-when-it-pays.md](../best-practices/fpu-when-it-pays.md)). -- Keep FP-to-integer conversions out of inner loops. - -## Detection - -Measure with CCC on a trained loop. A loop body around a `muls` that costs -the sum of its instructions instead of the longest chain points here. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| MUL = 2 or 3 cycles | (official) PRM timing page | any | Manual | -| `muls.l` 3.04–3.13 cycles with 1 or 7 chains; mul + independent op = 4.0–4.08 | (M) | Core 12841 | CCC/IEP, trained loops, best of 5 | -| `bfffo` 3 cycles, blocks both pipes | (M) | Core 12841 | Same | -| `fmove.l`/`.w` FP to integer 3.08 cycles, blocks both pipes | (M) | Core 12841 | Same | -| mul + add/addx rounding chain: 5–6 cycles per product | (M) | Core 12841 | Same | diff --git a/core/pitfalls/pc-relative-destination.md b/core/pitfalls/pc-relative-destination.md index e60563f..4901a97 100644 --- a/core/pitfalls/pc-relative-destination.md +++ b/core/pitfalls/pc-relative-destination.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, official] +basis: [official] components: [cpu-68080, toolchain] applies_to: core: "Core 12841" @@ -22,27 +22,21 @@ sources: ## Symptom Silent memory corruption: a write meant for a variable lands somewhere else. -It happens only in instructions that combine a full-extension-format source -with a PC-relative destination. +It happens in instructions that combine an extended-format source with a +PC-relative destination. ## Cause The 68080 allows PC-relative addressing for destinations (the 68000–68060 only for sources). The PC used is the address of the destination's extension word, and it is computed wrongly when the source uses the full extension -format, for example `(table.l,d0.w)` or memory indirect. - -vasm with `-m68080` makes such destinations by itself: it rewrites an -absolute destination `move.x ,label` into `label(pc)` by default (also -for addq/subq, bchg/bclr/bset, eor, fmove and AMMX stores). The -toolchain side is described in [vasm-pc-relative-destination.md](../../toolchain/pitfalls/vasm-pc-relative-destination.md). +format, for example `(table.l,d0.w)` or memory indirect (official: "not +calculated correctly with some extended source formats"). ## Wrong ```asm move.b (table.l,d0.w),result(pc) ; destination miscomputed - ; or, written with an absolute destination, rewritten by vasm -m68080: - move.b (table.l,d0.w),result ``` ## Right @@ -54,9 +48,6 @@ Address the destination through a register: move.b (table.l,d0.w),(a1) ``` -Or assemble the file with vasm `-no-opt` (this disables all vasm -optimizations). - ## Detection Scan the assembler listing for MOVE (and the other instructions above) with @@ -67,5 +58,3 @@ destination mode 7/2 (`d16(pc)`) and a full-format source. | Claim | Source | Core | Method | |---|---|---|---| | PC-relative destination is not calculated correctly with some extended source formats | (official) PRM, integer unit page | any | Manual | -| Miscomputed after a full-extension source; silent corruption | (M) | Core 12841 | Test program | -| vasm `-m68080` creates `(d16,PC)` destinations by default; `-nodpc` and `opt` don't stop it, `-no-opt` does | (M) | any | vasm 2.0f/2.0g listings | diff --git a/core/pitfalls/return-address-patching.md b/core/pitfalls/return-address-patching.md deleted file mode 100644 index df98d01..0000000 --- a/core/pitfalls/return-address-patching.md +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: Changing a return address defeats the return cache -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [cpu-68080] -applies_to: - core: "Core 12841" - os: [any] -tags: [68080, rts, return-cache, jump, patching] -related: - - core/cpu-68080/branches-and-prediction.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 2.6 and 12" ---- - -## Symptom - -Subroutine calls or patch stubs are several times slower than expected: -about 9.5 extra cycles per return, or about 45 cycles for an `rtd` used as a -jump. - -## Cause - -Returns are predicted by a return cache for rts/rtd/rtr. When code changes -the return address on the stack, or uses a return instruction as a jump, the -prediction is wrong and the CPU redirects after the ALU stage. - -## Wrong - -```asm -routine: - addq.l #2,(sp) ; skip an inline parameter word - rts ; mispredicted - -dispatch: - pea target ; "jump" through the stack - rts ; mispredicted -``` - -## Right - -- Pass parameters in registers, and return to the real return address. -- Jump directly with `jmp` or `bra`. -- To fall back to an original (patched) routine, use `jmp ([ptr,pc])`, which - is predicted. - -```asm - jmp ([oldvector,pc]) -``` - -## Detection - -Look for writes to `(sp)` before `rts`, `pea` + `rts`, and `rtd` used for -dispatch. Measure a call with CCC: more than about 5 cycles per bsr + rts -points here. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| bsr + rts: 4.6 cycles normally, 14.0 when the routine did `addq.l #2,(sp)` | (M) | Core 12841 | CCC | -| `rtd` used as a jump: about 45 cycles | (M) | Core 12841 | CCC | -| A computed-jump CopyMem was slower than a plain one | (M) | Core 12841 | Real workload | diff --git a/core/pitfalls/self-modifying-code-and-caches.md b/core/pitfalls/self-modifying-code-and-caches.md deleted file mode 100644 index 464cc1b..0000000 --- a/core/pitfalls/self-modifying-code-and-caches.md +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: CacheClearU does nothing; writes near code are slow -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured, official] -components: [cpu-68080] -applies_to: - core: "Core 12841" - os: [amigaos-3.9, amigaos-3.2] -tags: [68080, cache, self-modifying-code, cacheclearu, cinva, 68040-library] -related: - - core/cpu-68080/caches-and-memory.md - - core/cpu-68080/prm/specs.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 0 (rule 18) and 5.2" ---- - -## Symptom - -- Patched or generated code runs the old instructions, although the program - called `CacheClearU()` after writing it. -- Writes to buffers placed next to running code are about 3 times slower - than expected. - -## Cause - -- Under AmigaOS the 68080's 68040.library patches `CacheClearU` and - `CacheClearE` to a bare `rts`. They also never flush the 68080 data cache. -- The core detects writes into cached or in-flight code (official: "080 has - selfmodify detection"), but patched code still ran stale without an - instruction-cache flush (M). -- The self-modify detection slows every write near running code. - -## Wrong - -```asm - move.w #$4e71,(a0) ; patch code - movea.l 4.w,a6 - jsr _LVOCacheClearU(a6) ; does nothing on the 68080 - jmp (a0) ; may run the old instruction -``` - -## Right - -Flush the instruction cache with `cinva ic` in supervisor mode, for example -through `Supervisor()`: - -```asm - lea .flush(pc),a5 - movea.l 4.w,a6 - jsr _LVOSupervisor(a6) - ; ... -.flush: - cinva ic - rte -``` - -- Keep benchmark buffers and written data away from running code. -- Evicting the data cache takes 128–256 KB of reads. - -## Detection - -Search for `CacheClearU`/`CacheClearE` used after writing code. Check that -data written in hot loops is not linked into the code section next to the -loop. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| The 080 has self-modify detection | (official) PRM, specs page | any | Manual | -| `CacheClearU`/`CacheClearE` are a bare `rts` under the 080 68040.library | (M) | Core 12841 | AmigaOS 3.9 with the 080 68040.library | -| Patched code ran stale without `cinva ic` | (M) | Core 12841 | Test program | -| A store + 2 `add.l` took 9 cycles next to running code instead of about 3 | (M) | Core 12841 | CCC | diff --git a/core/pitfalls/tex-does-not-match-prm.md b/core/pitfalls/tex-does-not-match-prm.md deleted file mode 100644 index 0c7ca9f..0000000 --- a/core/pitfalls/tex-does-not-match-prm.md +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: TEX does not match the PRM -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured, official] -components: [cpu-68080] -applies_to: - core: "Core 12846" - os: [any] -tags: [68080, ammx, tex, texture, bug] -related: - - core/cpu-68080/prm/ammx/tex.md - - core/cpu-68080/core-bugs-by-revision.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 6 (measured 2026-10-31)" ---- - -## Symptom - -`TEX (An,Ax,Ay*Dm),Dn` reads the wrong texel: x/y coordinates in 16.16 and -the line width have no effect. `x 1, y 1, m 256` reads offset 0. - -## Cause - -On Core 12846 the third word of the instruction acts as a plain brief -extension word: bit 15 D/A, bits 14–12 register, bit 11 W/L, bits 10–9 -scale. The core reads the byte at `An + Xn.W/L * scale`. - -- Ax (word 3 bits 2–0), Dm (word 2 bits 14–12) and the displacement byte are - not used. -- The older `TEX8/16/24.size (An,(Av,Au)),Dn` encodings decode the same way. - There is no word, 24-bit, DXT1 or 32-bit fetch, and no modular map. -- The texel replaces the low byte of Dn. The other 56 bits are kept, not - shifted up. -- vasm 2.0g has no syntax for TEX: it needs `dc.w`. - -## Wrong - -```asm - ; per the PRM: byte at (a0) + y*width + x, with x in a1, y in a2 (16.16) - ; and the line width in d7. Hand-encoded with dc.w (vasm has no syntax). - ; On Core 12846 the coordinates and width are ignored. - ; tex (a0,a1,a2*d7),d4 -``` - -## Right - -Don't use TEX until the Apollo team settles its behaviour (question Q6 to the -core developer). Compute the address yourself and use `move.b`. - -## Detection - -Search for TEX, REX and `dc.w` sequences starting with `$FE`. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| TEX byte form with 16.16 coordinates and line width Dm | (official) PRM, TEX page | Core 12540+ | Manual | -| The core reads `An + Xn.W/L * scale`; Ax, Dm and displacement unused | (M) | Core 12846 | mh groups 25/26, 2026-10-31 | diff --git a/core/pitfalls/touch-misuse.md b/core/pitfalls/touch-misuse.md index 5fae552..c1f082d 100644 --- a/core/pitfalls/touch-misuse.md +++ b/core/pitfalls/touch-misuse.md @@ -1,10 +1,10 @@ --- -title: TOUCH slows sequential streams, and only one form is valid +title: Only one TOUCH form is valid type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, official] +basis: [core-developer, official] components: [cpu-68080] applies_to: core: "Core 12841" @@ -19,42 +19,35 @@ sources: ## Symptom -- A loop with `touch` on a sequential stream takes twice as long. -- A program crashes after a `touch` with a full extension word, or a - `touch (An)` writes memory. +A `touch` written in any form other than the 2-word `(An,Xn)` brief +extension does not do what the PRM describes. ## Cause -- The CPU already prefetches sequential streams; `touch` only adds work. -- The only valid form is the 2-word `(An,Xn)` brief extension (G). A - full-extension form is decoded as 2 words, so the next word runs as an - instruction. -- The PRM's `touch (An)` encoding (`$F61x`) is `move16 (An),abs.l` (M). +- The only valid form is the 2-word `(An,Xn)` brief extension (G). +- The PRM allows only mode 6 with a brief extension and no multiplier + (official). ## Wrong ```asm -loop: - touch 64(a0,d1.l) ; on a sequential stream: 2x slower - move.l (a0)+,d2 - ; ... +; kb:no-assemble vasm rejects this form + touch (a0) ; not mode 6 with a brief extension ``` ## Right -Use `touch d8(An,Dn)` only for random accesses, about 12–15 cycles before the -data is needed: +Use `touch d8(An,Dn)`: ```asm - touch 0(a1,d1.l) ; random lookup, issued early - ; ... 12-15 cycles of other work ... + touch 0(a1,d1.l) ; 2-word brief extension + ; ... other work ... move.b 0(a1,d1.l),d2 ``` ## Detection -Search for `touch` in loops that walk memory with `(An)+` or a fixed stride, -and for `touch (An)` or full-extension `touch` forms. +Search for `touch (An)` or full-extension `touch` forms. ## Evidence @@ -62,6 +55,3 @@ and for `touch (An)` or full-extension `touch` forms. |---|---|---|---| | Only mode 6, brief extension, no multiplier | (official) PRM, TOUCH page | any | Manual | | Only the 2-word `(An,Xn)` brief extension is valid | (G) | Core 12841 | Statement | -| `touch` on a sequential stream doubles the cycles | (M) | Core 12841 | CCC | -| `$F61x` (`touch (An)` in the PRM) is `move16 (An),abs.l` | (M) | Core 12841 | Test program | -| A full-extension form runs the next word as an instruction (crash) | (M) | Core 12841 | Test program | diff --git a/core/pitfalls/turtle-mode-counters.md b/core/pitfalls/turtle-mode-counters.md deleted file mode 100644 index 7c3f9c3..0000000 --- a/core/pitfalls/turtle-mode-counters.md +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: Turtle mode changes what the performance counters mean -type: pitfall -owner: WDrijver -status: draft -origin: ai-assisted -basis: [measured] -components: [cpu-68080] -applies_to: - core: "Core 12856" - os: [any] - board: [v4-unicorn] -tags: [68080, turtle, apollocontrol, pcr, ccc, iep, counters, benchmark, superscalar] -related: - - core/cpu-68080/performance-counters.md - - core/cpu-68080/core-at-a-glance.md - - guides/benchmark-method.md -sources: - - "lessons/2026-11-v4-turtle-mode.md" ---- - -## Symptom - -- A benchmark or a pipe test gives numbers far off the usual ones: code - runs 4.5 to 177 times slower, the pipe test says "1 pipe", and IEP1 is - 2.5 to 96 times the number of instructions run. -- PCR bit 0 still says the second pipe is on, so the result looks like a - core fault instead of a mode. - -## Cause - -Turtle mode (`ApolloControl TU=1`, `2` or `3`: A500, A1200, A4000 speed) -slows the 68080 down without lowering its clock: - -- CCC keeps counting at 99.3 MHz in every mode. -- Only one pipe issues: IEP2 reads 0. PCR bit 0 stays 1 all the same. -- IEP1 then counts about one per cycle (94-97 % of CCC), not one per - instruction. -- Each instruction takes more cycles. Counted loops on Core 12856: - -| Mode | Independent ALU | Memory | Branches | -|---|---|---|---| -| Turtle off (TU=0) | 1x | 1x | 1x | -| TU=3 (A4000) | 4.5x | 4.9x | 6.5x | -| TU=2 (A1200) | 89x | 85x | 59x | -| TU=1 (A500) | 177x | 172x | 117x | - -PCR bits 7-6 show the mode: `00` off, `01` TU=3, `11` TU=2, `10` TU=1. - -## Wrong - -```asm -; Time a routine and count pipes, whatever mode the machine is in. - movec ccc,a6 - bsr routine - movec ccc,d7 - sub.l a6,d7 ; in Turtle mode: up to 177x the real cost - movec iep1,d0 ; in Turtle mode: cycles, not instructions -``` - -## Right - -```asm -; Check PCR bits 7-6 first (readable in user mode on Core 12856). - movec pcr,d0 ; PCR ($808) - and.w #$00c0,d0 ; bits 7-6: 0 = Turtle off - bne .turtle ; Turtle on: report it, don't benchmark - movec ccc,a6 - bsr routine - movec ccc,d7 - sub.l a6,d7 -``` - -Or set `ApolloControl TU=0` before measuring, and note the mode with every -result. - -## Detection - -- Read PCR before a benchmark run and log it: `$04400101` at full speed on - Core 12856; `$04400141`, `$044001C1` or `$04400181` in Turtle mode. -- IEP2 = 0 while PCR bit 0 = 1 means Turtle mode (or a fault), not a - single-pipe core. -- A remote job over the network shows much less slowdown (4x, 12x, 22x - for a small file hash): measure the mode with a counted CPU loop. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| Counted loops run 4.5x / 89x / 177x slower in TU=3 / 2 / 1 (independent ALU loop: 128185 / 581499 / 11405896 / 22721312 CCC) | (M) 2026-11-25 | Core 12856, V4 UniCorn, ApolloOS R10 | 224007-instruction loop, CCC, 5 runs per mode, each mode set after a power cycle; see the lesson | -| CCC runs at 99.32 MHz in every mode | (M) 2026-11-25 | Core 12856 | CCC against the E-clock over timer waits, working and sleeping | -| IEP2 = 0 in every Turtle mode, while PCR bit 0 = 1 | (M) 2026-11-25 | Core 12856 | IEP1/IEP2 over the same loop; `movec` PCR in user and supervisor mode | -| IEP1 is 94-97 % of CCC in Turtle mode | (M) 2026-11-25 | Core 12856 | IEP1 564686 / 10874762 / 21430313 against CCC 581499 / 11405896 / 22721312 | -| PCR reads `$04400101`, `$04400141`, `$044001C1`, `$04400181` for TU=0, 3, 2, 1 | (M) 2026-11-25 | Core 12856 | `movec` PCR, one run per mode; other cores not checked | diff --git a/core/saga-3d-maggie/registers.md b/core/saga-3d-maggie/registers.md index 786aa82..c0d55ce 100644 --- a/core/saga-3d-maggie/registers.md +++ b/core/saga-3d-maggie/registers.md @@ -4,7 +4,7 @@ type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [saga-3d-maggie] applies_to: core: "Core 12847" @@ -12,14 +12,11 @@ applies_to: tags: [maggie, 3d, registers, span, texture, dxt1] related: - core/saga-3d-maggie/index.md - - core/pitfalls/maggie-depth-test-colour-write.md - - core/pitfalls/maggie-span-tail.md - core/pitfalls/maggie-span-usage.md - core/saga-registers/maggie-3d.md sources: - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 15.7" - "maggie.library source, github.com/RMortenB/MaggieLibrary, commit 64c78ef (2026-08-17)" - - "Regression tests test-maggie, test-maggiez, test-maggieend, test-maggiecnt, Core 12847, 2026-11-01" --- ## Summary @@ -27,8 +24,7 @@ sources: Maggie is the V4's texture-mapping span unit: the CPU sets up one span per scanline in registers at `$DFF250`, and writing the length starts it. There is no public documentation beyond this; the layout below is how -maggie.library uses it (SRC), checked by register-level tests on Core 12847 -(M). +maggie.library uses it (SRC). ## Details @@ -54,8 +50,7 @@ maggie.library uses it (SRC), checked by register-level tests on Core 12847 Read-only and free-running in the library's description (SRC): `+0` texture fetches, `+4` depth fetches, `+8` destination fetches, `+12` pixels started -(including pixels later killed by the depth test or alpha). **On Core 12847 -they read 0 and never move** (M). +(including pixels later killed by the depth test or alpha). ### Usage @@ -65,18 +60,6 @@ they read 0 and never move** (M). - The library's perspective path splits each span into runs of 16 pixels with affine interpolation inside each run. -### Behaviour measured on Core 12847 (test-maggie: 0 failures) - -- Length 1 to 64 writes exactly that many pixels, at any start pixel. -- U/V: 8:24, 1.0 = one texture width, point sampled. Negative dU works; U and - V wrap at 1.0. -- DXT1 blocks are row-major, colours and indices little-endian. Index 3 with - col0 ≤ col1 leaves the target pixel unchanged. -- Light 0 gives black. 16-bit output is RGB565. -- 32-bit colours with light `$FFFF` and tint `$FFFFFFFF`: RGB565 `$F800` - gives `$00FC0000`, white gives `$00FCFCFC`. The alpha byte is 0; full light - gives `$FC`, not `$FF`. - ## Differences from AmigaOS / AROS / 68060 Classic Amiga chipsets have no texture-mapping unit. Maggie is SAGA specific @@ -86,5 +69,4 @@ and not covered by the classic hardware reference. - DO write the start + length register last: it starts the span. - DO zero the second-order dU/dV registers once. -- DON'T use the counters at `$DFF300` for timing or sync on Core 12847. -- See the pitfalls: depth test, the last 8 bytes of a span, and span usage. +- See the span usage pitfall. diff --git a/core/saga-audio-arne/registers.md b/core/saga-audio-arne/registers.md index 36a9845..d1e6a81 100644 --- a/core/saga-audio-arne/registers.md +++ b/core/saga-audio-arne/registers.md @@ -4,7 +4,7 @@ type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured] +basis: [core-developer] components: [saga-audio-arne] applies_to: core: "Core 12841" @@ -52,8 +52,7 @@ The channel base addresses are in the official register map: ### Behaviour - Arne runs in a 60 kHz max mode (G, 2026-11-04): decimate input above - that. The guide gave about 66 kHz (decimate above 64 kHz); the core - developer's figure is leading. There is no minimum sample rate, and the + that. There is no minimum sample rate, and the HDMI audio output resamples down for compatibility with all monitors (G, 2026-11-04). - For games, use 44.1 kHz (period 80), the CD standard (G, 2026-11-04). diff --git a/guides/benchmark-method.md b/guides/benchmark-method.md deleted file mode 100644 index fe2c94a..0000000 --- a/guides/benchmark-method.md +++ /dev/null @@ -1,68 +0,0 @@ ---- -title: Benchmark 68080 code so the result is real -type: guide -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [cpu-68080] -applies_to: - core: "any" - os: [any] -tags: [benchmark, measuring, ccc, method, noise, placement] -related: - - core/cpu-68080/performance-counters.md - - core/best-practices/code-size-and-placement.md - - os/pitfalls/ramlib-reuses-library-by-name.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 8.1 and 8.2" ---- - -## Goal - -A speed comparison between two versions of 68080 code that you can trust: -the difference you report is the code's, not that of the cache, the -placement or the machine's mood. Most "gains" TuKo1982 first saw were wrong -for one of the reasons below (M). - -## Prerequisites - -- Timing with the CCC cycle counter (`movec ccc,Dn`, register `$809`), see - [performance-counters.md](../core/cpu-68080/performance-counters.md). -- Two or more builds of the code to compare, and a way to run each one many - times in one boot. - -## Steps - -1. **Know what you measure.** One dependency chain measures latency; N - independent chains, N at least the latency, measure throughput. A wrong - chain count once made the FPU look "no better than integer" (M). -2. **Train the loop.** Run it once before you time it, and discard that - first pass. -3. **Alternate the variants in one boot**, rotating the order: A B A B A B. - Run back to back, a second run gets a warm cache: a 35 % "gain" was - really 14 % (M). -4. **Vary the placement.** Build several copies and load them at different - addresses. Differences under 5 % on a single build are noise (see - [code-size-and-placement.md](../core/best-practices/code-size-and-placement.md)). - For library tests, give the test version a name of the **same length** - as the real one: the name string shifts the code. -5. **Measure the real workload 3 times** for table-driven code. Its noise is - about ±10 % (M). -6. **Record real call shapes first** (hook the calls and log their - arguments), then test with those, plus random sizes to expose - branch mispredictions. -7. **Test worst-case data:** very loud audio, maximum-range inputs. "Bit - exact with the C" proves nothing when the C has the same overflow. -8. **Run with nothing else active.** One session on a V4 ran 15–36 % slower - for 15 minutes for no visible reason, then recovered by itself (M). -9. **Give each variant a unique library name**, or flush between runs: - ramlib returns the library already in memory (see - [ramlib-reuses-library-by-name.md](../os/pitfalls/ramlib-reuses-library-by-name.md)). - -## Verification - -- The alternated runs agree with each other within the noise of step 4 or 5. -- The same result holds for several builds and load addresses. -- Report gains as positive percentages ("26 % fewer cycles") and slowdowns - in words, and state the core, the board and the data you used. diff --git a/guides/generators-and-verification.md b/guides/generators-and-verification.md deleted file mode 100644 index dc79982..0000000 --- a/guides/generators-and-verification.md +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: Write big 68080 kernels with a generator, and verify them in five steps -type: guide -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [cpu-68080] -applies_to: - core: "any" - os: [any] -tags: [generator, scheduling, verification, testing, emulator, dct, imdct] -related: - - core/best-practices/fixed-point-and-bitstreams.md - - core/best-practices/fpu-schedule-by-completion-slot.md - - guides/benchmark-method.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 10" ---- - -## Goal - -A large hand-tuned kernel (a transform such as a DCT or IMDCT) that is -faster than the compiler's code and proven bit-exact against a C -reference. - -## Prerequisites - -- A C reference of the kernel. -- A host scripting language for the generator (TuKo1982 used Python). -- A 68k emulator for the generic parts (vamos or Musashi) and a V4 for the - 080-specific build. - -## Steps - -1. **Generate the code, don't schedule it by hand.** A generator with a - dependency graph, a register allocator and a list scheduler (optionally - local search on a cycle model) gave a 32-point DCT 20 % faster than the - C and an IMDCT 21 % faster than GCC, both bit-exact (M). -2. **Keep the generator in the source tree.** Let the Makefile regenerate the - `.s` file, and check that it reproduces the shipped one. -3. **Use the cycle model to check a schedule, not only to find one.** A - greedy list scheduler on the FPU model was worse than a hand-designed - modulo rhythm: 2222 against 1644 cycles (M). The models still missed by - 10–20 % on some kernels, unexplained: always confirm with CCC on the - hardware (see [benchmark-method.md](benchmark-method.md)). -4. **Climb the verification ladder:** - 1. Simulate the generated assembler (a small 68k simulator) before the - first run. - 2. Run the generic 68k parts under an emulator and compare with the C - reference: random cases including ±2^31, exhaustive where possible - (4.2 million cases for one requantiser). - 3. Mutation-check the test: a 1-LSB change to one constant must be - caught. - 4. Run the 080-specific build on the V4 and compare checksums with the - emulator's 68020 build of the same configuration. - 5. Run full-file corpora plus fuzzed (randomly damaged) inputs, and - compare the output **and** the return codes. - -The fixed-point and bitstream techniques from the same work are in -[fixed-point-and-bitstreams.md](../core/best-practices/fixed-point-and-bitstreams.md). - -## Verification - -- Every rung of the ladder passes, including the mutation check. -- The checksums of the V4 build and the emulator's 68020 build match. -- The speed gain holds under [benchmark-method.md](benchmark-method.md). diff --git a/guides/testing-on-v4-hardware.md b/guides/testing-on-v4-hardware.md index c0e76ab..c8809c8 100644 --- a/guides/testing-on-v4-hardware.md +++ b/guides/testing-on-v4-hardware.md @@ -4,7 +4,7 @@ type: guide owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [general, toolchain, hardware] applies_to: core: "any" @@ -12,13 +12,10 @@ applies_to: mode: [any] tags: [testing, remote, ash, acp, apolloexplorer, serial, capture, ffmpeg, power-cycle] related: - - guides/benchmark-method.md - - guides/writing-cpu-tests.md - core/cpu-68080/performance-counters.md sources: - "lessons/2026-11-akb-verification.md" - "lessons/2026-11-apolloexplorer.md" - - "lessons/2026-11-v4-turtle-mode.md" - "ApolloKnowledgeBase tools/v4/v4test.py and tools/v4/tests/ (2026-11-09)" - "ApolloOS-Port project, mk/card.mk and tools/ (WDrijver, 2026-10)" - "github.com/WDrijver/ApolloCrossDev Projects/ApolloLib/ApolloCrossDev_Debug.c" @@ -34,8 +31,6 @@ This is how the knowledge base's own hardware tests run (`tools/v4/`). ## Prerequisites - A V4 on the network with **ApolloExplorerSrv** running, started at boot. - It must be recent: on a V4 with ApolloOS R9.5, `ash` connected but never - returned output until the server was updated, while `acp` worked (M). - On the other computer: `ash` and `acp` from ApolloExplorer. - For serial output: a USB-to-serial cable on the V4's serial port (the ApolloCrossDev README names a PL2303 cable), at 115200 8N1 without flow @@ -58,12 +53,7 @@ This is how the knowledge base's own hardware tests run (`tools/v4/`). 2. **Record the core number** with every result: `ash "ApolloControl CO"` prints it, for example `12556`. The SAGA register `$DFF3EA` (CORE REVISION) has no documented format. Record the Turtle - mode too (`ApolloControl TU=n`, shown in PCR bits 7-6): it slows code - down up to 177x, see - [turtle-mode-counters.md](../core/pitfalls/turtle-mode-counters.md). - Measure a mode's slowdown with a counted CPU loop, not with a remote - job: a small file hash over the network was only 4x, 12x and 22x slower - in TU=3, 2 and 1 (M). + mode too (`ApolloControl TU=n`, shown in PCR bits 7-6). 3. **Copy the program.** In `acp`'s destination, put a slash after the volume name: @@ -80,10 +70,7 @@ This is how the knowledge base's own hardware tests run (`tools/v4/`). baud, as ApolloLib's `ApolloDebugPutChar()` does: set `SERPER` (`$DFF032`), wait for `TBE` in `SERDATR` (`$DFF018`), write `SERDAT` (`$DFF030`). This needs no OS, so it also works in `os-takeover` code. - `Echo >SER:`, which goes through serial.device, did not reach the cable - at any baud rate between 9600 and 115200 (M). -6. **Take a picture or a video** of the HDMI output. The tested capture - device rejects ffmpeg's default pixel format, so name one: +6. **Take a picture or a video** of the HDMI output, for example: ```sh ffmpeg -f avfoundation -pixel_format uyvy422 -framerate 30 \ @@ -96,23 +83,12 @@ This is how the knowledge base's own hardware tests run (`tools/v4/`). names. ffmpeg needs about a second to start: start it before the program. 7. **Recover a hung V4.** Switch the plug off, wait 10 s, switch it on, and - wait until step 1 answers again. A V4 boots fast: the tested V4 answered - `ash` 15 s after power-on under ApolloOS R9.5, and answered ping 34 s - after power-on under AmigaOS 3.9 (M). Poll every second and give up - after 60 s; a V4 that is not back by then needs a look, not more + wait until step 1 answers again. Poll every second and give up after a + fixed time; a V4 that is not back by then needs a look, not more waiting. - - DON'T expect step 1 to answer after a power cycle unless - ApolloExplorerSrv starts at boot (`WBStartup` or `S:User-Startup`). - Without that, the V4 answers ping, but no remote command works until - someone starts the server by hand. - - DON'T take a V4 in Turtle mode for hung too soon. In TU=1 a - 60-second CPU-bound program kept it from answering on the network for - about two minutes, and a directory listing took over 30 s (M). Use - timeouts of minutes there. A power cycle returns to full speed. `tools/v4/v4test.py` in the knowledge base does all of this: it builds the -test with ApolloCrossDev, runs variants alternately (see -[benchmark-method.md](benchmark-method.md)), and stores output, serial log, +test with ApolloCrossDev, runs variants alternately, and stores output, serial log, picture and core number per run. ## Verification @@ -121,17 +97,3 @@ picture and core number per run. - A program that writes a known line to the UART (the knowledge base test `serial-out`) shows that line in the serial log. - After a power cycle, `RAM:` is empty and step 1 answers again. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| `ash` hangs with the older ApolloExplorerSrv, works after the update; `acp` works with both | (M) | Core 12556 | V4 UniCorn, ApolloOS R9.5, 2026-11-09 | -| Direct UART writes at 115200 arrive; `Echo >SER:` does not | (M) | Core 12556 | `tools/v4/tests/serial-out`; `SER:` listened for at 9600, 19200, 38400, 57600, 115200 | -| The V4 answers `ash` 15 s after power-on | (M) | Core 12556 | `v4test.py power-cycle`, Tasmota plug | -| The V4 answers ping 34.4 s after power-on | (M) | Core 12856 | V4 UniCorn, AmigaOS 3.9, Tasmota plug off 5 s then on, ping polled every 0.5 s, 2026-11-16 | -| Without ApolloExplorerSrv in the startup, nothing answers on port 30302 after a power cycle | (M) | Core 12856 | Same power cycle: port 30302 refused 90 s after power-on while ping answered | -| The capture device needs `-pixel_format uyvy422` and offers 1920x1080 at up to 60 fps | (M) | any | ffmpeg 9.0.2, macOS | -| A small file hash over the network takes 0.04 / 0.15 / 0.47 / 0.88 s at full speed / TU=3 / TU=2 / TU=1, while counted CPU loops are 4.5x / 89x / 177x slower | (M) | Core 12856 | V4 UniCorn, ApolloOS R10, 2026-11-25, each mode set after a power cycle; [lesson](../lessons/2026-11-v4-turtle-mode.md) | -| In TU=1 the V4 did not answer on the network for about 2 minutes during a 60 s CPU-bound program, and finished it normally; a remote directory listing did not finish within 30 s | (M) | Core 12856 | Same runs, one occurrence each | -| A power cycle returns to full speed | (M) | Core 12856 | Same runs: the speed check after each power cycle matched full speed | diff --git a/guides/writing-cpu-tests.md b/guides/writing-cpu-tests.md deleted file mode 100644 index e422cf0..0000000 --- a/guides/writing-cpu-tests.md +++ /dev/null @@ -1,61 +0,0 @@ ---- -title: Write CPU tests for the 68080 core -type: guide -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [cpu-68080] -applies_to: - core: "any" - os: [any] -tags: [testing, cpu-tests, assert, emulator, core] -related: - - core/cpu-68080/core-bugs-by-revision.md - - core/cpu-68080/performance-counters.md - - guides/generators-and-verification.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 14" ---- - -## Goal - -Tests of the 68080 core whose failures point at the core, not at the test: -each check is unambiguous, reproducible and traceable to one instruction. - -## Prerequisites - -- The test harness's `assert_zero` address, `$00D8000C`. -- An 080-aware disassembler and a 68k emulator. - -## Steps - -1. **One check, one write.** Write (result − expected) to `assert_zero` - (`$00D8000C`), in the size the result was computed in. -2. **Plain code:** no macros, one instruction per line. MRI assemblers - silently take a second instruction on a line as a comment. -3. **Number the checks.** Put the check number in a register - (`movea.w #n,a5`) so a failure is easy to find. -4. **Loop each test about 5 times.** Cold and trained passes must give the - same result. -5. **Hand-trace every expected value** from the bytes actually written. -6. **Run everything that is not 080-specific on a 68k emulator first.** A - check that fails on any CPU is a bug in the test. -7. **Decode every hand-encoded `dc.w` back** with an 080-aware disassembler, - and check its length. - -Mistakes TuKo1982 made, so you don't: - -- the element size of a fill against the size of its address; -- indexing with `.l` after `divu` + `swap` (the quotient is in the high - word); -- expecting IEP2 to move on a cold pass; -- comparing equal operands in an operand-order test; -- using a register as scratch that was still to be checked. - -## Verification - -- The generic part passes on the emulator. -- All passes of the loop give the same result on the V4. -- A deliberately wrong expected value makes exactly the right check fail, - with its number in a5. diff --git a/hardware/pitfalls/ide-speed-cf-write-corruption.md b/hardware/pitfalls/ide-speed-cf-write-corruption.md deleted file mode 100644 index ea22e99..0000000 --- a/hardware/pitfalls/ide-speed-cf-write-corruption.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: ApolloControl IDESPEED 3 can corrupt writes to a CF card -type: pitfall -owner: WDrijver -status: draft -origin: ai-assisted -basis: [measured] -components: [hardware] -applies_to: - core: "Core 12856" - os: [apolloos-r10] - board: [v4-unicorn] -tags: [ide, cf, apollocontrol, idespeed, timing, corruption] -related: - - guides/testing-on-v4-hardware.md -sources: - - "ApolloOS R10 port (ApolloOS-Port), 2026-11-17: CF card SanDisk SDCFXS 128 GB on the V4 IDE port, SFS volume" - - "github.com/ApolloTeam-dev/ApolloSoftware Tools/ApolloControl/2.21: ID=IDESPEED/N - 0=Slow, 1=Fast, 2=Faster, 3=Fastest" ---- - -## Symptom - -After `ApolloControl ID=3`, a filesystem on a CF card reports checksum -errors on blocks written since the change, for example SFS: "DH0 has a -checksum error in block 9223". The error is still there after a reread -at a slower speed: the block was **written** wrong. - -## Cause - -`ID=3` (fastest IDE timing) is faster than this CF card handles. Reads -may still look fine, but writes are corrupted. - -## Wrong - -```text -C:ApolloControl ID=3 ; in S:Startup-Sequence, untested card -``` - -## Right - -Measure the card before setting a speed in the Startup-Sequence. Write a -large file at each level, check it by hash, reread it at a lower level, -and use the highest level that passes. On the tested card `ID=2` passed, -and levels 0–2 were about equally fast (SFS, 16 MB: write ~8 MB/s), so -`ID=3` gained nothing. - -## Detection - -Before you trust an IDE speed level: copy a 16 MB file to the card, check -its SHA-256 on the V4, set a lower level, and check it again. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| ID=3 corrupts writes | (M) 2026-11-17 | Core 12856, V4 UniCorn | SanDisk SDCFXS 128 GB, SFS: checksum error on block 9223 (SFS NodeContainer) written at ID=3; raw read 3× at ID=2 identical, checksum still wrong | -| ID=0, 1, 2 correct and equally fast | (M) 2026-11-17 | Core 12856, V4 UniCorn | 16 MB written and SHA-256-checked on the V4 at each level: write 2.7–2.9 s, read 0.6–0.7 s | -| One card only | (M) | | Other cards may tolerate ID=3; measure each card | diff --git a/hardware/v4-generic/i2c-register.md b/hardware/v4-generic/i2c-register.md index 5891609..cc28206 100644 --- a/hardware/v4-generic/i2c-register.md +++ b/hardware/v4-generic/i2c-register.md @@ -4,7 +4,7 @@ type: reference owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [hardware, libraries] applies_to: core: "any" @@ -16,7 +16,6 @@ related: sources: - "i2clib source (i2c.library 40.0 'for Apollo Core boards', BSD licence): src/apollo.i and i2cbootrom.s" - "ApolloOS-Port commit 3b151de (2026-11-18): arch/m68k-amiga/battclock/ds3231.c and test/tools/RTCTest.c" - - "Hardware test on a V4 Unicorn, Core 12856, ApolloOS R10 dev card, 2026-11-18" --- ## Summary @@ -43,11 +42,6 @@ battclock.resource both use it to reach an RTC chip such as the DS3231. - **RTC address:** a DS3231 or DS1307 answers at `$D0` (write) / `$D1` (read). Registers 0..6 are seconds, minutes, hours, weekday, date, month and year in BCD. -- **Year and weekday as C:I2Clock 0.7 stores them** (measured 2026-11-18): - year register = year - 1976 (so 1976..2075; the DS3231 century bit is not - used), weekday register = the Amiga weekday (0 = Sunday). A program that - writes the DS3231 standard (year - 2000) makes I2Clock show the year 24 - years too early, and the other way round. ## Differences from AmigaOS / AROS / 68060 @@ -57,12 +51,10 @@ battclock.resource both use it to reach an RTC chip such as the DS3231. i2c.library) read and set it, so Prefs/Time and `SetClock SAVE` did not reach it. - ApolloOS R10's battclock.resource probes `$D0` when `$DC0000` has no clock - and then reads and writes the RTC itself, in I2Clock's year format. + and then reads and writes the RTC itself. ## Do / Don't -- DO keep I2Clock's year format (year - 1976) when writing the RTC, so the - chip stays usable from AmigaOS, ApolloOS R9.x and R10. - DO run a whole transfer (start to stop) without other tasks touching `$DE0080` in between, e.g. under `Disable()`; a transfer of the 7 time registers takes well under a millisecond. @@ -74,5 +66,3 @@ battclock.resource both use it to reach an RTC chip such as the DS3231. | Claim | Source | Core | Method | |---|---|---|---| | SCL bit 1, SDA bit 0 written as a word at `$DE0080`; SDA read at bit 0 of `$DE0081` | (SRC) i2clib `src/apollo.i` | any | source reading | -| A DS3231 answers at `$D0` and reads/writes correctly with this protocol | (M) 2026-11-18 | Core 12856 | C:RTCTest PROBE/READ/WRITE on a V4 Unicorn, compared with C:I2Clock SHOW | -| I2Clock stores year - 1976 and the Amiga weekday | (M) 2026-11-18 | Core 12856 | RTCTest wrote 2026 as standard (26), I2Clock showed 2002; I2Clock's own 2026 read back as register 50 | diff --git a/lessons/2026-11-akb-verification.md b/lessons/2026-11-akb-verification.md index 417a6ae..5fb4c19 100644 --- a/lessons/2026-11-akb-verification.md +++ b/lessons/2026-11-akb-verification.md @@ -4,7 +4,7 @@ type: lesson owner: WDrijver status: draft origin: ai-assisted -basis: [core-developer, measured, source-code] +basis: [source-code] components: [toolchain, cpu-68080, hardware, general] applies_to: core: "any" @@ -16,20 +16,16 @@ related: - toolchain/pitfalls/float-settings-mismatch.md - toolchain/pitfalls/vasm-68080-encoding-issues.md - core/cpu-68080/caches-and-memory.md - - core/cpu-68080/performance-counters.md - core/saga-registers/system.md - - guides/benchmark-method.md sources: - "ApolloTeam-dev/ApolloKnowledgeBase pull requests #32 to #41 (2026-11-08 to 2026-11-09)" - "WDrijver/ApolloCrossDev pull request #24 (README opcode list)" - - "Test programs tools/v4/tests/ (moviw, add-mem-dbra, fpu-m68881, serial-out), run on a V4 UniCorn, Core 12556, 2026-11-09" - "WDrijver: ApolloControl CO prints the core number (2026-11-09)" distilled_into: - guides/testing-on-v4-hardware.md - toolchain/vasm-assembler.md - toolchain/c-compiler-options.md - toolchain/pitfalls/float-settings-mismatch.md - - core/cpu-68080/performance-counters.md --- ## Project @@ -48,21 +44,13 @@ knowledge base itself. Done by Claude (AI) with WDrijver, 2026-11-08 to ## What went well -- The CI checks found real errors in reviewed files at once: - - `movec $809,Dn` does not assemble in vasm; `movec ccc,Dn` does. Fixed in - three files. - - The `$DFF300` Maggie counters were used in the knowledge base but - missing from the SAGA register documentation. - - The ApolloCrossDev README listed `moviw.l` and `bcc.s+` as GCC output; - GCC has no patterns for them, only vasm accepts them. +- The CI checks found real errors in reviewed files at once: the `$DFF300` + Maggie counters were used in the knowledge base but missing from the SAGA + register documentation. - `kb:expect` checks catch a stale compiler: a GCC-6.50-Dev built before a fix fails the check of that fix. - The remote test loop from the ApolloOS-Port project worked for the - knowledge base with few changes. Three open questions from step 1 were - measured in one afternoon. -- Alternating variants and printing load addresses (from - [benchmark-method.md](../guides/benchmark-method.md)) turned a confusing - result into a clear one within two runs. + knowledge base with few changes. ## What went wrong @@ -71,27 +59,14 @@ knowledge base itself. Done by Claude (AI) with WDrijver, 2026-11-08 to an install older than its script. - CI failed twice on GitHub 502/504 errors in `check_owners.py`; it retries now. -- `ash` hung on the test V4 (ApolloOS R9.5) until ApolloExplorerSrv was - updated; `acp` worked with the old server. - A CI run after an ApolloCrossDev update rebuilds the toolchain from scratch, which takes more than 30 minutes. -- Three claims in the vasm pitfall did not reproduce with vasm 2.0f. They - stay open until ApolloCrossDev ships vasm 2.0g. ## What the AI got wrong -- **`SER:` is not the debug serial line.** To test the serial log, the AI - wrote `Echo >SER:` on the V4 and listened at 9600 to 115200 baud: nothing - arrived. The cable was fine: the debug output (ApolloLib - `ApolloDebugPutChar()`) writes the Paula UART registers directly at - 115200. A test that does the same was received at once. - **Soft-float links without `-lm`.** The AI built a `-m68080` (soft-float) variant without `-lm`; the link failed on `__mulsf3`. libnix keeps the soft-float routines in `libm`. -- **One run of a benchmark is not a result.** The first `add.l #1,mem` loop - run gave 2 cycles per iteration in two rounds and 21.6 in the third. Only - after printing the counter's address did it show that the counter - shared a cache line with the loop code. - **vasm and `moviw.l #$8123`.** The AI wrote the PRM's example literally; vasm warns "using signed operand as unsigned" and wants `#-32477`. - **Looking for the core number in registers.** The AI looked for the core @@ -101,37 +76,21 @@ knowledge base itself. Done by Claude (AI) with WDrijver, 2026-11-08 to a function in the same file; GCC inlined it, so no call was left to test. The called function must be external. - **Tools that hang.** The first ffmpeg recording from the HDMI capture - hung: the device rejects the default pixel format (`-pixel_format - uyvy422` is needed), and without a timeout nothing stopped it. Every - remote command (ash, acp, ffmpeg) needs a timeout and stdin from - `/dev/null`. + hung, and without a timeout nothing stopped it. Every remote command (ash, + acp, ffmpeg) needs a timeout and stdin from `/dev/null`. ## Evidence | Claim | Source | Core | Method | |---|---|---|---| -| `add.l #1,mem` + `dbra`: 2 cycles per iteration; `dbra` alone and `addq.l #1,Dn` + `dbra`: 1 | (M) | Core 12556 | `tools/v4/tests/add-mem-dbra`, CCC, 65536 iterations, 8 rotating rounds under `Disable()`, V4 UniCorn | -| Same loop, counter in the same 64-byte line as the loop code: 20–23 cycles per iteration (38 once with `(An)`) | (M) | Core 12556 | Same test, counter at 7 distances from the loop, 2 runs | -| Gunnar expects about 1 iteration per cycle | (G) 2026-11-03 | not stated | [caches-and-memory.md](../core/cpu-68080/caches-and-memory.md) | -| `-m68080 -m68881`: 8 cycles per element of a float dot product; `-m68080` alone: 63 | (M) | Core 12556 | `tools/v4/tests/fpu-m68881`, 3 alternating rounds | -| `moviw.l` runs: register, memory and N/Z flags correct; encoded `$303D 8123` | (M) | Core 12556 | `tools/v4/tests/moviw`, 5 passes | -| CCC (`movec ccc,Dn`) reads in user mode | (M) | Core 12556 | All tests above | -| Direct Paula UART writes at 115200 reach the USB serial adapter; `Echo >SER:` does not | (M) | Core 12556 | `tools/v4/tests/serial-out`; `Echo >SER:` listened for at 5 baud rates | | Soft-float routines are in libnix `libm`; `-m68080` with or without `-m68881` links the base multilib `.` | (SRC) | any | `m68k-amigaos-nm` over the libraries; `gcc -print-multi-directory` | -| GCC 6.5 emits `cmpiw.l`, `addiw.l`, `dbra.l`, but never `moviw.l` or `bcc.s+` | (M) | any | `kb:expect` checks in [compiler-variants.md](../toolchain/compiler-variants.md) | -| vasm accepts `movec ccc,Dn` (`$4E7A x809`), not `movec $809,Dn` | (M) | any | Fragment assembly in CI (PR #34) | -| `ash` needs a recent ApolloExplorerSrv; `acp` works with an older one | (M) | Core 12556 | ApolloOS R9.5, before and after the server update | -| Power cycle with a Tasmota plug: the V4 answers `ash` 15 s after power-on | (M) | Core 12556 | `v4test.py power-cycle` | ## Candidates for distillation -- **New `core/pitfalls/data-next-to-running-code.md`:** writing data in the - cache line of running code costs about 10 times as much. First measure it - on Core 12841, and find the exact distance at which the cost starts. - **New `guides/testing-on-v4-hardware.md`:** the remote test loop: - `ash`/`acp` with timeouts; - `ApolloControl CO` for the core number; - - serial output through the Paula UART, not `SER:`; + - serial output through the Paula UART; - HDMI capture with ffmpeg; - power cycling. - **Update `toolchain/vasm-assembler.md` or @@ -140,8 +99,4 @@ knowledge base itself. Done by Claude (AI) with WDrijver, 2026-11-08 to written as negative values. - **Update `toolchain/c-compiler-options.md`:** the multilib that `-m68080` links, and `-lm` for soft-float. -- **Update `core/cpu-68080/performance-counters.md`:** widen - `applies_to.core` once more cores are measured; CCC already works on Core - 12556. Done for the note in PR #41. -- **Update `float-settings-mismatch.md` (done in PR #41):** `-lm` and the - FPU measurement. +- **Update `float-settings-mismatch.md` (done in PR #41):** `-lm`. diff --git a/lessons/2026-11-apolloexplorer.md b/lessons/2026-11-apolloexplorer.md index e675080..9bd6cf3 100644 --- a/lessons/2026-11-apolloexplorer.md +++ b/lessons/2026-11-apolloexplorer.md @@ -4,7 +4,7 @@ type: lesson owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [devs, libraries, general] applies_to: core: "Core 12856" @@ -14,16 +14,13 @@ applies_to: tags: [network, tcp, bsdsocket, arostcp, amitcp-ng, v4net, mtu, systemtaglist, priority, testing] related: - os/pitfalls/v4net-full-size-frames-lost.md - - os/pitfalls/v4-rom-modules-and-reset.md - guides/testing-on-v4-hardware.md sources: - "WDrijver/ApolloExplorer pull request #9, commits 5d466e9 and 4f4b504 (2026-11-16)" - "Test harness tests/aetest.py and tests/mockserver.py in WDrijver/ApolloExplorer" - - "Measured on a V4 UniCorn, Core 12856, v4net.device 3.0, under ApolloOS R9.6 (AROSTCP) and AmigaOS 3.9 (AmiTCP_NG 4.1.8), 2026-11-16" - "ApolloOS source: AROSTCP tcp_usrreq.c, tcp_output.c, kern/uipc_socket.c; rom/dos/systemtaglist.c, createnewproc.c" - "AmiTCP_NG source (github.com/MW0MWZ/AmiTCP_NG): src/netinet/tcp_usrreq.c, src/net/ng_ifconfig.c, src/kern/uipc_socket.c" - "V4Net source (github.com/ApolloTeam-dev/V4Net) and pull request #1: v4net.device 3.1, MTU 1498 (2026-11-24)" - - "Measured on a V4 UniCorn, Core 12856, v4net.device 3.0 and 3.1, under ApolloOS R9.9 (AROSTCP bsdsocket.library 4.57), 2026-11-24 and 2026-11-25" - "WDrijver/ApolloCrossDev issue #33 (GCC-6.50-Dev internal compiler error in bbb pass i)" --- @@ -49,15 +46,9 @@ and fixed there as `v4net.device` 3.1 (V4Net pull request #1, released as protocol directly, so a failure points at the server or the network, not at the Qt clients. A mock server with fault injection (split messages, pings, latency) showed the clients were fine before anyone touched the V4. -- **Narrowing down by size.** Growing a directory listing one entry at a - time showed replies up to 1435 bytes arrive and 1497 bytes never do; a - `ping -D -s` binary search then proved it outside the application. - **Reading the stack and OS sources instead of assuming.** The AROSTCP, AmiTCP_NG and DOS sources answered questions that classic Amiga knowledge would have answered wrongly or not at all (see the evidence table). -- **Before and after numbers for every fix.** Each fix got a test scenario - first (`busy`, `churn --op cd`, `fault split-header`), measured on the old - server, then on the new one, then again under the second OS. - **Remote configuration without seeing the output.** With large replies lost, `Search >NIL:` return codes (0 found, 5 not found) and output-free commands (`Copy`, `Echo >>`) were enough to back up, check and change @@ -68,9 +59,6 @@ and fixed there as `v4net.device` 3.1 (V4Net pull request #1, released as `v4l_TransmitFrame` explained the exact limit (1512 bytes works, 1513 does not), and a driver that reports MTU 1498 fixes every stack and every program at once. -- **The same test harness proved the driver fix.** ApolloExplorerSrv 1.4.2, - which has no workaround, was the test client: with v4net.device 3.0 it - hung, with 3.1 and no configuration every scenario passed. ## What went wrong @@ -78,8 +66,7 @@ and fixed there as `v4net.device` 3.1 (V4Net pull request #1, released as them set `NP_Priority` in the `SystemTagList()` tags, which does nothing on ApolloOS (below), so it could not have worked as intended. - Server threads stuck sending to the V4's lost packets could not be shut - down; switching server versions needed power cycles. A soft reset was - avoided because of `os/pitfalls/v4-rom-modules-and-reset.md`. + down; switching server versions needed power cycles. - Each failed test left a stuck session on the old server until it was restarted. - The fix that passed every test under ApolloOS failed under AmigaOS, because @@ -96,15 +83,10 @@ and fixed there as `v4net.device` 3.1 (V4Net pull request #1, released as - **Blamed the server code first.** From the code review alone, the AI ranked five server bugs as the likely causes. They were real, but the main cause was the V4's Ethernet driver (`os/pitfalls/v4net-full-size-frames-lost.md`). - Only measuring on the V4 found it. - **Assumed `TCP_MAXSEG` works on every stack.** It read the AROSTCP source and stopped there; the server also ignored the `setsockopt()` result. AmiTCP_NG does not implement the option, so under AmigaOS 3.9 the fix did nothing and failed silently. -- **Blamed the driver for loss it did not cause.** Under ApolloOS, about one - packet per 4 MB was lost in bursts; the AI attributed that to the driver. - Under AmigaOS 3.9 with the same driver and core, 4 MB downloads showed no - loss at all, so it is not the driver alone. The cause is still unknown. - **Misread a test failure.** A download that failed with "0 of 12 header bytes" was first read as the server not sending its 16-byte acknowledgement. Reading the server code showed the acknowledgement was @@ -115,8 +97,6 @@ and fixed there as `v4net.device` 3.1 (V4Net pull request #1, released as - **Proposed an ApolloOS issue for the driver.** `v4net.device` is not in the ApolloOS repository; it lives in the apollo-core SVN (`apollo_software/net/V4Net`) and also runs on AmigaOS. -- **Waited 3 minutes after a power cycle.** The V4 is up in 15 to 35 s - (`guides/testing-on-v4-hardware.md`); a timeout should be based on that. - **Got a protocol constant wrong in its own test tool.** It treated 0 as success for `PMT_MKDIR`; the server answers `AT_OK` (1). - **Took the OS from the discovery reply again.** The second test V4 @@ -132,19 +112,11 @@ and fixed there as `v4net.device` 3.1 (V4Net pull request #1, released as | Claim | Source | Core | Method | |---|---|---|---| -| The V4 never sends a 1500-byte IP packet; 1498 bytes works; receiving 1500 works | (M) | Core 12856 | `ping -D -s` binary search, size sweep 0 to 1470, TCP upload; v4net.device 3.0, ApolloOS R9.6 and AmigaOS 3.9 | -| `TCP_MAXSEG` 1400 on the accepted socket fixes large replies under AROSTCP | (M) | Core 12856 | `tests/aetest.py smoke/shell/transfer` on ApolloOS R9.6: all timed out before, all pass after | | `TCP_MAXSEG` can only lower the MSS a connection negotiated, so it must be set after `accept()`/`connect()` | (SRC) | any | AROSTCP `netinet/tcp_usrreq.c` | | AmiTCP_NG 4.1.8 rejects `TCP_MAXSEG` with `EINVAL`; it reads `mtu=` from the interface file | (SRC) | any | AmiTCP_NG `src/netinet/tcp_usrreq.c` ("not yet"), `src/net/ng_ifconfig.c` | -| `mtu=1492` in `DEVS:NetInterfaces/V4net` fixes large replies under AmiTCP_NG | (M) | Core 12856 | AmigaOS 3.9: replies up to 3771 bytes arrive; every `tests/aetest.py` scenario passes | | AROSTCP and AmiTCP_NG both support `SO_RCVTIMEO`/`SO_SNDTIMEO`; non-blocking only via `FIONBIO` (no `MSG_DONTWAIT`) | (SRC) | any | AROSTCP and AmiTCP_NG `kern/uipc_socket.c` | | `NP_Priority` in `SystemTagList()` tags is ignored: its own `NP_Priority` (the caller's) comes first and `CreateNewProc()` uses the first match | (SRC) | any | ApolloOS `rom/dos/systemtaglist.c` (`TAG_MORE` after its defaults), `createnewproc.c` (`ApplyTagChanges`) | -| A shell command started from a priority-8 task starves AROSTCP: no new connection for 9.5 s during `List SYS: ALL` | (M) | Core 12856 | `tests/aetest.py busy` on ApolloOS R9.6; with `SetTaskPri(0)` around `SystemTagList()`: 46 replies, median 56 ms; on AmigaOS 3.9: 89 replies, median 36 ms | -| A finished session left its server thread alive ~60 s: 30 sessions held 4.6 MB, all back after 90 s | (M) | Core 12856 | `tests/aetest.py churn --avail`; after the fix -19 KB (ApolloOS), -15 KB (AmigaOS) | -| A header split with a 200 ms gap dropped the connection (50 `FIONREAD` polls without waiting) | (M) | Core 12856 | `tests/aetest.py fault split-header`, before and after | | Since 2.97.2 `v4l_TransmitFrame` declares the TX length rounded up to a longword: a 1513/1514-byte frame becomes 1516, 1520 with CRC, over the 1518-byte limit | (SRC) | any | V4Net `source/v4net/v4l.c`, `CHANGELOG.txt` | -| v4net.device 3.1 (MTU 1498) fixes large replies with no configuration and no application workaround | (M) | Core 12856 | ApolloOS R9.9, ApolloExplorerSrv 1.4.2: `tests/aetest.py` smoke, shell, transfer, concurrent pass; with 3.0 they hang. With 1.4.4: 4 × 200 sessions, 20 transfers up to 10 MB, 6 parallel clients, 0 failures | -| About one lost packet per 4 MB (1.2 to 1.5 s stall) under ApolloOS; none under AmigaOS | (M) | Core 12856 | Per-chunk arrival times of 4 MB downloads: ApolloOS R9.6 with `TCP_MAXSEG` 1400, 1.1 to 1.25 MB/s; AmigaOS 3.9 with `mtu=1492`, 4.2 to 4.3 MB/s, largest gap 15 ms | ## Candidates for distillation @@ -161,10 +133,7 @@ and fixed there as `v4net.device` 3.1 (V4Net pull request #1, released as AmigaOS), which socket options each supports, and the interface configuration keywords such as `mtu=`. The knowledge base has nothing on networking yet. -- **The lost packets under ApolloOS.** Not the driver alone (none under - AmigaOS with the same driver). Compare AROSTCP and AmiTCP_NG at the same - MSS before filing anything. - **A guide for testing network services on V4** (`guides/`): a protocol-level harness separate from the client, a mock server for the - client side, ping size sweeps, `Search >NIL:` return codes when output - cannot come back, and before/after numbers per fix. + client side, and `Search >NIL:` return codes when output cannot come + back. diff --git a/lessons/2026-11-lide-device.md b/lessons/2026-11-lide-device.md index 76af324..a053ff0 100644 --- a/lessons/2026-11-lide-device.md +++ b/lessons/2026-11-lide-device.md @@ -4,7 +4,7 @@ type: lesson owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain, devs] applies_to: core: "any" @@ -20,7 +20,6 @@ related: sources: - "lide.device V4 backend 48.14 (ApolloSoftware Drivers/scsi.device), Makefile change of 2026-11-24" - "ApolloCrossDev GCC-6.50-Dev, macOS install built 2026-11-16; GCC-6.50-Dev-MacOS.sh and GCC-6.50-Dev-Linux.sh at commit 053c5ad10 (2026-11-24)" - - "Link tests with m68k-amigaos-ld and vasm 2.0g, objdump -h and nm on the result, 2026-11-24" --- ## Project @@ -37,10 +36,6 @@ tested the new build on a V4 and reported it OK on 2026-11-24. - All four variants (cache, no cache, no read-ahead, experimental postinc) built with GCC-6.50-Dev without errors or warnings on the first attempt. -- `-m68080` accepts the `move16 (a0)+,(a1)+` inline assembler of the read - path; `-mcpu=68060` is not needed for MOVE16. -- Linking an unstripped copy and comparing `nm -n` and `objdump -s` with the - old build caught a layout change that a successful build did not show. ## What went wrong @@ -48,30 +43,16 @@ tested the new build on a V4 and reported it OK on 2026-11-24. installed; the build failed until the compiler path was changed. - The NDK 3.2 path from the KB and the Makefile template, `/m68k-amigaos/ndk32-include/Include_H`, does not exist in this - install. NDK 3.2 is installed as `/m68k-amigaos/ndk-include` - (`exec/execbase.h` 47.2). There is no `ndk39-include` either; only - `ndk13-include`. Neither install script (`GCC-6.50-Dev-MacOS.sh`, + install. Neither install script (`GCC-6.50-Dev-MacOS.sh`, `-Linux.sh`) creates `ndk32-include` or `ndk39-include`; they run amiga-gcc `make all NDK=3.2`, which installs into `ndk-include`. -- The missing include path is silent: GCC ignores a `-I` folder that does - not exist, and `ndk-include` is on its built-in search path, so the - template still builds, with NDK 3.2 by accident rather than by its setting. - Selecting NDK 3.9 through the template would also fall back to 3.2 without - any message. - `apollo-build`'s `find-acd.sh` does not check that the NDK folders exist. -- After the vasm conversion, `_endskip` (the `rt_EndSkip` target, linked last - to mark the end of the resident) ended up at offset 0 of a separate code - hunk instead of at the end of the device. The build gave no warning. ## What the AI got wrong - It first planned to build with the project's own Makefile flags (`-mcpu=68060`, GCC-6.50-Stable) because they were "tested on hardware", and only switched when the developer asked for the AKB defaults. -- It wrote the vasm sources with `section code,code`, as in the KB vasm - example, assuming the linker would merge them into the GCC code hunk. It - did not: the hunk name decides merging, and only `.text` merges with GCC's - code. - On macOS it created `bootblock.s` and then ran `rm bootblock.S`. The default macOS filesystem is case-insensitive, so both names are the same file and the new source was deleted. Renaming `.S` to `.s` on macOS needs @@ -84,35 +65,18 @@ tested the new build on a V4 and reported it OK on 2026-11-24. | Claim | Source | Core | Method | |---|---|---|---| -| A vasm `-Fhunk` section named `code` or `CODE` stays a separate hunk when linked with GCC objects by `m68k-amigaos-ld`; a section named `.text` is merged into GCC's code hunk | (M) 2026-11-24 | none (host) | One C object plus a vasm object with `section ,code`; `objdump -h` shows 2 sections for `code`/`CODE`, 1 for `.text`; `nm` places the vasm symbol at 0 of its own hunk or after the C code | -| In lide.device, `section .text,code` gives the same layout as the old gas build: `_endskip` and `_bootblock` after the C and libc code, boot block 0x22 bytes with identical bytes | (M) 2026-11-24 | none (host) | Unstripped link of old and new objects, `nm -n`, `objdump -s` | -| The GCC-6.50-Dev install has `ndk-include` (NDK 3.2, `execbase.h` 47.2) and `ndk13-include`, no `ndk32-include` or `ndk39-include` | (M) 2026-11-24 | none (host) | `ls /m68k-amigaos`, install built 2026-11-16 | | The install scripts do not create `ndk32-include` or `ndk39-include` | (SRC) `GCC-6.50-Dev-MacOS.sh`, `GCC-6.50-Dev-Linux.sh` at 053c5ad10 | none | `grep ndk`; NDK only through `make all NDK=3.2` | -| A missing `-I` folder is ignored; `` then comes from `ndk-include` | (M) 2026-11-24 | none (host) | `m68k-amigaos-gcc -H -E` with `-I.../ndk32-include/Include_H` | -| `-m68080` accepts MOVE16 in inline assembler | (M) 2026-11-24 | none (host) | Build without `-mcpu=68060`; `objdump -d` shows 113 `move16` in the postinc variant | -| The installed vasm is 2.0g; the KB names 2.0f | (M) 2026-11-24 | none (host) | `vasmm68k_mot -v` | | The 48.14 build with the AKB defaults (GCC-6.50-Dev, `-O2 -m68080`, vasm) works on a V4 | Developer report, 2026-11-24 | not recorded | Hardware test of the built device | -| `-O2` instead of `-Os` makes the device about 4 KB larger (28216 to 32536 bytes) | (M) 2026-11-24 | none (host) | File size of `build/scsi.device` before and after | ## Candidates for distillation - `toolchain/target-os-headers.md` and `toolchain/c-compiler-options.md`: correct the NDK paths to what the install scripts create (`ndk-include` for NDK 3.2), or record which ApolloCrossDev version creates - `ndk32-include/Include_H` and `ndk39-include`. Mention that a wrong NDK - path is silent. + `ndk32-include/Include_H` and `ndk39-include`. - ApolloCrossDev `Projects/_makefiles/Makefile`: same path fix, or a check that fails when `C_INCL_NDK` does not exist. - `skills/apollo-build/scripts/find-acd.sh`: report a `PROBLEM=` when the NDK folder the template uses is missing. -- New `toolchain/pitfalls/vasm-section-name-hunk-merge.md`: when vasm objects - are linked with GCC objects, use `section .text,code` (and `.data`/`.bss`) - when the code must share GCC's hunk: resident end markers (`rt_EndSkip`), - single-hunk devices and ROM modules, 16-bit PC-relative references between - C and assembler. Change the example in `toolchain/vasm-assembler.md` - accordingly or add a note to it. -- `toolchain/vasm-assembler.md`: vasm version 2.0g in current installs. -- `toolchain/c-compiler-options.md`: note that `-m68080` covers MOVE16, so - code that used `-mcpu=68060` / `-m68060` for MOVE16 can drop it. -- `toolchain/pitfalls/gcc-misc-traps.md` or a host note: on macOS, `foo.S` +- A toolchain pitfall or a host note: on macOS, `foo.S` and `foo.s` are the same file. diff --git a/lessons/2026-11-v4-turtle-mode.md b/lessons/2026-11-v4-turtle-mode.md deleted file mode 100644 index 6176328..0000000 --- a/lessons/2026-11-v4-turtle-mode.md +++ /dev/null @@ -1,109 +0,0 @@ ---- -title: Turtle mode on the V4 - what it slows down and what it does to the counters -type: lesson -owner: WDrijver -status: draft -origin: ai-assisted -basis: [measured] -components: [cpu-68080, hardware] -applies_to: - core: "Core 12856" - os: [apolloos-r10] - mode: [any] - board: [v4-unicorn] -tags: [turtle, apollocontrol, pcr, ccc, iep, counters, superscalar, benchmark, speed] -related: - - core/cpu-68080/performance-counters.md - - core/cpu-68080/core-at-a-glance.md - - guides/benchmark-method.md - - guides/testing-on-v4-hardware.md -sources: - - "Probe programs run remotely on a V4 UniCorn, Core 12856, ApolloOS R10 dev card, 2026-11-25: one run per mode (full speed, TU=3, TU=2, TU=1), each after a power cycle" - - "ApolloControl 2.23 (28.10.2026) template: TU=TURTLE/N 0=Off, 1=A500, 2=A1200, 3=A4000" -distilled_into: - - core/pitfalls/turtle-mode-counters.md - - core/cpu-68080/performance-counters.md - - core/cpu-68080/core-at-a-glance.md - - guides/testing-on-v4-hardware.md ---- - -## Project - -Measuring how a V4 behaves in each Turtle mode, as part of probing the -68080 for a debugging and remote-control tool. Done by Claude (AI) with -WDrijver on 2026-11-24 and 2026-11-25, on the V4 UniCorn test machine -(Core 12856, ApolloOS R10 dev card, RTG Workbench). Each mode was set -with `ApolloControl TU=n` right after a power cycle, then the same probe -programs ran: counted loops read with CCC and IEP1-IEP3, a timing of -CCC against the E-clock, PCR reads, and the trace bits. - -## What went well - -- `ApolloControl TU=n` switches the mode at once, without a reboot, and - a power cycle returns to full speed (TU=0). -- The network stack, a remote shell and file transfers kept working in - every Turtle mode, just slower, so the whole run could be unattended. -- The same counted loops in every mode gave clean, repeatable numbers - (5 runs per loop, within a few percent). - -## What went wrong - -- In Turtle 1, a 60-second CPU-bound loop kept the V4 from answering on - the network for about two minutes. A remote runner with a short - timeout took that for a hang and power-cycled a machine that was - still working. (Observation, one occurrence.) -- A remote directory listing that takes well under a second at full - speed did not finish within 30 s in Turtle 1, so a script with fixed - timeouts lost its results. Timeouts that suit full speed are too short - in Turtle mode. - -## What the AI got wrong - -- **It measured the slowdown with a network-bound job.** Timing a small - remote job (a file hash over the network) gave 4x, 12x and 22x for - TU=3, 2, 1. Counted CPU loops show 4.5x, 89x and 177x: the network - part hid most of the slowdown in Turtle 1 and 2. -- **It expected a lower clock.** A MHz value estimated from the board's - multiplier reads 99.2 MHz in every mode, and CCC really does run at - 99.3 MHz in every mode. Turtle does not lower the clock; it makes each - instruction take more cycles. -- **It trusted PCR bit 0 for the number of pipes.** PCR bit 0 (second - pipe) stays 1 in every Turtle mode, yet IEP2 stays 0: only one pipe - issues. -- **It read IEP1 as an instruction count.** In Turtle mode IEP1 follows - CCC (94-97 % of it), so it counts cycles, not instructions: 2.5, 48 and - 96 counts per real instruction in TU=3, 2, 1. - -## Evidence - -All (M): V4 UniCorn, Core 12856, ApolloOS R10, 2026-11-25. Loops of -224007 independent ALU instructions, 32768 memory instructions and -112003 instructions with branches, read with `movec` CCC/IEP1/IEP2 in -user mode, 5 runs each (run 0 shown, the others within 4 %). - -| Claim | Source | Core | Method | -|---|---|---|---| -| Independent ALU loop takes 128185 / 581499 / 11405896 / 22721312 CCC at full speed / TU=3 / TU=2 / TU=1: 1.0x / 4.5x / 89x / 177x | (M) | Core 12856 | counted loop, CCC | -| Memory loop: 16697 / 82644 / 1411433 / 2879166 CCC (1.0x / 4.9x / 85x / 172x); branch loop: 96183 / 625994 / 5717206 / 11239674 CCC (1.0x / 6.5x / 59x / 117x) | (M) | Core 12856 | counted loops, CCC | -| CCC runs at 99.32 MHz in every mode, working and sleeping (within 1 %) | (M) | Core 12856 | CCC against the E-clock over timer waits | -| Only one pipe issues in TU=1, 2 and 3: IEP2 = 0; at full speed IEP1 + IEP2 = 224017 for 224007 instructions | (M) | Core 12856 | IEP1, IEP2 over the independent loop | -| In Turtle mode IEP1 is 94-97 % of CCC (564686, 10874762, 21430313 for TU=3, 2, 1), not the instruction count | (M) | Core 12856 | IEP1 against CCC, same loop | -| PCR reads `$04400101` at full speed, `$04400141` in TU=3, `$044001C1` in TU=2, `$04400181` in TU=1: bits 7-6 change with the mode, bit 0 stays 1 | (M) | Core 12856 | `movec` PCR in supervisor and user mode (same value) | -| Trace bits behave the same in every mode: T1 gives a trace exception per instruction (6 of 6), T0 gives none | (M) | Core 12856 | trace test with T1, then T0 | -| A remote file hash took 0.04 / 0.15 / 0.47 / 0.88 s at full speed / TU=3 / TU=2 / TU=1 | (M) | Core 12856 | same small file, over the network | - -## Candidates for distillation - -- `core/cpu-68080/performance-counters.md`: add that in Turtle mode IEP1 - counts cycles, IEP2 reads 0, and the pipe-count rule ("IEP2 < n/16: 1 - pipe") answers 1 pipe; CCC keeps its rate. Add the PCR bits 7-6 values - per mode (needs a check on another core before it becomes a rule). -- New `core/pitfalls/turtle-mode-counters.md`: DON'T benchmark or count - instructions in Turtle mode; check PCR bits 7-6 (or set TU=0) before - timing code, and don't read PCR bit 0 as "two pipes are issuing". -- `guides/testing-on-v4-hardware.md`: remote timeouts in Turtle mode - (minutes, not seconds), and measure the slowdown with a CPU loop, not - a network job. -- `core/cpu-68080/core-at-a-glance.md`: one line on Turtle mode (single - issue, same clock, 4.5x / 89x / 177x slower for TU=3 / 2 / 1 on - Core 12856). diff --git a/os/apolloos-and-amigaos-on-v4.md b/os/apolloos-and-amigaos-on-v4.md index 38565a1..0c6b573 100644 --- a/os/apolloos-and-amigaos-on-v4.md +++ b/os/apolloos-and-amigaos-on-v4.md @@ -26,7 +26,7 @@ OS-specific guidelines yet. ### Detecting Apollo V4 hardware Gate 68080 code on AttnFlags bit 10 and FPU code on the 68881 flag at run -time: see [best-practices/detect-68080-and-fpu-at-run-time.md](best-practices/detect-68080-and-fpu-at-run-time.md). +time. ### OS functions per target OS @@ -40,10 +40,7 @@ No content yet. ### Known traps on V4 under AmigaOS -See `os/pitfalls/`: stack patches hiding small-stack bugs, library globals -shared between tasks, V4 ROM modules and soft resets, and `ramlib` reusing a -library by name. `CacheClearU` doing nothing on the 68080 is in -[core/pitfalls/self-modifying-code-and-caches.md](../core/pitfalls/self-modifying-code-and-caches.md). +See `os/pitfalls/`. ## Differences from AmigaOS / AROS / 68060 diff --git a/os/best-practices/detect-68080-and-fpu-at-run-time.md b/os/best-practices/detect-68080-and-fpu-at-run-time.md deleted file mode 100644 index d777ddb..0000000 --- a/os/best-practices/detect-68080-and-fpu-at-run-time.md +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: Detect the 68080 and the FPU at run time -type: best-practice -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [general, cpu-68080] -applies_to: - core: "Core 12798-12841" - os: [amigaos-3.9, amigaos-3.2] -tags: [attnflags, detection, 68080, fpu, execbase, libraries] -related: - - core/cpu-68080/core-at-a-glance.md - - toolchain/best-practices/gcc-code-generation-for-68080.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 1, 9.1 and 13" ---- - -## Goal - -Correctness and portability: run 080-specific and FPU code only where it -works, and keep one binary usable on other CPUs or with the FPU switched off. - -## Technique - -- Gate 080 code paths on `AttnFlags & (1 << 10)` in ExecBase. -- Gate FPU code paths on the 68881 flag **at run time**. The FPU can be - switched off (vampiresupport.resource); AttnFlags then reads `$040f` - instead of `$847f`. -- In a library, do the check in LibInit, and build that object with - `-m68020` so it runs on any CPU before it decides. - -```c -#include -#include - -extern struct ExecBase *SysBase; - -BOOL has_68080(void) { return (SysBase->AttnFlags & (1 << 10)) != 0; } -BOOL has_fpu(void) { return (SysBase->AttnFlags & AFF_68881) != 0; } -``` - -## Evidence - -| Variant | Measurement | Core | Test setup | -|---|---|---|---| -| FPU on | AttnFlags = `$847f` | Core 12798-12841 | AmigaOS 3.9 (M) | -| FPU off | AttnFlags = `$040f` | Core 12798-12841 | Same | - -## When not to use - -- In an os-takeover program that you only ship for the V4, a single check at - start-up is enough; don't test in inner loops. -- The DevPac include set redefines `AFB_68080`; use the NDK includes (plus - DevPac `funcdef.i`) so the flag name matches. diff --git a/os/libraries/maggie-library.md b/os/libraries/maggie-library.md index baf5611..00c9536 100644 --- a/os/libraries/maggie-library.md +++ b/os/libraries/maggie-library.md @@ -4,7 +4,7 @@ type: reference owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [libraries, saga-3d-maggie] applies_to: core: "Core 12841+" @@ -14,8 +14,6 @@ related: - os/pitfalls/maggie-library-side-effects.md - os/libraries/maggie-library-functions.md - core/saga-3d-maggie/registers.md - - core/pitfalls/maggie-depth-test-colour-write.md - - core/pitfalls/maggie-span-tail.md sources: - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 15.1 and 15.3-15.8" - "maggie.library source, github.com/RMortenB/MaggieLibrary, commit 64c78ef (2026-08-17), MaggieLibrary_API.md" @@ -34,8 +32,7 @@ before using it: a call changes your task's FPCR and E registers. Source: , the golden source. These notes were read against commit `64c78ef` (2026-08-17); the full API is in `MaggieLibrary_API.md`, and every function with its registers is in -[maggie-library-functions.md](maggie-library-functions.md). Version tested on a V4: `maggie 4.0 (Sep 9 2026)`, -AmigaOS 3.9. +[maggie-library-functions.md](maggie-library-functions.md). ### Linking and building (SRC) @@ -160,9 +157,6 @@ per draw (`magSetRGB`), multiplied with the texture and the light. and setup times per frame. "Spans" is the raster; "Setup" is the CPU work (transform, clipping, setup, edge walk). `PROFILE=2` adds a per-edge timer, which doubles the edge cost. -- The FPU rules apply to your own transform code: one FP register write per - cycle, fmul 5 and fadd 6 cycles of latency, 3 cycles per FP-to-integer - conversion (see [core/cpu-68080/fpu-performance-model.md](../../core/cpu-68080/fpu-performance-model.md)). ## Differences from AmigaOS / AROS / 68060 diff --git a/os/libraries/workbench-wbconfig.md b/os/libraries/workbench-wbconfig.md index 7f0b296..4861ccd 100644 --- a/os/libraries/workbench-wbconfig.md +++ b/os/libraries/workbench-wbconfig.md @@ -4,7 +4,7 @@ type: reference owner: WDrijver status: draft origin: ai-assisted -basis: [measured, other] +basis: [other] components: [libraries] applies_to: core: "any" @@ -14,8 +14,6 @@ tags: [workbench, wbconfig, iprefs, wbpattern, backdrop, wallpaper, icon-font, f sources: - "Disassembly of AmigaOS 3.5 C:IPrefs 44.23 (30.11.1999) and AmigaOS 3.9 workbench.library 45.102, 2026-11-18" - "ApolloOS-Port commits 2e09af9, cfe53b4 and 2a68741 (2026-11-18): workbench/c/iprefs/wbpatternprefs.c, fontprefs.c, workbench/prefs/wbpattern/" - - "File format measured with R9.6's Prefs/WBPattern on an Apollo V4, ApolloOS R10 dev card, 2026-11-18 (one option per save, file compared)" - - "Hardware test on an Apollo V4, ApolloOS R10 dev card, 2026-11-18: wallpaper and XEN 9 icon labels at boot with only R10's IPrefs" --- ## Summary @@ -24,8 +22,7 @@ The AmigaOS 3.5/3.9 Workbench does not read `WBPattern.prefs` or the icon font from `font.prefs` itself. IPrefs loads them and hands them over through the private, undocumented `WBConfig()` call of workbench.library. ApolloOS R10 runs the AmigaOS 3.9 workbench.library (45.102), so its own IPrefs uses -the same call; this file documents it, and the `WBPattern.prefs` format of -the 3.5+ WBPattern editor. +the same call; this file documents it. ## Details @@ -93,35 +90,6 @@ frees the bitmap), then the struct (`AllocVec`/`FreeVec` in 44.23). To free a returned struct: `CloseFont()` on +4, then the struct. -### WBPattern.prefs (AmigaOS 3.5+ editor format) - -`ENV:Sys/WBPattern.prefs`, `FORM PREF` with these chunks in this order: - -| Chunk | Size | Contents | -|---|---|---| -| `PRHD` | 6 | prefs header, all 0 | -| `FIP0` | 4 | one option byte per placement (Workbench, Windows, Screen), then one global byte | -| `WPOS` | 4 | `$0000000B` as the editor writes it; meaning unknown, keep it as read | -| `PTRN` | 24 + n | one per placement: `struct WBPatternPrefs` (`prefs/wbpattern.h`), then n data bytes | - -`FIP0` option byte of a placement: - -| Bits | Meaning | -|---|---| -| `$0F` | precision: 0 Image, 1 Icon, 2 GUI, 3 Exact, 4 True-color, 5 None | -| `$10` | "Standard" (set in all four bytes by the editor's Standard gadget) | -| `$20` | centre the picture | -| `$40` | tile the picture | -| `$80` | fill the border (only together with `$20`) | - -The global (4th) byte: `$02` = "Lock pens 4-7". - -`PTRN`: `wbp_Which` = 0 Workbench, 1 Windows, 2 Screen. A picture has -`wbp_Flags` bit `WBPF_PATTERN` clear and the file name (with its NUL) as data. -A pattern has `WBPF_PATTERN` set and the planar 16x16 pattern as data; the -editor writes an all-zero 96-byte pattern for "no backdrop". The centre / -tile / fill options are **not** in `wbp_Flags`; they are in `FIP0`. - ## Differences from AmigaOS / AROS / 68060 - **AROS:** `WBConfig()` is a stub in AROS's workbench.library, and AROS's @@ -132,8 +100,6 @@ tile / fill options are **not** in `wbp_Flags`; they are in `FIP0`. after `DTM_PROCLAYOUT`, as AmigaOS's picture.datatype does. If it returns the source bitmap, the Workbench shows no backdrop (fixed in ApolloOS R10, ApolloOS-Port commit 9617ad6). -- **The prefs file** of the 3.5+ editor keeps its options in `FIP0`; reading - `wbp_Flags` for them (as older code does) finds 0. ## Do / Don't diff --git a/os/pitfalls/aros-exec-differs-for-amigaos-modules.md b/os/pitfalls/aros-exec-differs-for-amigaos-modules.md index 9a31ce2..3752ee4 100644 --- a/os/pitfalls/aros-exec-differs-for-amigaos-modules.md +++ b/os/pitfalls/aros-exec-differs-for-amigaos-modules.md @@ -4,7 +4,7 @@ type: pitfall owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [libraries, devs, filesys] applies_to: core: "any" @@ -14,9 +14,8 @@ applies_to: tags: [exec, waitio, iof-quick, initresident, romtag, etd, trackdisk, fat95, expansion-rom] related: - os/apolloos-specific-on-v4.md - - os/pitfalls/v4-rom-modules-and-reset.md sources: - - "ApolloOS-Port R8, commits ce4f7f7 (InitResident), 4a2be87 (WaitIO), 433fe9a (diskimage.device); V4 tests 2026-11-24 with EXP 48.12-beta" + - "ApolloOS-Port R8, commits ce4f7f7 (InitResident), 4a2be87 (WaitIO), 433fe9a (diskimage.device)" - "(SRC) AROS rom/exec/waitio.c, rom/exec/initresident.c; fat95 src/fat95.s (ChangeReport, OpenAll, DiskUpdate)" --- @@ -93,6 +92,5 @@ never sent, and RomTag init code must save the registers it uses. | Claim | Source | Core | Method | |---|---|---|---| -| fat95 calls `WaitIO` on an unsent `IOF_QUICK` request; AROS removed the unqueued node | (M) 2026-11-24, (SRC) fat95.s ChangeReport | Core 12856 | Traced fat95 build on a V4; request dump: `ln_Type` 7, `io_Flags` 1, succ/pred 0; fixed WaitIO: FAT image and FAT32 SD mount, hot-swap OK | -| fat95 init changes `d4`; AROS InitCode loses its loop state | (M) 2026-11-24 | Core 12856 | exfat-handler and sagasd.device not started; started after InitResident saved d2-d7/a2-a6 | -| diskimage.device without `ETD_UPDATE` makes fat95 write-protect the volume | (M) 2026-11-24, (SRC) fat95.s DiskUpdate | Core 12856 | Copy/MakeDir on a fat95-mounted FAT16 image fail, pass after the fix; `fsck_msdos` clean | +| fat95 calls `WaitIO` on an unsent `IOF_QUICK` request; AROS removed the unqueued node | (SRC) fat95.s ChangeReport, AROS rom/exec/waitio.c | any | Source reading | +| diskimage.device without `ETD_UPDATE` makes fat95 write-protect the volume | (SRC) fat95.s DiskUpdate | any | Source reading | diff --git a/os/pitfalls/background-process-leaks-memory.md b/os/pitfalls/background-process-leaks-memory.md index 79ec61b..9a65865 100644 --- a/os/pitfalls/background-process-leaks-memory.md +++ b/os/pitfalls/background-process-leaks-memory.md @@ -4,19 +4,16 @@ type: pitfall owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [commands, libraries, general] applies_to: core: "any" os: [apolloos-r10] mode: [os-friendly] tags: [memory-leak, lock, progdir, shell, systemtags, run, task-resource, arexx, daemon] -related: - - os/pitfalls/library-globals-shared-between-tasks.md sources: - "ApolloOS-Port (github.com/ApolloTeam-dev/ApolloOS-Port), commits 6739caa (Shell) and 1766c2e (task.resource), 2026-11-23" - "ApolloOS legacy tree (github.com/ApolloTeam-dev/ApolloOS, master 0645ecc): compiler/include/dos/cliinit.h, rom/task/task_execfuncs.c, rom/task/task_support.c" - - "ApolloOS-Port test/tools/SysAsync.c, RexxSend.c, OpenLib.c (measurements on a V4 with the R10 dev ROM, 2026-11-23)" --- ## Symptom @@ -24,12 +21,10 @@ sources: A program that starts processes in the background, such as a daemon calling `SystemTags(..., SYS_Asynch, TRUE, ...)`, a script using `Run`, or RexxMast starting one process per ARexx message, slowly loses free -memory. Each start loses up to about 100 bytes: +memory. Each start loses: -- 72 bytes for a lock on SFS when the starting program sits on an SFS - volume. On RAM: the loss is hidden, because the RAM handler allocates - from a pool. -- 32 bytes when the started command is a C program. +- a lock on the starting program's drawer; +- a task.resource hook entry when the started command is a C program. After a few starts from a program in drawer `X`, that drawer can no longer be deleted ("object in use"), even though nothing is running in it any more. @@ -52,7 +47,7 @@ There are two independent bugs, in two ROM modules. (`compiler/startup/startup.c`) calls `InitTaskHooks()` in every C program. That call adds a `TaskListHookEntry` to the task's entry in task.resource. When the task ends, task.resource frees the task entry - but not the hook entry: 32 bytes per process that ran a C program. A + but not the hook entry: one per process that ran a C program. A long-running Shell keeps its entry, so running commands one after the other from one Shell shows no loss. Only new processes do. @@ -108,7 +103,7 @@ SetProgramDir(home); This workaround follows from the source and was not measured. Do not use PROGDIR: in other tasks of the same process while it is cleared. The -32-byte task.resource loss has no workaround in the application. +task.resource loss has no workaround in the application. ## Detection @@ -126,9 +121,4 @@ PROGDIR: in other tasks of the same process while it is cleared. The | Claim | Source | Core | Method | |---|---|---|---| -| Async start from a starter on SFS: 72 bytes (resident Echo), 104 bytes (C program); from a starter on RAM: 0 / 32 | (M) 2026-11-23 | R10 dev ROM on V4 (core not recorded) | test/tools/SysAsync, 20 or 100 starts, AvailMem difference | -| The starter's drawer stays "in use" after async starts; deletable after a plain `CreateNewProc` | (M) 2026-11-23 | same | fresh drawer on SFS, 3 or 20 starts, then `Delete` | -| Plain `CreateNewProc()` processes leak nothing; a no-startup HUNK program leaks nothing | (M) 2026-11-23 | same | SysAsync PROC mode; hand-made 2-instruction HUNK | -| Shell with the `UnLock`: 0 bytes, drawer deletable | (M) 2026-11-23 | same | fixed Shell made resident, started via `SYS_CustomShell` | -| With both fixes in the ROM: 0 bytes per ARexx message (before ~107) and per async start; 360 parallel RX calls cost 144 bytes (log files) instead of ~40 KB | (M) 2026-11-23 | same | test/tools/RexxSend, three parallel RX loops | | The legacy ApolloOS tree has the same code | (SRC) | any | ApolloOS master 0645ecc: cliinit.h line 170, rom/task FreeMem sites | diff --git a/os/pitfalls/library-globals-shared-between-tasks.md b/os/pitfalls/library-globals-shared-between-tasks.md deleted file mode 100644 index ad0079b..0000000 --- a/os/pitfalls/library-globals-shared-between-tasks.md +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: Library globals are shared between calling tasks -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [libraries] -applies_to: - core: "any" - os: [amigaos-3.9, amigaos-3.2] -tags: [libraries, reentrancy, race, tasks, stackswap] -related: - - os/pitfalls/stack-patches-hide-small-stack-bugs.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 13" ---- - -## Symptom - -A shared library works with one caller but crashes or mixes up data when -several tasks call it at the same time, for example several player tasks -using one decoder library. - -## Cause - -Library globals, and data in the library base, are shared by every task that -calls the library. A per-base `StackSwapStruct`, for example, is overwritten -by the second caller while the first is still using it. - -## Wrong - -```c -struct MyLibBase { - struct Library lib; - struct StackSwapStruct sss; /* one for all callers */ -}; -``` - -## Right - -Keep per-call state on the stack or in a block allocated per call (or per -opener), never in the library base or in globals: - -```c -LONG decode(struct MyLibBase *base, struct Frame *f) -{ - struct StackSwapStruct sss; /* per call */ - /* ... */ -} -``` - -## Detection - -Look for writable globals and writable fields in the library base that are -used during a call. Test with two or more tasks calling at once. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| A per-base StackSwapStruct raced with several player tasks | (M) | any | MP3 library on AmigaOS 3.9 | diff --git a/os/pitfalls/locale-preflanguages-native-names.md b/os/pitfalls/locale-preflanguages-native-names.md index d6fdf44..f51224b 100644 --- a/os/pitfalls/locale-preflanguages-native-names.md +++ b/os/pitfalls/locale-preflanguages-native-names.md @@ -4,7 +4,7 @@ type: pitfall owner: WDrijver status: draft origin: ai-assisted -basis: [source-code, measured] +basis: [source-code] components: [libraries] applies_to: core: "any" @@ -79,4 +79,3 @@ per-language files (not only its catalog) appear. Print | Claim | Source | Core | Method | |---|---|---|---| | `loc_PrefLanguages` is built from the native names; catalogs use `LanguagesOnDiskNames` | (SRC) workbench/libs/locale/initlocale.c | any | Read | -| Utilities/Help opened the English guide with German set, the German guide after mapping `deutsch` to `german`; same for the six other languages | (M) 2026-11-24 | Core 12856 | ApolloOS R9.9 dev card, locale.prefs per language, reboot, Help Copy, screen captured | diff --git a/os/pitfalls/maggie-library-side-effects.md b/os/pitfalls/maggie-library-side-effects.md index 17db7d1..ad61322 100644 --- a/os/pitfalls/maggie-library-side-effects.md +++ b/os/pitfalls/maggie-library-side-effects.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [core-developer, measured, source-code] +basis: [core-developer, source-code] components: [libraries, saga-3d-maggie, cpu-68080] applies_to: core: "Core 12841+" @@ -14,7 +14,6 @@ related: - os/libraries/maggie-library.md - core/cpu-68080/prm/apollo-bit.md - core/cpu-68080/bank-prefix.md - - core/pitfalls/fpu-float-to-integer-conversion.md sources: - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 15.2" - "maggie.library source, github.com/RMortenB/MaggieLibrary, commit 64c78ef (2026-08-17)" @@ -46,8 +45,8 @@ After the first frame drawn with maggie.library: - **BANK-prefixed FPU instructions:** about 470 in the setup and raster assembler, for example `fdiv e0,e4,e0` = `$7905 $F200 $0220`, `fmove.s (a2)+,e18`, and `fmoverz.l e13,d3` (which does not exist on the - V2). They work on Core 12841 (M), but the team has decided not to support - BANK on FPU instructions in future cores (G, 2026-10-26). + V2). The team has decided not to support BANK on FPU instructions in + future cores (G, 2026-10-26). ## Wrong @@ -88,5 +87,4 @@ call. Run a draw with other tasks active. |---|---|---|---| | FPCR set to RZ and not restored; E registers clobbered; Apollo bit not set; `hasMaggie` = 1 | (SRC) | any | maggie.library source, commit 64c78ef | | The windowed sample sets the Apollo bit with `SetSR(0x800, 0x800)` | (SRC) | any | samples/Windowed | -| BANK-prefixed FPU instructions work | (M) | Core 12841 | Library running on the V4 | | No BANK prefix on FPU instructions in future cores | (G, 2026-10-26) | Future core | Statement | diff --git a/os/pitfalls/pooled-realloc-shrink-overwrites-pool.md b/os/pitfalls/pooled-realloc-shrink-overwrites-pool.md index 15b3307..dede9f0 100644 --- a/os/pitfalls/pooled-realloc-shrink-overwrites-pool.md +++ b/os/pitfalls/pooled-realloc-shrink-overwrites-pool.md @@ -4,17 +4,14 @@ type: pitfall owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [libraries] applies_to: core: "any" os: [apolloos-r10, amigaos-3.9, amigaos-3.2] tags: [memory, pools, realloc, freepooled, alert, freetype, porting] -related: - - os/pitfalls/library-globals-shared-between-tasks.md sources: - "ApolloOS-Port commit aac8859 (2026-11-18): external/freetype-2.10.0/builds/aros/src/base/ftsystem.c" - - "Hardware test on a V4 (DEV card, ApolloOS R10 ROM), 2026-11-18" --- ## Symptom @@ -25,10 +22,6 @@ Recoverable Alert `0x0100000F` "Memory header not located", with the PC in exec's pool manager (`PoolManagerAlert`). The task that shows the alert is often a helper task, and its parent then waits forever for it. -On ApolloOS R10 before the fix, System/FTManager raised this alert within -5 seconds of every start, in the task that scans `Fonts:TrueType` with -freetype2.library. - ## Cause Ported code often maps a C library's `realloc` callback onto exec memory as @@ -85,6 +78,4 @@ the same FreeType wrapper wrote to address 0 when the pool was empty. | Claim | Source | Core | Method | |---|---|---|---| -| FTManager raised alert 0x0100000F (PC in PoolManagerAlert) within 5 s of every start | (M) 2026-11-18 | Core 12856 | V4 DEV card, R10 ROM, freetype2.library 2.10.0 AROS port; started over rxnet, 2 of 2 starts | | `ft_realloc` copied `cur_size` bytes into the new block | (SRC) `builds/aros/src/base/ftsystem.c`, FreeType 2.10.0 AROS port | any | source reading | -| With the copy limited to `min(cur_size, new_size)` the alert is gone, FTManager lists the 74 TrueType fonts, quits cleanly, and the library expunges | (M) 2026-11-18 | Core 12856 | same test, ApolloOS-Port commit aac8859 | diff --git a/os/pitfalls/ramlib-reuses-library-by-name.md b/os/pitfalls/ramlib-reuses-library-by-name.md deleted file mode 100644 index 0ce2061..0000000 --- a/os/pitfalls/ramlib-reuses-library-by-name.md +++ /dev/null @@ -1,51 +0,0 @@ ---- -title: OpenLibrary by path returns the version already in memory -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [libraries] -applies_to: - core: "any" - os: [amigaos-3.9, amigaos-3.2] -tags: [ramlib, openlibrary, benchmark, testing, libraries] -related: - - core/cpu-68080/performance-counters.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 8.2" ---- - -## Symptom - -You benchmark or test two builds of a library, but both runs give the same -results: the second build is never used. - -## Cause - -AmigaOS `ramlib` matches libraries by name. Opening a second build by its -path returns the library that is already in memory with that name. - -## Wrong - -```c -base1 = OpenLibrary("work:old/mylib.library", 0); -CloseLibrary(base1); -base2 = OpenLibrary("work:new/mylib.library", 0); /* still the old one */ -``` - -## Right - -Give each variant a unique name, or flush the old one from memory between -runs. When a test name changes the code layout, keep it the same length as -the real name (the name string shifts the code). - -## Detection - -Print the library's version string or a build marker after opening it. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| A second build opened by path returned the one in memory | (M) | any | Library benchmarks on AmigaOS 3.9 | diff --git a/os/pitfalls/stack-patches-hide-small-stack-bugs.md b/os/pitfalls/stack-patches-hide-small-stack-bugs.md deleted file mode 100644 index 88ee287..0000000 --- a/os/pitfalls/stack-patches-hide-small-stack-bugs.md +++ /dev/null @@ -1,61 +0,0 @@ ---- -title: Stack patches hide small-stack code paths -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [general] -applies_to: - core: "any" - os: [amigaos-3.9, amigaos-3.2] -tags: [stack, stackattack, stackswap, testing, libraries] -related: - - toolchain/pitfalls/gcc-stackswap-defer-pop.md - - os/pitfalls/library-globals-shared-between-tasks.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 13" ---- - -## Symptom - -A library or program works on the developer's machine but crashes for some -users, typically callers with a small stack. - -## Cause - -StackAttack-style patches give every process a large stack. On machines with -such a patch, the code paths for small stacks (a `StackSwap()` to a private -stack, stack checks) never run, so their bugs stay hidden. - -## Wrong - -Testing only on a system with a stack patch installed. - -## Right - -Test the small-stack paths on a stack you allocate yourself and swap to with -`StackSwap()`, so they run whatever patches are installed: - -```c -struct StackSwapStruct sss; -UBYTE *stack = AllocVec(4096, MEMF_ANY); /* deliberately small */ -sss.stk_Lower = stack; -sss.stk_Upper = (ULONG)(stack + 4096); -sss.stk_Pointer = (APTR)(stack + 4096); -StackSwap(&sss); -run_test(); -StackSwap(&sss); -FreeVec(stack); -``` - -## Detection - -Check whether a stack patch is active on the test machine, and test library -entry points with a small caller stack. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| Small-stack code paths never run on machines with a stack patch | (M) | any | Library testing on AmigaOS 3.9 on the V4 | diff --git a/os/pitfalls/stackcall-struct-return-a0.md b/os/pitfalls/stackcall-struct-return-a0.md deleted file mode 100644 index 0ed4b4d..0000000 --- a/os/pitfalls/stackcall-struct-return-a0.md +++ /dev/null @@ -1,94 +0,0 @@ ---- -title: Struct-returning calls into ApolloOS stack-call libraries corrupt the library base -type: pitfall -owner: WDrijver -status: draft -origin: ai-assisted -basis: [measured, source-code] -components: [libraries, toolchain] -applies_to: - core: "any" - os: [apolloos-r10] -tags: [stdc, posixc, genmodule, stack-call, struct-return, a0, cexp, sincos, ldiv] -related: - - os/pitfalls/library-globals-shared-between-tasks.md -sources: - - "ApolloOS source arch/m68k-all/include/aros/genmodule.h (master @ 0645ecc524): AROS_GM_LIBFUNCSTUB, AROS_GM_RELLIBFUNCSTUB, AROS_GM_STACKCALL" - - "github.com/ApolloTeam-dev/ApolloOS.R10 issue #6" - - "ApolloOS R10 port (ApolloOS-Port), 2026-11-17: Zune clock crash, test program StructRet" ---- - -## Symptom - -A program built against ApolloOS's shared C libraries (stdc.library, -posixc.library and the other stack-call libraries made by genmodule): - -- gets garbage from `ldiv()`, `div()`, `lldiv()`, `imaxdiv()` or any - `double complex` function; -- crashes later, often a few seconds afterwards and in another function. - One example is a Software Failure (Line 1010 at PC 0x26 in supervisor - mode) at a task switch, followed by a reset that looks like a freeze. - -Code that never calls such a function by name is hit too. GCC turns -`sin(x)` and `cos(x)` of the same `x` into a single `cexp()` call. - -## Cause - -On m68k, ApolloOS's genmodule stubs load the library base into `%a0` -before they jump to the library vector: - -```text -cexp: move.l StdCBase,a0 - jmp -372(a0) -``` - -GCC passes the hidden result pointer of a struct-returning function -(`ldiv_t`, `double complex`) in `%a0` too, so the stub destroys it. The -library function then writes its result to the library base and corrupts -its first bytes, and the caller reads uninitialised stack. - -Functions that return scalars (`int`, `double`, pointers) are not -affected. - -## Wrong - -```c -/* linked with -lstdc stubs (uselibs stdc) on an affected ApolloOS */ -#include -x = cx + (WORD)(cos(a) * r); /* with sin(a) nearby GCC emits cexp() */ -y = cy - (WORD)(sin(a) * r); -``` - -## Right - -Until the stubs are fixed (ApolloOS.R10 issue #6, fixed in the R10 port -on 2026-11-17), keep struct returns away from the stubs: - -- Link the static C library for the affected functions. -- Or stop GCC from merging `sin` and `cos`: - `-fno-builtin-sin -fno-builtin-cos` stops the `cexp` transformation. - Calling them on separately computed (`volatile`) values also works. -- Do not call `div`-family or `complex.h` functions through the shared - library. - -The fix itself carries the base in `%a1` and keeps `%a0` in all three -macros. Stubs and libraries must be rebuilt together. - -## Detection - -Run `m68k-amigaos-nm` on the objects. An undefined `cexp`, `cexpf`, -`ldiv`, `div` or `lldiv` (or another struct-returning libc function) in a -program linked against the shared C library is a candidate. - -A minimal check: print `ldiv(17, 5)` through stdc.library. It must print -quotient 3 and remainder 2. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| The stub loads the base into `%a0` | (SRC) `arch/m68k-all/include/aros/genmodule.h` | any | Source and `objdump` of `stdc_cexp_stub.o`: `movea.l StdCBase,a0; jmp -372(a0)` | -| GCC passes the result pointer in `%a0` | (M) 2026-11-17 | any | `objdump` of Zune's clock.c: `lea 84(sp),a0; jsr (a3)` with a3 = `cexp` | -| GCC merges `sin` and `cos` into `cexp` | (M) 2026-11-17 | any | clock.o references `cexp`, not `sin` or `cos` (GCC 6.5, `-O2`) | -| Results are lost and the base is corrupted | (M) 2026-11-17 | Core 12856, V4 UniCorn | Test StructRet: no output and RC 16688456 with the old stubs; `3 rem 2` and `cexp(0) = 1 + 0i` with the fixed stubs | -| It crashes the machine | (M) 2026-11-17 | Core 12856, V4 UniCorn | Zune clock in Prefs/Time and Utilities/Clock: Software Failure, PC 0x26, within seconds; 90 s without failure after the fix | diff --git a/os/pitfalls/v4-rom-modules-and-reset.md b/os/pitfalls/v4-rom-modules-and-reset.md deleted file mode 100644 index 45b82f0..0000000 --- a/os/pitfalls/v4-rom-modules-and-reset.md +++ /dev/null @@ -1,62 +0,0 @@ ---- -title: V4 ROM modules, soft resets and avail flush -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [devs, general] -applies_to: - core: "any" - os: [amigaos-3.9] -tags: [loadmodule, rom, resident, reset, dma, ethernet, audio-device, avail] -related: - - os/apolloos-and-amigaos-on-v4.md - - core/saga-audio-arne/registers.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 13" ---- - -## Symptom - -- A module loaded with LoadModule is not used: the ROM version stays active. -- The machine boots into a corrupted state after a soft reset while a - network driver was running. -- Audio interrupts break after `avail flush`. - -## Cause - -| Trap | Cause | -|---|---| -| LoadModule does not replace a module | Modules with priority 105 or more cannot be replaced by LoadModule on the V4: its stub has priority 104 | -| Corruption after a soft reset | Devices whose DMA survives a soft reset (V4 Ethernet RX) keep writing into memory while the next boot runs | -| Audio broken after `avail flush` | ROM audio.device 37.10 writes −1 into all Paula interrupt vectors on expunge | - -## Wrong - -```text -LoadModule DEVS:mydriver.device ; priority 110: silently not used -Avail FLUSH ; expunges audio.device 37.10 -``` - -## Right - -- Flash modules with priority 105 or more into the ROM instead of using - LoadModule. Check the live vectors, not the resident list, to see which - version is active. -- Stop the DMA of such devices in a ColdReboot patch. -- Avoid `avail flush` on the V4. - -## Detection - -After LoadModule, compare the library or device vectors with the new -module's code. After a soft reset with networking active, check for memory -corruption early in the boot. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| LoadModule stub priority 104 | (M) | any | AmigaOS 3.9 on the V4 | -| Ethernet RX DMA survives a soft reset | (M) | any | Network driver work on the V4 | -| audio.device 37.10 writes −1 into the Paula interrupt vectors on expunge | (M) | any | AmigaOS 3.9 ROM on the V4 | diff --git a/os/pitfalls/v4net-full-size-frames-lost.md b/os/pitfalls/v4net-full-size-frames-lost.md index 817e1cb..5f2ed23 100644 --- a/os/pitfalls/v4net-full-size-frames-lost.md +++ b/os/pitfalls/v4net-full-size-frames-lost.md @@ -4,7 +4,7 @@ type: pitfall owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [devs] applies_to: core: "Core 12856" @@ -13,11 +13,8 @@ applies_to: board: [v4-unicorn] tags: [network, ethernet, v4net, mtu, mss, tcp, arostcp, amitcp-ng, bsdsocket, stall] related: - - os/pitfalls/v4-rom-modules-and-reset.md - guides/testing-on-v4-hardware.md sources: - - "Measured on a V4 UniCorn, Core 12856, v4net.device 3.0, under ApolloOS R9.6 (AROSTCP) and AmigaOS 3.9 (AmiTCP_NG 4.1.8), 2026-11-16 (ping size sweeps, tests/aetest.py of WDrijver/ApolloExplorer)" - - "Measured on a V4 UniCorn, Core 12856, v4net.device 3.0 and 3.1, under ApolloOS R9.9 (AROSTCP bsdsocket.library 4.57), 2026-11-24 and 2026-11-25" - "V4Net source (github.com/ApolloTeam-dev/V4Net): source/v4net/v4l.c (v4l_TransmitFrame), source/v4net/hwprivate.h, CHANGELOG.txt" - "ApolloTeam-dev/V4Net pull request #1 (fix: MTU 1498, v4net.device 3.1)" - "ApolloTeam-dev/ApolloSoftware: Drivers/v4net.device/3.1-beta" @@ -31,25 +28,13 @@ sources: A TCP connection from the V4 stalls as soon as the V4 sends more than about 1.4 KB in one go. Small replies keep arriving, and data sent *to* the V4 -arrives fine, so the connection looks alive but "unstable". In -ApolloExplorer, every `ash` command with output and every download hung, -while uploads worked. Seen under ApolloOS and under AmigaOS 3.9 alike. - -From any other host on the LAN: - -```sh -ping -D -s 1470 # 1498-byte IP packet: reply -ping -D -s 1472 # 1500-byte IP packet: no reply, ever -``` +arrives fine, so the connection looks alive but "unstable". ## Cause `v4net.device` 3.0 does not transmit a 1513- or 1514-byte Ethernet frame -(a 1499- or 1500-byte IP packet); 1512 bytes and smaller work (M). Receiving -full-size frames works (M). - -The reason is in the driver (SRC): since 2.97.2, `v4l_TransmitFrame` -declares the TX length rounded up to a longword, the length it actually +(a 1499- or 1500-byte IP packet). The reason is in the driver (SRC): since +2.97.2, `v4l_TransmitFrame` declares the TX length rounded up to a longword, the length it actually pushes into the TX FIFO (a fix for dropped frames on IceDrake cores 11901 and 12205, `CHANGELOG.txt`). A 1513- or 1514-byte frame is then declared as 1516 bytes, 1520 with the CRC: over the 1518-byte Ethernet limit, so the MAC @@ -57,9 +42,7 @@ never sends it. The driver still reported an MTU of 1500, so the TCP/IP stack built 1500-byte packets: TCP used an MSS of 1460, and every full-size segment was -lost and retransmitted at the same size forever. The same happens under -ApolloOS (AROSTCP) and AmigaOS 3.9 (AmiTCP_NG), so it is the driver, not the -OS or the stack. +lost and retransmitted at the same size forever. **Fixed in `v4net.device` 3.1** (24.11.2026, in ApolloSoftware as `Drivers/v4net.device/3.1-beta`): the driver reports an MTU of 1498 to every @@ -67,7 +50,7 @@ stack (`S2_DEVICEQUERY`, and the netdev personality) and clamps `MTU=` in its config to 1498 (SRC: `HW_MAX_MTU` in `source/v4net/hwprivate.h`). Not yet known: which releases before 2.97.2 are unaffected, and how 3.1 -behaves under AmigaOS 3.9 and 3.2 (tested under ApolloOS R9.9 only). +behaves under AmigaOS 3.9 and 3.2. ## Wrong @@ -81,18 +64,13 @@ send( client, reply, replyLength, 0 ); ## Right **Use `v4net.device` 3.1 or later.** Then nothing is needed in the stack -configuration or in the program: the code above works (M). Check with +configuration or in the program. Check with `Version DEVS:Networks/v4net.device`. **With an older `v4net.device`**, keep packets at 1498 bytes or below. In order of preference: -1. **In the driver config, for every stack:** `MTU=1498` in - `ENVARC:SANA2/v4net.config` (copy it to `ENV:SANA2/` or reboot). The - driver then reports 1498 to the stack (M, v4net.device 3.0 on ApolloOS - R9.9). - -2. **In the stack's interface file (AmiTCP_NG):** AmiTCP_NG reads `mtu=` from +1. **In the stack's interface file (AmiTCP_NG):** AmiTCP_NG reads `mtu=` from `DEVS:NetInterfaces/V4net` (SRC: `src/net/ng_ifconfig.c`; it is clamped to the device MTU). Add the line and restart the network (power-cycle the V4): @@ -101,12 +79,10 @@ order of preference: mtu=1492 ``` - The stack then sends at most 1492-byte packets and uses an MSS of 1452 - (M). The interface file in ApolloSoftware's v4net.device 3.0-beta and - 3.1-beta already has this line. AROSTCP on ApolloOS did not apply it (M, - R9.9). + The interface file in ApolloSoftware's v4net.device 3.0-beta and + 3.1-beta already has this line. -3. **In one program: `TCP_MAXSEG` on the connected socket.** AROSTCP +2. **In one program: `TCP_MAXSEG` on the connected socket.** AROSTCP (ApolloOS) only lets `TCP_MAXSEG` lower the MSS a connection has negotiated (SRC: `tcp_usrreq.c` accepts a value only when it is `<= tp->t_maxseg`). On a listen socket `t_maxseg` is still the 512-byte @@ -133,11 +109,6 @@ order of preference: ## Detection -- `ping -D -s 1472 ` from another host gets no reply, while - `ping -D -s 1470` does. This fails with every driver, also 3.1: the - 1500-byte reply must be fragmented and `-D` forbids that. The useful test - is `ping -s 3000 ` (fragmented): a reply with 3.1 or with an MTU - workaround, none with 3.0 and no workaround (M). - Check the driver version: `Version DEVS:Networks/v4net.device`. - A TCP service on the V4 whose small replies work but whose large ones never arrive (the client receives not even the first byte). @@ -146,17 +117,6 @@ order of preference: | Claim | Source | Core | Method | |---|---|---|---| -| A 1500-byte IP packet from the V4 never arrives; 1498 bytes does | (M) | Core 12856 | `ping -D -s` binary search from a Mac on the same gigabit LAN, v4net.device 3.0, ApolloOS R9.6 and AmigaOS 3.9 | -| Every payload size 0 to 1470 bytes gets a reply | (M) | Core 12856 | One ping per size, spaced out, ApolloOS R9.6 | -| The V4 receives 1500-byte packets | (M) | Core 12856 | TCP upload with 1460-byte segments, 200 KB in 0.33 to 0.36 s, both OSes | -| Other hosts on the same LAN send 1500-byte packets fine | (M) | n/a | `ping -D -s 1472` to three other hosts | -| TCP replies up to 1435 bytes arrive, 1497 bytes never | (M) | Core 12856 | Directory listing grown one entry at a time, both OSes | | Since 2.97.2 the declared TX length is rounded up to a longword: 1513/1514 bytes become 1516, 1520 with CRC | (SRC) | any | V4Net `v4l_TransmitFrame`, `CHANGELOG.txt` 2.97.2 | -| `MTU=1498` in v4net.config fixes it with v4net.device 3.0 | (M) | Core 12856 | ApolloOS R9.9, ApolloExplorerSrv 1.4.2 (no workaround): fragmented pings to 8000 bytes, TCP replies to 3771 bytes, `tests/aetest.py` smoke, shell, transfer, concurrent pass | -| v4net.device 3.1 fixes it without any config | (M) | Core 12856 | ApolloOS R9.9, no v4net.config: same tests with ApolloExplorerSrv 1.4.2 pass; with 1.4.4 also 4 × 200 short sessions, 20 transfers up to 10 MB (3.6 MB/s up, 1.4 MB/s down) and 6 parallel clients, 0 failures | -| `TCP_MAXSEG` 1400 on the accepted socket makes large replies arrive under AROSTCP | (M) | Core 12856 | ApolloExplorer 1.4.4 on ApolloOS R9.6: shell output, 1 MB transfers and parallel sessions pass | -| `TCP_MAXSEG` has no effect under AmiTCP_NG 4.1.8 | (M) | Core 12856 | ApolloExplorer 1.4.4 on AmigaOS 3.9: replies over 1435 bytes still lost | -| `mtu=1492` in `DEVS:NetInterfaces/V4net` fixes it under AmiTCP_NG | (M) | Core 12856 | AmigaOS 3.9: replies up to 3771 bytes arrive; all ApolloExplorer tests pass; 4 MB downloads at 4.2 MB/s | -| `mtu=1492` in `DEVS:NetInterfaces/V4Net` has no effect under AROSTCP | (M) | Core 12856 | ApolloOS R9.9 with v4net.device 3.0: large replies still lost with the line present | | `TCP_MAXSEG` can only lower `t_maxseg`; `tcp_output()` caps segments at it | (SRC) | any | AROSTCP `tcp_usrreq.c`, `tcp_output.c` | | AmiTCP_NG rejects `TCP_MAXSEG` with `EINVAL`; reads `mtu=` per interface | (SRC) | any | AmiTCP_NG `src/netinet/tcp_usrreq.c`, `src/net/ng_ifconfig.c` | diff --git a/skills/apollo-build/SKILL.md b/skills/apollo-build/SKILL.md index 5e6403c..4a9c62b 100644 --- a/skills/apollo-build/SKILL.md +++ b/skills/apollo-build/SKILL.md @@ -81,9 +81,6 @@ code around a symptom, check whether it is a known trap: |---|---| | Internal compiler error, or wrong code that looks like a compiler bug | First an `UPDATE=compiler` from step 2: the fix may only need a reinstall. Then `toolchain/compiler-variants.md` (bug table: fixed only in a reinstalled GCC-6.50-Dev) and the pitfall it names | | Floats wrong, or link errors about float functions | `toolchain/pitfalls/float-settings-mismatch.md` | -| `sprintf`, headers or libnix surprises | `toolchain/pitfalls/libnix-and-header-traps.md` | -| Other GCC oddities | `toolchain/pitfalls/gcc-misc-traps.md` | -| C calling assembler, registers lost | `toolchain/pitfalls/calling-assembler-from-gcc.md` | | vasm rejects or mis-encodes a 68080 instruction | `toolchain/pitfalls/vasm-68080-encoding-issues.md`, `toolchain/pitfalls/vasm-pc-relative-destination.md` | | A function missing on one target OS | `toolchain/target-os-headers.md` (build against the oldest target's NDK) | | ApolloLib misbehaves | `toolchain/pitfalls/apollolib-known-bugs.md` | diff --git a/skills/apollo-new-project/assets/main-os-friendly.c b/skills/apollo-new-project/assets/main-os-friendly.c index 8bb3b89..f0f222d 100644 --- a/skills/apollo-new-project/assets/main-os-friendly.c +++ b/skills/apollo-new-project/assets/main-os-friendly.c @@ -12,7 +12,7 @@ extern struct ExecBase *SysBase; -/* ApolloKnowledgeBase os/best-practices/detect-68080-and-fpu-at-run-time.md */ +/* ApolloKnowledgeBase os/apolloos-and-amigaos-on-v4.md */ static int has_68080(void) { return (SysBase->AttnFlags & (1 << 10)) != 0; } static int has_fpu(void) { return (SysBase->AttnFlags & AFF_68881) != 0; } diff --git a/skills/apollo-new-project/assets/main-os-takeover.c b/skills/apollo-new-project/assets/main-os-takeover.c index 95c9fd7..cefa688 100644 --- a/skills/apollo-new-project/assets/main-os-takeover.c +++ b/skills/apollo-new-project/assets/main-os-takeover.c @@ -13,7 +13,7 @@ extern struct ExecBase *SysBase; -/* ApolloKnowledgeBase os/best-practices/detect-68080-and-fpu-at-run-time.md */ +/* ApolloKnowledgeBase os/apolloos-and-amigaos-on-v4.md */ static int has_68080(void) { return (SysBase->AttnFlags & (1 << 10)) != 0; } int main(void) diff --git a/toolchain/apollolib/debug.md b/toolchain/apollolib/debug.md index 0ae41e8..9014394 100644 --- a/toolchain/apollolib/debug.md +++ b/toolchain/apollolib/debug.md @@ -4,7 +4,7 @@ type: reference owner: WDrijver status: reviewed origin: ai-assisted -basis: [source-code, measured] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -16,7 +16,6 @@ related: - guides/testing-on-v4-hardware.md sources: - "ApolloLib, github.com/WDrijver/ApolloCrossDev Projects/ApolloLib (ApolloCrossDev_Debug.h, _Debug.c, _Defines.h), commit 639e195 (2026-11-04)" - - "guides/testing-on-v4-hardware.md (serial output on a V4 UniCorn, 2026-11-09)" --- ## Summary @@ -52,10 +51,7 @@ The output goes through the Paula UART, without OS calls (SRC): | `SERDAT` | `$DFF030` | Write the character, with its stop bit | On the other side, set the terminal to 115200 8N1 without flow control, for -example with a USB-to-serial cable on the V4's serial port. Writing to -`SER:` (for example `Echo >SER:`) goes through serial.device and did not -reach the cable at any baud rate between 9600 and 115200 (M). Use the -direct UART writes above for debug output. +example with a USB-to-serial cable on the V4's serial port. ### Macros, set 1: AD and ADX (ApolloCrossDev_Defines.h) diff --git a/toolchain/apollolib/memory-and-blit.md b/toolchain/apollolib/memory-and-blit.md index 979778e..546be3d 100644 --- a/toolchain/apollolib/memory-and-blit.md +++ b/toolchain/apollolib/memory-and-blit.md @@ -12,8 +12,6 @@ applies_to: tags: [apollolib, memcpy, fill, endian, blit, alpha, ammx, move16] related: - toolchain/apollolib/index.md - - core/cpu-68080/measured-instruction-costs.md - - core/best-practices/align-copy-destination.md - toolchain/pitfalls/apollolib-known-bugs.md sources: - "ApolloLib, github.com/WDrijver/ApolloCrossDev Projects/ApolloLib (ApolloCrossDev_LibASM.s, _Lib.h), commit 639e195 (2026-11-04)" @@ -41,10 +39,6 @@ All take their arguments in registers; the prototypes in | `ApolloFillLongs(d, value, size)` | a1, d4, d3 = bytes | 4 bytes | **Ignored** | | `ApolloFillBlock(d, count, value)` | a0, d3 = bytes, d4 | 32 bytes (4 × AMMX `store`), 32-byte aligned | **Ignored** | -`move16` needs no alignment on the 68080, but is never faster than -aligned AMMX or quad moves (see -[measured-instruction-costs.md](../../core/cpu-68080/measured-instruction-costs.md)). - ### Endian swap | Routine | What it does | @@ -83,7 +77,5 @@ The blit routines work on R5G6B5 pixels (16-bit modes). - DO give sizes in multiples of 32 (`ApolloCopyBlock32`, `ApolloFillBlock`) or 4 (`ApolloCopyLongs`, `ApolloFillLongs`). -- DO align the destination of large copies (see - [align-copy-destination.md](../../core/best-practices/align-copy-destination.md)). - DON'T use `ApolloEndianSwapLongBuffer` from an ApolloLib older than 639e195: it swapped words, not bytes. diff --git a/toolchain/best-practices/gcc-code-generation-for-68080.md b/toolchain/best-practices/gcc-code-generation-for-68080.md index fa0ac49..53296bd 100644 --- a/toolchain/best-practices/gcc-code-generation-for-68080.md +++ b/toolchain/best-practices/gcc-code-generation-for-68080.md @@ -4,7 +4,7 @@ type: best-practice owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain, cpu-68080] applies_to: core: "Core 12841" @@ -13,8 +13,6 @@ tags: [gcc, m68080, code-generation, portable, assembler, fpu] related: - toolchain/c-compiler-options.md - toolchain/pitfalls/float-settings-mismatch.md - - toolchain/pitfalls/gcc-misc-traps.md - - core/best-practices/fixed-point-and-bitstreams.md sources: - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 9.1 and 15.1" --- @@ -33,9 +31,6 @@ pays off. - **FPU**: `-m68080` alone gives soft-float; add `-m68881` for FPU code (see [float-settings-mismatch.md](../pitfalls/float-settings-mismatch.md)). For full control, write FPU kernels in assembler. -- **Multiply-heavy loops**: GCC spills every 64-bit product. Plain 68020 - assembler with the 64-bit sum in a register pair (add/addx) and unrolled - blocks with a computed entry beats it clearly. - **Float-heavy C with `-std=c11`**: add `-fexcess-precision=fast`. `-std=c11` alone forces `-fexcess-precision=standard`, which rounds every float temporary through a Dn; in maggie.library that caused about 1320 @@ -69,16 +64,10 @@ long sum(const long *p, long n) ## Evidence -| Variant | Measurement | Core | Test setup | -|---|---|---|---| -| MP3 decoder, 68020 build vs 080 build, on the 080 | 080 build 0–8 % faster | Core 12841 | Full decode (M) | -| `-m68080` vs `-m68020` code generation alone | About 2 % on an MP3 decoder | Core 12841 | Same | -| `-O3` vs `-O2` | No gain | Core 12841 | Same | -| Hand-written 68020 multiply loops vs GCC | Clearly faster | Core 12841 | MP3/FLAC kernels | +No speed measurements are recorded. The code generation claims for +`-m68020` are checked by the `kb:compile` block above in CI. ## When not to use -- Don't expect much from `-m68080` itself: about 2 % on its own. The large - gains came from hand-written or generated assembler kernels. - A `-m68080` binary does not run on other CPUs or emulators: keep a 68020 build if the program must run elsewhere. diff --git a/toolchain/c-compiler-options.md b/toolchain/c-compiler-options.md index c4935dc..113a3ba 100644 --- a/toolchain/c-compiler-options.md +++ b/toolchain/c-compiler-options.md @@ -38,11 +38,10 @@ runtime (`-noixemul`). Link with `m68k-amigaos-gcc` and the same flags. | `-fomit-frame-pointer` | Frees the frame pointer register for general use | Other optimization levels: `-O` (basic), `-O3` (aggressive), `-Os` (small -size). `-O3` gave no gain over `-O2` in measured projects. +size). -Don't add `-mtune=68060`: it stops GCC from using the 64-bit `muls.l` (FLAC -3x slower). See [gcc-misc-traps.md](pitfalls/gcc-misc-traps.md) and, for -more on code generation, [gcc-code-generation-for-68080.md](best-practices/gcc-code-generation-for-68080.md). +For more on code generation, see +[gcc-code-generation-for-68080.md](best-practices/gcc-code-generation-for-68080.md). ### C runtime @@ -83,10 +82,6 @@ generated code is the same. | MUI | `-lmui` | | Math | `-lm` | -libnix's `libm` also holds the soft-float routines (`__mulsf3`, -`__addsf3` and so on): a program built without `-m68881` on purpose does -not link without `-lm` (M). - GCC picks the libraries by CPU and FPU options (multilib). `-m68080`, with or without `-m68881`, links the base libraries (multilib folder `.`), not the `libm020` or `libm020/libm881` builds (SRC: `m68k-amigaos-gcc @@ -122,5 +117,3 @@ m68k-amigaos-gcc main.o -noixemul -O2 -m68080 -m68881 -ffast-math -fomit-frame-p - DON'T mix libnix and clib2 objects in one program. - DON'T mix objects built with and without `-m68881`, and link with the same flags you compile with. -- DO link with `-lm` when you use `sprintf` with libnix (see - [libnix-and-header-traps.md](pitfalls/libnix-and-header-traps.md)). diff --git a/toolchain/compiler-variants.md b/toolchain/compiler-variants.md index 5370a24..a75365d 100644 --- a/toolchain/compiler-variants.md +++ b/toolchain/compiler-variants.md @@ -89,7 +89,6 @@ It applies none by TuKo1982 and none of the bbb fixes. | ICE on `sinf`/`cosf` with `-ffast-math` | [gcc-fsincos-ice.md](pitfalls/gcc-fsincos-ice.md) | Fixed | Not fixed | Not fixed | | 16-bit loop counter in an address register runs away | [gcc-dbra-address-register-loop.md](pitfalls/gcc-dbra-address-register-loop.md) | Fixed | Not fixed | Not fixed | | `btst` tests the wrong byte of a bit field in memory | [gcc-btst-memory-bit-number.md](pitfalls/gcc-btst-memory-bit-number.md) | Fixed | Fixed | Not fixed | -| Memory indirect operand on the wrong stack slot after a call | [gcc-double-indirect-stack-slot.md](pitfalls/gcc-double-indirect-stack-slot.md) | Fixed | Fixed | Not fixed | | bbb pass fixes up a post-increment it just made; pointer stride too small | [gcc-bbb-autoinc-converted-insn.md](pitfalls/gcc-bbb-autoinc-converted-insn.md) | Fixed | Not fixed | Not fixed | | bbb pass keeps a stale memory value after a store; wrong 64-bit results | [gcc-bbb-stale-memory-value.md](pitfalls/gcc-bbb-stale-memory-value.md) | Fixed | Not fixed | Not fixed | | ICE "insn does not satisfy its constraints" after an auto-increment | [gcc-bbb-autoinc-fixup-ice.md](pitfalls/gcc-bbb-autoinc-fixup-ice.md) | Fixed | Not fixed | Not fixed | diff --git a/toolchain/pitfalls/calling-assembler-from-gcc.md b/toolchain/pitfalls/calling-assembler-from-gcc.md deleted file mode 100644 index b471a7a..0000000 --- a/toolchain/pitfalls/calling-assembler-from-gcc.md +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: Calling assembler from GCC (registers, movem order, FPU ABI) -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [toolchain, cpu-68080] -applies_to: - core: "any" - os: [any] -tags: [gcc, assembler, abi, registers, movem, fpu] -related: - - toolchain/vasm-assembler.md - - toolchain/c-compiler-options.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 9.3" ---- - -## Symptom - -The machine hangs or C code misbehaves after calling an assembler routine. -It looks like a hardware bug: a clobbered a2 hung the machine three times -before it was found. - -## Cause - -- GCC expects d2–d7 and a2–a6 to be preserved by the callee. -- `movem.l` loads registers in register-mask order, not in the order you list - them. Loading arguments from the stack with one `movem.l` can put them in - the wrong registers. -- Which FPU registers a routine must preserve depends on the ABI you use, and - is easy to get wrong when it is not written down. - -## Wrong - -```asm -_routine: - movem.l 4(sp),a2/d1 ; loads d1 first, then a2: not "a2 then d1" - move.l (a2)+,d0 ; a2 clobbered and not restored - rts -``` - -## Right - -```asm -_routine: - move.l a2,-(sp) ; save a callee-saved register - movea.l 8(sp),a2 ; load arguments with separate moves - move.l 12(sp),d1 - move.l (a2)+,d0 - movea.l (sp)+,a2 - rts -``` - -- Document the FPU registers your routine keeps, for example "keeps - FP2–FP7/FPCR". - -## Detection - -Review every assembler routine called from C for writes to d2–d7/a2–a6 -without a save and restore, and for `movem.l` used to load arguments. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| A clobbered a2 hung the machine three times | (M) | any | Project debugging on the V4 | -| `movem.l` loads in register-mask order | (M) | any | Same | diff --git a/toolchain/pitfalls/float-settings-mismatch.md b/toolchain/pitfalls/float-settings-mismatch.md index be816b9..10857ac 100644 --- a/toolchain/pitfalls/float-settings-mismatch.md +++ b/toolchain/pitfalls/float-settings-mismatch.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -29,10 +29,9 @@ sources: ## Cause - For the AmigaOS target, `-m68080` alone does **not** turn on the FPU: no - 680x0 CPU option does (SRC). Hardware floating point comes from `-m68881` - (M: on Core 12556 a float loop built with `-m68080 -m68881` ran 7.9 - times faster than with `-m68080` alone). `-m68080` - alone compiles float work into calls such as `__floatsisf` (M). + 680x0 CPU option does (SRC). Hardware floating point comes from `-m68881`. + `-m68080` alone compiles float work into soft-float calls such as + `__mulsf3` (CI check below). - Objects built with different float settings, linked together (for example `-m68080` objects with a libnix `printf` built for the other setting), pass doubles in a way the other side does not expect. @@ -52,8 +51,6 @@ m68k-amigaos-gcc lib.o app.o -noixemul -o app # mixed - Compile **and** link everything with the same flags, including `-m68881`: the standard set is in [c-compiler-options.md](../c-compiler-options.md). -- A program built for soft-float on purpose links with `-lm`: libnix keeps - `__mulsf3` and the other soft-float routines in its `libm` (M). - Keep library code (`-nostartfiles`) integer (fixed point), and check its objects for soft-float symbols. - Write FPU kernels in assembler when you need full control over the FPU @@ -90,8 +87,5 @@ float scale(float a, float b) { return a * b; } | Claim | Source | Core | Method | |---|---|---|---| -| `-m68080` emits no FPU instructions | (M) | any | Project builds | +| `-m68080` alone emits soft-float calls; with `-m68881` it emits `fsmul.s` | CI `kb:compile` check | any | GCC `-S` output, blocks above | | No 680x0 CPU option sets the FPU flag for AmigaOS; `-m68881` sets hard float explicitly | (SRC) | any | GCC source, `m68k.c` | -| `-m68080` objects with libnix `printf` printed garbage doubles | (M) | any | MP3 project | -| Soft-float in a `-nostartfiles` library crashed with a CHK error | (M) | any | MP3 library, ReplayGain path | -| `-m68080 -m68881` runs FPU code on a V4: 8 cycles per element of a float dot product, 63 with `-m68080` alone | (M) | Core 12556 | `tools/v4/tests/fpu-m68881`, V4 UniCorn, 3 alternating rounds, 2026-11-09 | diff --git a/toolchain/pitfalls/gcc-bbb-autoinc-converted-insn.md b/toolchain/pitfalls/gcc-bbb-autoinc-converted-insn.md index 33e48ce..13edfac 100644 --- a/toolchain/pitfalls/gcc-bbb-autoinc-converted-insn.md +++ b/toolchain/pitfalls/gcc-bbb-autoinc-converted-insn.md @@ -4,7 +4,7 @@ type: pitfall owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -15,7 +15,6 @@ related: - toolchain/pitfalls/gcc-bbb-autoinc.md sources: - "github.com/WDrijver/ApolloCrossDev pull request #29 by delwall (bbb-autoinc-converted-insn-fix.patch, merged 2026-11-24)" - - "Reproduction with GCC-6.50-Dev 6.5.0b, installed 2026-11-25 (this file, Evidence)" --- ## Symptom @@ -76,17 +75,7 @@ With `-m68080 -m68881 -ffast-math -fomit-frame-pointer -Ofast ## Right -Use GCC-6.50-Dev installed on or after 2026-11-24. The same loop then -compiles to: - -```text - fsmove.s (a0)+,fp0 - fsmove.s (a0)+,fp3 - fsmove.s (a0)+,fp2 - fsmove.s (-12,a0),fp0 - fsmove.s (-8,a0),fp3 - fsmove.s (-4,a0),fp2 -``` +Use GCC-6.50-Dev installed on or after 2026-11-24. With an older install, GCC-6.50-Stable or GCC-6.50-Base, compile the affected file with `-fbbb=-`, or reinstall GCC-6.50-Dev. @@ -103,5 +92,4 @@ bytes the pointer advances per iteration must be the record size. | Claim | Source | Core | Method | |---|---|---|---| | Two groups of loads on one record, converted in one pass, give wrong offsets and too small a stride; `-fbbb=-` is correct | (SRC) ApolloCrossDev PR #29 | any (compiler output) | Patch description with the reproducer and the wrong `-S` output | -| With the fix, the reproducer gives three post-increments, then `(-12,a0)`, `(-8,a0)`, `(-4,a0)` | (M) 2026-11-25 | any (compiler output) | GCC-6.50-Dev 6.5.0b installed 2026-11-25 08:34, flags above, `-S` | | Only GCC-6.50-Dev applies the patch | (SRC) | any | `GCC-6.50-Dev-*.sh` and `GCC-6.50-Stable-*.sh`, ApolloCrossDev `c1fba26a4` | diff --git a/toolchain/pitfalls/gcc-bbb-autoinc-fixup-ice.md b/toolchain/pitfalls/gcc-bbb-autoinc-fixup-ice.md index be36100..d66d825 100644 --- a/toolchain/pitfalls/gcc-bbb-autoinc-fixup-ice.md +++ b/toolchain/pitfalls/gcc-bbb-autoinc-fixup-ice.md @@ -4,7 +4,7 @@ type: pitfall owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -16,7 +16,6 @@ related: sources: - "github.com/WDrijver/ApolloCrossDev issue #33 and pull request #34 (bbb-autoinc-fixup-constraints-fix.patch, merged 2026-11-24)" - "ApolloTeam-dev/V4Net, source/v4net/netdev.c, drv_dma_alloc (where it was found)" - - "Reproduction with GCC-6.50-Dev 6.5.0b, installed 2026-11-25 (this file, Evidence)" --- ## Symptom @@ -96,7 +95,5 @@ If `-fbbb=-` makes it go away, it is this bug or another bbb bug. | Claim | Source | Core | Method | |---|---|---|---| -| ICE with default flags and with `-fbbb=i`; `-fbbb=-` compiles | (M) 2026-11-24 | any (compiler output) | ApolloCrossDev issue #33, GCC-6.50-Dev built 2026-11-24 15:15 UTC, `-noixemul -O2 -m68020 -fomit-frame-pointer -msoft-float` | -| With the fix the reproducer compiles with `-m68020` and with `-m68080` | (M) 2026-11-25 | any (compiler output) | GCC-6.50-Dev 6.5.0b installed 2026-11-25 08:34, same flags, NDK 3.2 headers | | Cause: the re-emitted insn is recognized as `*addsi3_internal` without a constraint check | (SRC) | any | `bbb-autoinc-fixup-constraints-fix.patch`, `bbb-opts.c` | | Only GCC-6.50-Dev applies the patch | (SRC) | any | `GCC-6.50-Dev-*.sh` and `GCC-6.50-Stable-*.sh`, ApolloCrossDev `c1fba26a4` | diff --git a/toolchain/pitfalls/gcc-bbb-autoinc.md b/toolchain/pitfalls/gcc-bbb-autoinc.md index ba45583..723f9e3 100644 --- a/toolchain/pitfalls/gcc-bbb-autoinc.md +++ b/toolchain/pitfalls/gcc-bbb-autoinc.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -69,5 +69,4 @@ Scc. | Claim | Source | Core | Method | |---|---|---|---| -| Miscompile as described | (M) | any | Real project code, `-S` output | | Fix in ApolloCrossDev PR #5, applied by the Dev scripts only | (SRC) | any | Pull request, install scripts | diff --git a/toolchain/pitfalls/gcc-bbb-propagate-moves-ice.md b/toolchain/pitfalls/gcc-bbb-propagate-moves-ice.md index b477776..3dca9dc 100644 --- a/toolchain/pitfalls/gcc-bbb-propagate-moves-ice.md +++ b/toolchain/pitfalls/gcc-bbb-propagate-moves-ice.md @@ -4,7 +4,7 @@ type: pitfall owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -16,7 +16,6 @@ related: sources: - "github.com/WDrijver/ApolloCrossDev pull request #35 (bbb-propagate-moves-bb-boundary-fix.patch, merged 2026-11-25)" - "Lua 5.4.6 lobject.c, luaO_str2num (where it was found)" - - "Reproduction with GCC-6.50-Dev 6.5.0b, installed 2026-11-25 (this file, Evidence)" --- ## Symptom @@ -125,5 +124,4 @@ bbb bug. | Claim | Source | Core | Method | |---|---|---|---| | ICE at `-O3 -m68080` and `-Ofast -m68080 -m68881`; `-fbbb=-` and `-fbbb` without `p` compile it | (SRC) ApolloCrossDev PR #35 | any (compiler output) | Patch description, Lua 5.4.6 `lobject.c` and the reduced case | -| With the fix the reduced case compiles at `-O3 -m68080` and `-Ofast -m68080 -m68881` | (M) 2026-11-25 | any (compiler output) | GCC-6.50-Dev 6.5.0b installed 2026-11-25 08:34, `-noixemul -S` | | Only GCC-6.50-Dev applies the patch | (SRC) | any | `GCC-6.50-Dev-*.sh` and `GCC-6.50-Stable-*.sh`, ApolloCrossDev `c1fba26a4` | diff --git a/toolchain/pitfalls/gcc-bbb-propagate-moves-loop-exit.md b/toolchain/pitfalls/gcc-bbb-propagate-moves-loop-exit.md index 6264a33..50a5125 100644 --- a/toolchain/pitfalls/gcc-bbb-propagate-moves-loop-exit.md +++ b/toolchain/pitfalls/gcc-bbb-propagate-moves-loop-exit.md @@ -4,7 +4,7 @@ type: pitfall owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -15,7 +15,6 @@ related: - toolchain/pitfalls/gcc-bbb-propagate-moves-ice.md sources: - "github.com/WDrijver/ApolloCrossDev issue #36 and pull request #37 (bbb-propagate-moves-addr-exit-fix.patch, merged 2026-11-25)" - - "Reproduction with GCC-6.50-Dev 6.5.0b, installed 2026-11-25 before pull request #37 (this file, Evidence)" --- ## Symptom @@ -68,27 +67,6 @@ out: } ``` -At `-O2 -m68020`, before the fix, the loop advances `a0`, but the early exit -computes `p - s` from `a1`, which still holds `s`: - -```text - move.l d5,a1 ; a1 = s - ... - move.l a1,a0 -.L4: - clr.l d1 - move.b (a0)+,d1 ; p advances in a0 only - move.b d1,d4 - and.b d3,d4 - jne .L9 ; early exit - ... -.L9: - sub.l d5,a1 ; p - s from a1 = s: always 0 -``` - -Every early exit after the first iteration returns `acc` instead of -`3 * (p - s) + acc`. - ## Right Use GCC-6.50-Dev installed on or after 2026-11-25, after pull request #37 @@ -100,14 +78,12 @@ affected file with `-fbbb=-`, or reinstall GCC-6.50-Dev. In `-S` output, look for a loop that post-increments one address register and has an exit label that reads another address register which the loop -never writes. Compare with `-fbbb=-`, where the loop copies the pointer -back (`move.l a0,a1`) inside the loop. +never writes. ## Evidence | Claim | Source | Core | Method | |---|---|---|---| -| The early exit at `.L9` computes `p - s` from `a1`, which still holds `s`; `-fbbb=-` copies `a0` to `a1` inside the loop | (M) 2026-11-25 | any (compiler output) | GCC-6.50-Dev 6.5.0b installed 2026-11-25 08:34 (before PR #37), `-O2 -m68020 -S`, with and without `-fbbb=-` | | Cause: increment size taken from a `strict_low_part` (VOIDmode) destination; no copy emitted for two address registers with offset 0 | (SRC) | any | `bbb-propagate-moves-addr-exit-fix.patch`, ApolloCrossDev issue #36 | | With the fix, `.L9` uses `a0 - 1`, the same as `-fbbb=-` | (SRC) ApolloCrossDev PR #37 | any (compiler output) | Patch description | | Only GCC-6.50-Dev applies the patch | (SRC) | any | `GCC-6.50-Dev-*.sh` and `GCC-6.50-Stable-*.sh`, ApolloCrossDev `c1fba26a4` | diff --git a/toolchain/pitfalls/gcc-bbb-shift-wrong-code.md b/toolchain/pitfalls/gcc-bbb-shift-wrong-code.md index 3b2ec3a..3f6df08 100644 --- a/toolchain/pitfalls/gcc-bbb-shift-wrong-code.md +++ b/toolchain/pitfalls/gcc-bbb-shift-wrong-code.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -20,12 +20,10 @@ sources: ## Symptom -Wrong results, without any warning, at `-O2` and `-Os`, for 68000 to 68080: - -- An addition or index that uses a shift count gives a result that depends - on what was left in the register. A typical victim is a `BYTE` or `WORD` - loop counter used both as a shift count and as an array index. -- A table-driven CRC loses its high byte (seen with `-O2 -m68080`). +Wrong results, without any warning, at `-O2` and `-Os`, for 68000 to 68080. +An addition or index that uses a shift count gives a result that depends +on what was left in the register. A typical victim is a `BYTE` or `WORD` +loop counter used both as a shift count and as an array index. ## Cause @@ -70,9 +68,7 @@ Compile with `-S` and look for a register that is loaded with `move.w`, used as a shift count and then used as a 32-bit value with no `ext.l` in between. Compare the results with the same code built with `-fbbb=-`. -CI checks that GCC-6.50-Dev keeps the `ext.l` in the example above. A Dev -install built before the fix (2026-10-08) still drops it, while `-fbbb=-` -keeps it: +CI checks that GCC-6.50-Dev keeps the `ext.l` in the example above: ```c // kb:compile @@ -88,6 +84,4 @@ int f(const short *p, int x) | Claim | Source | Core | Method | |---|---|---|---| -| Shift-count case: up to 20000 wrong results per function before the fix, 0 after | (M) | any | 20000 calls with garbage in the scratch registers, `-O2`/`-Os` 68020 and `-O2` 68080, on a V4 | -| CRC case: 99612 of 100000 calls wrong before the fix, 0 after | (M) | any | `-O2 -m68080` and `-O2 -m68020 -mtune=68080`, on a V4 | | `-fbbb=-` or leaving out the pass letter hides each bug | (SRC) | any | ApolloCrossDev PR #10 | diff --git a/toolchain/pitfalls/gcc-bbb-stale-memory-value.md b/toolchain/pitfalls/gcc-bbb-stale-memory-value.md index 340ef9c..daa8c62 100644 --- a/toolchain/pitfalls/gcc-bbb-stale-memory-value.md +++ b/toolchain/pitfalls/gcc-bbb-stale-memory-value.md @@ -4,7 +4,7 @@ type: pitfall owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -83,6 +83,4 @@ that slot before the store, with no reload in between. Compare with | Claim | Source | Core | Method | |---|---|---|---| | A `DImode` store over an `SImode` spill slot kept the stale value; `opt_elim_dead_assign` deleted the reload; wrong 64-bit products | (SRC) ApolloCrossDev PR #30 | any (compiler output) | Pull request description with the `-S` excerpt above | -| With the fix the reduced case matches the host | (M) delwall, PR #30 | V4 (core not stated) | Run on a Vampire V4 against host results | -| 703 of 720 compilations (373 C files at `-m68080 -O2/-O3/-Os`) unchanged; the rest only keep loads the old pass had replaced | (M) delwall, PR #30 | any (compiler output) | Comparison of compiler output before and after the patch | | Only GCC-6.50-Dev applies the patch | (SRC) | any | `GCC-6.50-Dev-*.sh` and `GCC-6.50-Stable-*.sh`, ApolloCrossDev `c1fba26a4` | diff --git a/toolchain/pitfalls/gcc-btst-memory-bit-number.md b/toolchain/pitfalls/gcc-btst-memory-bit-number.md index 47034e9..31e99c7 100644 --- a/toolchain/pitfalls/gcc-btst-memory-bit-number.md +++ b/toolchain/pitfalls/gcc-btst-memory-bit-number.md @@ -4,7 +4,7 @@ type: pitfall owner: WDrijver status: draft origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -17,7 +17,7 @@ related: sources: - "github.com/WDrijver/ApolloCrossDev pull request #26 (m68k-btst-mem-offset-fix.patch)" - "github.com/WDrijver/gcc gcc-stable, gcc/config/m68k/m68k.md: *tst_bftst_mem, *tst_bftst_mem1, *tst_bftst_mem2" - - "ApolloOS R10 port (ApolloOS-Port), 2026-11-16: Regina REXX, exec stdAllocReverse, reqtools" + - "ApolloOS R10 port (ApolloOS-Port), 2026-11-16: exec stdAllocReverse, reqtools" --- ## Symptom @@ -37,8 +37,7 @@ memory operand: ``` Seen in ApolloOS R10: exec's `stdAllocReverse` never cleared -`MEMF_REVERSE|MEMF_CLEAR` memory, Regina REXX found no built-in function -written in lower case, and a reqtools flag test went wrong. +`MEMF_REVERSE|MEMF_CLEAR` memory, and a reqtools flag test went wrong. ## Cause @@ -123,5 +122,4 @@ decodes as such instructions too and gives false alarms. |---|---|---|---| | The example compiles to `btst #-23,(a3)`; `btst #1,(3,a3)` with the fix | (SRC) | any | `m68k-amigaos-gcc -m68080 -O2 -S`, GCC 6.5.0b with and without the patch; also `-m68020`, `-m68060` | | ApolloOS R10 (7662 C files) has 4 such instructions; with the fix 0, and the assembly is otherwise identical | (SRC) | any | `-S` output of the whole build with and without the patch, compared file by file | -| Regina REXX on R10: lower-case built-ins not found before the fix, found after (also ARexx file I/O) | (M) | Core 12856 | Scripts run with `rx` on a V4, regina.library built with each compiler | | `-mno-bitfield` avoids the bug | (SRC) | any | `-S` output of the example and of a pointer-to-flags test | diff --git a/toolchain/pitfalls/gcc-dbra-address-register-loop.md b/toolchain/pitfalls/gcc-dbra-address-register-loop.md index 7167333..dac5d98 100644 --- a/toolchain/pitfalls/gcc-dbra-address-register-loop.md +++ b/toolchain/pitfalls/gcc-dbra-address-register-loop.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -21,17 +21,16 @@ sources: ## Symptom A loop with a 16-bit counter runs about 4 billion times instead of the -intended count, at `-O2`. It always shows on real Fast RAM; under emulators -only when the low word of the pointer is `$8000` or higher. +intended count, at `-O2`. ## Cause GCC's m68k patterns `*dbne_hi`/`*dbge_hi` emit `subq.w #1,An; cmp.w #-1,An`, which is a 32-bit operation on an address register. After ivopts builds a UWORD counter from a pointer, the high word never reaches −1. The bug is -GCC's, not the core's: the same loop also runs away on a real 68060. +GCC's, not the core's. -The fix (`tst.w An; subq.w #1,An; jne`, also faster) is +The fix (`tst.w An; subq.w #1,An; jne`) is `m68k-dbra-hi-addrreg-fix.patch` from ApolloCrossDev pull request #7, merged on 2026-11-03. A later merge dropped the step that applies it; it was put back in GCC-6.50-Dev the same day. GCC-6.50-Stable and GCC-6.50-Base do not @@ -56,7 +55,7 @@ Use GCC-6.50-Dev installed on or after 2026-11-03 (its install log shows "Applying the m68k dbra HI address-register fix"). With another variant or an older install: -- compile with `-fno-ivopts` (3–6 % slower on the tested code), or +- compile with `-fno-ivopts`, or - mark the affected function `__attribute__((noinline))`. ## Detection @@ -67,7 +66,4 @@ Compile with `-S` and look for `subq.w #1,aN` followed by `cmp.w #-1,aN`. | Claim | Source | Core | Method | |---|---|---|---| -| Loop runs away on Fast RAM | (M) | any | Real project, V4 | -| `tst.w An` tests only bits 15–0; `subq` to An leaves the CCR alone | (M) | Core 12841 | Self-checking test tstan, 252 checks x 3 passes; 0 failures on the 080 and on a real 68060 | -| The old GCC loop also runs away on a real 68060 | (M) | 68060 | Same test | | Fix in ApolloCrossDev PR #7, applied by the Dev scripts | (SRC) | any | Pull requests, install scripts | diff --git a/toolchain/pitfalls/gcc-double-indirect-stack-slot.md b/toolchain/pitfalls/gcc-double-indirect-stack-slot.md deleted file mode 100644 index 4dd8cda..0000000 --- a/toolchain/pitfalls/gcc-double-indirect-stack-slot.md +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: GCC 6.5 puts memory indirect operands on the wrong stack slot after a call -type: pitfall -owner: WDrijver -status: draft -origin: ai-assisted -basis: [measured, source-code] -components: [toolchain] -applies_to: - core: "any" - os: [any] -tags: [gcc, double-indirect, memory-indirect, reload, miscompile, m68080] -related: - - toolchain/compiler-variants.md - - core/pitfalls/double-memory-indirect.md -sources: - - "ApolloOS R10 port (ApolloOS-Port), 2026-11-17: libjpeg 9 jdsample.c sep_upsample in jfif.library; whole-build scan of 7662 C files" - - "github.com/WDrijver/ApolloCrossDev pull request #15 (removes double-indirect-fix.patch, 2026-11-04)" - - "github.com/WDrijver/ApolloCrossDev issue #27 (this bug, with the reproduction)" ---- - -## Symptom - -Code compiled with GCC-6.50-Dev and `-m68080 -O2 -fomit-frame-pointer` -updates the wrong variable through a pointer argument. In libjpeg 9, -`jpeg_read_scanlines()` returned 0 rows forever and corrupted `cinfo->err`. -A program decoding a JPEG looped and then crashed with a garbage PC. - -## Cause - -- Since `double-indirect-fix.patch` was removed (2026-11-04), GCC-6.50-Dev - emits memory indirect operands `([bd,An],od)` on `-m68080`. Its cost model - chooses them there. On `-m68020` and `-m68060` it does not. -- When a pointer argument gets no register, reload replaces it by its stack - slot inside the outer memory reference: `([N,sp])`. `N` is the offset at - function entry. Reload does not add the bytes of a call's pushed - arguments, so between the pushes and the pop the operand addresses - another argument's slot. -- The bbb pass is not involved: `-fbbb=-` gives the same code. - -## Wrong - -```c -/* out_ctr: 6th argument; -m68080 -O2 -fomit-frame-pointer */ -cinfo->cconvert->convert(cinfo, st->buf, st->next_row, out_buf + *out_ctr, n); -*out_ctr += n; -``` - -```text - jsr (a0) - add.l d2,([56,sp]) ; 20 bytes still pushed: this is cinfo's slot - lea (20,sp),sp -``` - -## Right - -Build with `-fno-double-indirect`. GCC then loads the pointer from the right -slot (`move.l (76,sp),a0`) and emits no memory indirect operands at all. -That also avoids the slow mode (see -[double-memory-indirect.md](../../core/pitfalls/double-memory-indirect.md)). - -## Detection - -Compile with `-S` and search for `([`. In the ApolloOS R10 tree (7662 C -files), the Dev compiler emitted 23437 memory indirect operands, 2236 of them -sp-based in 676 files. With `-fno-double-indirect` it emitted none. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| `add.l d2,([56,sp])` after the call, with 20 bytes of arguments pushed | (M) 2026-11-17 | any | `-S` of a 50-line reduction of libjpeg `sep_upsample`; RTL dumps: the bad operand first appears in the reload pass, from the REG_EQUIV `(mem (plus argp 28))` | -| Only `-m68080` | (M) 2026-11-17 | any | Same file with `-m68020`, `-m68060`: pointer loaded into a register first | -| `-fno-double-indirect` fixes it | (M) 2026-11-17 | Core 12856, V4 UniCorn | Reduction: `move.l (76,sp),a0`. jfif.library rebuilt: MultiView shows the JPEG on the V4 | -| Scale | (M) 2026-11-17 | any | Whole-build `-S` scan, ApolloOS R10 tree | diff --git a/toolchain/pitfalls/gcc-fsincos-ice.md b/toolchain/pitfalls/gcc-fsincos-ice.md index 9c89013..e1aa09c 100644 --- a/toolchain/pitfalls/gcc-fsincos-ice.md +++ b/toolchain/pitfalls/gcc-fsincos-ice.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -38,9 +38,7 @@ constraint. When the pointer in its address gets no hard register, the operand becomes a memory-indirect address that the backend rejects. The fix, `m68k-sincos-constraint-fix.patch` from ApolloCrossDev pull -request #8, was merged on 2026-11-03. Only GCC-6.50-Dev applies it. It -changes no code that compiled before: 69 C files with 3 flag sets gave -byte-identical assembly. +request #8, was merged on 2026-11-03. Only GCC-6.50-Dev applies it. ## Wrong @@ -62,5 +60,4 @@ The ICE above, with `-m68881 -ffast-math` in the flags. | Claim | Source | Core | Method | |---|---|---|---| -| ICE before the fix, builds with it | (M) | any | Failing project file and a 30-line reproducer, rebuilt cc1 | -| No other code change | (M) | any | 69 C files x 3 flag sets, byte-identical assembly | +| Empty input constraint of `sincos2_68881`; fixed in ApolloCrossDev PR #8, only GCC-6.50-Dev applies it | (SRC) | any | Pull request, `GCC-6.50-Dev-Linux.sh` | diff --git a/toolchain/pitfalls/gcc-misc-traps.md b/toolchain/pitfalls/gcc-misc-traps.md deleted file mode 100644 index 964d684..0000000 --- a/toolchain/pitfalls/gcc-misc-traps.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: Smaller GCC 6.5 traps (-mtune=68060, NULL writes, -O3) -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [toolchain] -applies_to: - core: "any" - os: [any] -tags: [gcc, mtune, muls, null-pointer, trap, O3] -related: - - toolchain/c-compiler-options.md - - toolchain/best-practices/gcc-code-generation-for-68080.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 9.1 and 9.2" ---- - -## Symptom - -- Multiply-heavy C code (FLAC) runs 3 times slower than expected. -- A deliberate write to address 0 ends in a guru 80000027 instead of the - intended effect. -- `-O3` builds are not faster than `-O2`. - -## Cause - -- `-mtune=68060` stops GCC from using the 64-bit `muls.l`, because the 68060 - emulates it in software. The 68080 runs it in hardware. -- GCC treats `*(ULONG *)0` as undefined behaviour and turns it into - `trap #7` (guru 80000027). -- `-O3` gave nothing over `-O2` in the measured projects. - -## Wrong - -```sh -m68k-amigaos-gcc -O2 -m68080 -mtune=68060 ... # FLAC 3x slower -``` - -```c -*(ULONG *)0 = value; /* becomes trap #7 */ -``` - -## Right - -- Don't tune for the 68060. Use the standard flags (`-m68080`, no `-mtune`). -- Make the NULL access in assembler, and compile with - `-fno-delete-null-pointer-checks`. -- Stay at `-O2` unless a measurement shows otherwise. - -## Detection - -Check Makefiles for `-mtune=68060` and `-O3`. Grep `-S` output for -`trap #7`. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| `-mtune=68060`: FLAC 3x slower | (M) | Core 12841 | FLAC decode | -| `*(ULONG*)0` becomes `trap #7` | (M) | any | `-S` output | -| `-O3` no gain over `-O2` | (M) | Core 12841 | MP3/FLAC projects | diff --git a/toolchain/pitfalls/gcc-mrtd-calling-convention.md b/toolchain/pitfalls/gcc-mrtd-calling-convention.md index fb8f5ca..f9911fb 100644 --- a/toolchain/pitfalls/gcc-mrtd-calling-convention.md +++ b/toolchain/pitfalls/gcc-mrtd-calling-convention.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain] applies_to: core: "any" @@ -12,7 +12,6 @@ applies_to: tags: [gcc, mrtd, rtd, calling-convention, ice, miscompile] related: - toolchain/compiler-variants.md - - toolchain/pitfalls/calling-assembler-from-gcc.md sources: - "github.com/WDrijver/ApolloCrossDev pull request #9 (merged on 2026-11-03)" - "github.com/WDrijver/ApolloCrossDev GCC-6.50-Dev-Linux.sh (2026-11-03)" @@ -60,8 +59,7 @@ The ICE above, or a link of `-mrtd` objects with a C library that was not built with `-mrtd`. CI checks that GCC-6.50-Dev compiles a call with stack arguments under -`-mrtd`. A Dev install built before the fix (2026-10-08) stops on this file -with the ICE above, at `-O0` and `-O2`. The called function must be external: +`-mrtd`. The called function must be external: GCC inlines one from the same file, and no call is left to test. ```c @@ -76,6 +74,5 @@ int callit(int x) { return add3(x, 2, 3) + 1; } | Claim | Source | Core | Method | |---|---|---|---| -| ICE on every call before the fix | (M) | any | Test case in ApolloCrossDev PR #9 | -| Correct with the fix | (M) | any | Test program built entirely with `-mrtd`, 10 tests, `-O0` to `-O3` and `-Os`, 68020/68040/68080, under vamos and on a V4 (3 rounds) | -| No change in code built without `-mrtd` | (M) | any | 400 C and 38 C++ files, byte-identical assembly | +| No `call_pop` patterns, bbb stack adjustment and cc0 `tst.l d0` defects; fixed in ApolloCrossDev PR #9, only GCC-6.50-Dev applies it | (SRC) | any | Pull request, `GCC-6.50-Dev-Linux.sh` | +| GCC-6.50-Dev compiles a call with stack arguments under `-mrtd` | CI | any | `kb:compile` block in Detection | diff --git a/toolchain/pitfalls/gcc-stackswap-defer-pop.md b/toolchain/pitfalls/gcc-stackswap-defer-pop.md deleted file mode 100644 index 8e8adde..0000000 --- a/toolchain/pitfalls/gcc-stackswap-defer-pop.md +++ /dev/null @@ -1,57 +0,0 @@ ---- -title: GCC pops call arguments after StackSwap -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [toolchain] -applies_to: - core: "any" - os: [amigaos-3.9, amigaos-3.2] -tags: [gcc, stackswap, stack, defer-pop, crash] -related: - - toolchain/c-compiler-options.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), sections 0 (rule 20) and 9.2" ---- - -## Symptom - -A program or library that calls `StackSwap()` crashes callers with small -stacks. The caller's stack is corrupted after the call returns. - -## Cause - -GCC defers popping call arguments and may emit `lea N(sp),sp` *after* the -code has swapped the stack back. It then adjusts the caller's stack instead -of the private one. This crashed an MP3 library for callers with small -stacks. - -## Wrong - -```c -StackSwap(&sss); -result = decode(frame, len); /* arguments popped later ... */ -StackSwap(&sss); /* ... after this swap back */ -``` - -## Right - -Build every file that uses `StackSwap()` with `-fno-defer-pop` (or with a -frame pointer), and read the generated code around the swap. - -```sh -m68k-amigaos-gcc -noixemul -O2 -m68080 -m68881 -fno-defer-pop -c player.c -``` - -## Detection - -Compile with `-S` and check that no `lea N(sp),sp` or `addq.l #N,sp` follows -the second `StackSwap` call for arguments pushed before it. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| `lea N(sp),sp` emitted after the swap back; crashes with small caller stacks | (M) | any | MP3 library, AmigaOS 3.9 | diff --git a/toolchain/pitfalls/gcc-variadic-taglist-address.md b/toolchain/pitfalls/gcc-variadic-taglist-address.md deleted file mode 100644 index b30eda7..0000000 --- a/toolchain/pitfalls/gcc-variadic-taglist-address.md +++ /dev/null @@ -1,129 +0,0 @@ ---- -title: "&tag1 as a tag list breaks when GCC inlines or clones a variadic function" -type: pitfall -owner: WDrijver -status: draft -origin: ai-assisted -basis: [measured] -components: [toolchain] -applies_to: - core: "any" - os: [any] -tags: [gcc, varargs, variadic, taglist, stack-tags, inline, ipa-cp, constprop] -related: - - toolchain/pitfalls/gcc-misc-traps.md - - toolchain/compiler-variants.md -sources: - - "ApolloOS R10 port (ApolloOS-Port), 2026-11-25: Prefs/IControl ChunkyImageOrSpace(), fixed in commit b5fd0c5c" - - "Reproduction with GCC-6.50-Dev m68k-amigaos-gcc 6.5.0b, -m68080 -fomit-frame-pointer, -O1/-O2/-Os/-O3 (this file, Detection)" ---- - -## Symptom - -A small helper of the classic Amiga form `f(Tag tag1, ...)` passes -`(struct TagItem *)&tag1` to a `...A()` function (`NewObjectA`, -`MUI_NewObjectA`, `SetAttrsA`). The called function sees none of the tags, -or garbage after the first one. Objects come up with default attributes, -`OM_NEW` or `MUIM_Setup` fails, and a window does not open. No warning is -given. - -In ApolloOS R10, IControl's preferences window never opened under AROS -Zune. Serial debug in ChunkyImage showed width 0, height 0, 0 colours and -no pixels, although the caller passed all of them. - -## Cause - -Reading the variadic arguments through the address of the last named -parameter was never valid C. It works only while the function is an -ordinary out-of-line function whose named and variadic arguments lie next -to each other on the stack, which is the classic m68k stack calling -convention. GCC is free to break that, and GCC 6.5 (ApolloCrossDev) does: - -- **Inlining.** A variadic function that never calls `va_start` can be - inlined. At the call site GCC then does not push the variadic arguments - at all. `&tag1` becomes the address of a local copy of `tag1`, followed - by whatever lies in the frame. This happens to a `static` helper at - `-O1`, `-O2`, `-Os` and `-O3`. It also happens to a non-static helper - called from the same file; only calls from other files still work. -- **Interprocedural constant propagation.** When every call passes the - same constant first argument (for example `TAG_IGNORE`), GCC makes a - specialised clone (`f.constprop.N` in the symbol table) without that - parameter. Inside the clone `&tag1` again points at a local copy, not - at the stack slot before the variadic arguments. `__attribute__((noinline))` - alone does not stop this. - -## Wrong - -```c -static Object *ChunkyImageOrSpace(Tag tag1, ...) -{ - struct TagItem *tags = (struct TagItem *)&tag1; /* not the caller's tags */ - Object *o = MUI_NewObjectA(MUIC_ChunkyImage, tags); - ... -} - -ChunkyImageOrSpace(TAG_IGNORE, 0, - MUIA_ChunkyImage_Pixels, (IPTR)pixels, MUIA_Bitmap_Width, 128, TAG_DONE); -``` - -## Right - -Copy the tags with `va_arg`. This is valid C and stays correct when GCC -clones the function: the clone still reads the caller's arguments. - -```c -#include - -#define MAXTAGS 16 -static Object *ChunkyImageOrSpace(Tag tag1, ...) -{ - struct TagItem tags[MAXTAGS + 1]; - Tag tag = tag1; - va_list ap; - int n = 0; - - va_start(ap, tag1); - while (tag != TAG_DONE && n < MAXTAGS) - { - tags[n].ti_Tag = tag; - tags[n].ti_Data = va_arg(ap, IPTR); /* ULONG on AmigaOS headers */ - n++; - tag = va_arg(ap, Tag); - } - va_end(ap); - tags[n].ti_Tag = TAG_DONE; - tags[n].ti_Data = 0; - - return MUI_NewObjectA(MUIC_ChunkyImage, tags); -} -``` - -On AROS and ApolloOS sources, `AROS_SLOWSTACKTAGS_PRE` / -`AROS_SLOWSTACKTAGS_ARG` / `AROS_SLOWSTACKTAGS_POST` (``) -do the same. If the `&tag1` form must stay, mark the function -`__attribute__((noinline, noclone))`. Both attributes are needed. - -## Detection - -- Review: search for `(struct TagItem *)&` in your own code. Every hit in - a function without `va_start` is a candidate. The `vastubs.c` files of - NList and BetterString use the form too, but they are compiled only for - non-AROS compilers and are called from other files. -- Build: `m68k-amigaos-objdump -t file.o | grep constprop` lists cloned - functions. A variadic helper that is missing from the symbol table was - inlined. -- Reproduction (GCC-6.50-Dev, `-m68080 -fomit-frame-pointer -O2`): a - static `wrong(Tag tag1, ...)` that returns `use_tags((struct TagItem - *)&tag1)`, called twice as `wrong(TAG_IGNORE, 0, 0x80001234, 42, - TAG_DONE)`. The caller's code contains no push of `0x80001234` at all, - and `use_tags` receives the address of a local holding 1. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| A static variadic helper using `&tag1` is inlined and the variadic arguments are not pushed, at -O1, -O2, -Os and -O3 | (M) 2026-11-25 | any (compiler output) | GCC-6.50-Dev 6.5.0b, `-m68080 -fomit-frame-pointer`, objdump of the reproduction | -| A non-static helper is inlined the same way at a call site in the same file | (M) 2026-11-25 | any | same; `extern` variant | -| `noinline` alone gives a `.constprop` clone without the constant first parameter; `noinline, noclone` keeps the stack layout | (M) 2026-11-25 | any | same; `noinline` and `noinline, noclone` variants | -| The `va_arg` copy is also cloned, but reads the caller's arguments from the stack | (M) 2026-11-25 | any | same; disassembly of `wrong.constprop.0` (`lea 84(sp),a0`) | -| IControl's ChunkyImage objects got no attributes and the window did not open; with the `va_arg` copy all four images are built and the window opens | (M) 2026-11-25 | Core 12856 | ApolloOS R10 dev card, AROS master Zune muimaster.library with serial debug in ChunkyImage/Bitmap setup | diff --git a/toolchain/pitfalls/libnix-and-header-traps.md b/toolchain/pitfalls/libnix-and-header-traps.md deleted file mode 100644 index 7ba7ba1..0000000 --- a/toolchain/pitfalls/libnix-and-header-traps.md +++ /dev/null @@ -1,72 +0,0 @@ ---- -title: libnix and header traps -type: pitfall -owner: TuKo1982 -status: reviewed -origin: ai-assisted -basis: [measured] -components: [toolchain] -applies_to: - core: "any" - os: [amigaos-3.9, amigaos-3.2] -tags: [libnix, sprintf, stdio, stack, headers, mui, stdint] -related: - - toolchain/c-compiler-options.md - - toolchain/target-os-headers.md -sources: - - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 9.5" - - "github.com/WDrijver/ApolloCrossDev pull request #6 (merged on 2026-11-03)" ---- - -## Symptom - -- `sprintf` prints 16-bit numbers for `%d` and returns no length. -- GCC 6 fails on `stdint.h` from an SDK. -- A MUI 3.8 system refuses to open muimaster.library. -- Output from worker processes is garbled; a requested stack size is - ignored; `memset`/`memcmp` are slow; `%p` prints wrongly. - -## Cause - -| Trap | Cause | -|---|---| -| `sprintf` behaves like RawDoFmt | libnix `sprintf` lives in `libm.a`. Without `-lm`, amiga.lib's `sprintf` (RawDoFmt: `%d` = 16 bits, no length returned) is linked silently | -| SDK `stdint.h` breaks GCC 6 | The SDK's header conflicts with GCC 6's own | -| muimaster.library does not open | GCC 6 `mui.h` sets `MUIMASTER_VMIN` to 20 (MUI 4). ApolloCrossDev installs from 2026-11-03 lower it to 19 in all GCC 6.5 variants | -| Worker process output | libnix stdio is not safe from worker processes | -| Stack size ignored | libnix does not honour `__stack` | -| Slow `memset`/`memcmp` | libnix works byte by byte | -| `%p` | Misprints in libnix | - -## Wrong - -```sh -m68k-amigaos-gcc main.o -noixemul -o app # amiga.lib sprintf -m68k-amigaos-gcc -I sdk/include -c main.c # SDK stdint.h first -``` - -## Right - -```sh -m68k-amigaos-gcc main.o -noixemul -lm -o app # libnix sprintf -m68k-amigaos-gcc -idirafter sdk/include -c main.c # SDK headers last -``` - -- Open muimaster.library with version 19 for MUI 3.8. An install from - 2026-11-03 does this through `MUIMASTER_VMIN`; with an older install, pass - 19 yourself. -- Do stdio from the main process only. -- Swap to your own stack with `StackSwap()` when you need a larger one (see - [gcc-stackswap-defer-pop.md](gcc-stackswap-defer-pop.md)). -- Write your own `memset`/`memcmp` for hot paths. - -## Detection - -Check the link line for `-lm`, the include order for SDK folders, and the -muimaster version you open. - -## Evidence - -| Claim | Source | Core | Method | -|---|---|---|---| -| All items in the table | (M) | any | Project builds on AmigaOS 3.9 | diff --git a/toolchain/pitfalls/vasm-68080-encoding-issues.md b/toolchain/pitfalls/vasm-68080-encoding-issues.md index b365b55..242ebaf 100644 --- a/toolchain/pitfalls/vasm-68080-encoding-issues.md +++ b/toolchain/pitfalls/vasm-68080-encoding-issues.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, source-code] +basis: [source-code] components: [toolchain, cpu-68080] applies_to: core: "Core 12841" @@ -12,9 +12,7 @@ applies_to: tags: [vasm, bank, ammx, encoding, branches, listing] related: - core/pitfalls/bank-prefix-pitfalls.md - - core/pitfalls/ammx-pc-relative-source.md - core/pitfalls/ammx-separate-load-and-store.md - - core/pitfalls/tex-does-not-match-prm.md - toolchain/vasm-assembler.md sources: - "TuKo1982, 68080 compilation and optimisation guide (2026-10-30), section 9.4" @@ -37,32 +35,18 @@ differently from the core: | BANK single operand (`tst e6`, `clr e2`) | Sets AA only | Uses the plain Dn: `tst e6` tests d6 | | `add.l #imm,En` | Sets BB only (`$7101`) | Writes plain Dn + imm into En | | `add.l b1,d0` | Emits `$71F1`, a BANK word with SS ≠ 0 | Illegal instruction | -| `move.l a0,b1` | Rejects it | Not a supported form anyway | -| AMMX PC-relative source (`load .k(pc),d0`) | Counts the displacement from the third word; the core counts from the second | Reads 2 bytes early | | An out-of-range `.s` branch with `-m68080` | Silently emits the 080-only `.s+` | Runs only on the 68080 | -| abs, min, max, andn | Assembles them | They do nothing on the core and raise no exception | -| TEX | No syntax in 2.0g | Needs `dc.w` | -| movz2, moveh, some `touch (An,Xn)` forms | Not available | Needs `dc.w` | -| `load` at the top of a file | Taken as a directive | Assembly error or wrong code | - -Without `-no-opt`, vasm also emits `and/or/sub #imm` instead of -`andi/ori/subi`, rewrites branch sizes and turns `move.l #imm` into `moveq`, -so binaries are not byte-identical to Devpac builds. ## Wrong ```asm tst.l e6 ; assembles as tst.l d6 - load .k(pc),d0 ; reads .k - 2 ``` ## Right - Hand-encode BANK single-operand and `#imm,Rn` forms with AA = BB (see [bank-prefix-pitfalls.md](../../core/pitfalls/bank-prefix-pitfalls.md)). -- Load AMMX data through `lea .k(pc),An` + `load (An),Dn`. -- Don't use abs/min/max/andn. -- Use `-no-opt` for byte-exact round trips and for CPU tests. - Decode every hand-encoded `dc.w` back with an 080-aware disassembler and check its length. @@ -71,8 +55,7 @@ so binaries are not byte-identical to Devpac builds. Assemble with `-L file.lst` and check: - BANK words (`$71xx`) in front of single-operand and `#imm` instructions; -- odd displacement bytes in `.s` branches (the `.s+` form); -- `(pc)` source operands on AMMX instructions. +- odd displacement bytes in `.s` branches (the `.s+` form). CI checks three rows of the table with the vasm that ApolloCrossDev ships and the standard flags (`-m68080 -m68881 -opt-speed`). When a vasm update @@ -102,6 +85,6 @@ far: rts | Claim | Source | Core | Method | |---|---|---|---| -| Encodings in the table above | (M) | Core 12841 | vasm 2.0f/2.0g listings run on the V4 | +| Encodings in the table above | CI | any | `kb:compile` block in Detection, vasm shipped with ApolloCrossDev | | ApolloCrossDev ships vasm 2.0f | (SRC) | any | `vasm.c`: `_VER "vasm 2.0f"` | | The vasm opcode table (`cpus/m68k/opcodes.h`, "apollo" entries) is a good encoding reference | (SRC) | any | vasm source | diff --git a/toolchain/pitfalls/vasm-pc-relative-destination.md b/toolchain/pitfalls/vasm-pc-relative-destination.md index 189441a..eb81834 100644 --- a/toolchain/pitfalls/vasm-pc-relative-destination.md +++ b/toolchain/pitfalls/vasm-pc-relative-destination.md @@ -4,7 +4,7 @@ type: pitfall owner: TuKo1982 status: reviewed origin: ai-assisted -basis: [measured, official, source-code] +basis: [official, source-code] components: [toolchain, cpu-68080] applies_to: core: "Core 12841" @@ -27,15 +27,11 @@ written as an absolute address. ## Cause - With `-m68080`, vasm optimizes an absolute destination `move.x ,label` - into a PC-relative destination `label(pc)` by default. It does the same - for addq/subq, bchg/bclr/bset, eor, fmove and AMMX stores. + into a PC-relative destination `label(pc)` by default. - The 68080 computes a PC-relative destination wrongly when the source uses the full extension format (for example `(table.l,d0.w)` or memory indirect). See [core/pitfalls/pc-relative-destination.md](../../core/pitfalls/pc-relative-destination.md). -- This optimization is on by default; `-opt-speed` is not what causes it. - `-nodpc` and `opt` directives do not turn it off; only `-no-opt` does. -- ApolloCrossDev ships vasm 2.0f (SRC), which has this behaviour (M). The - vasm author has been informed; a fix will come in a future ApolloCrossDev +- ApolloCrossDev ships vasm 2.0f (SRC). The vasm author has been informed; a fix will come in a future ApolloCrossDev update. ## Wrong @@ -54,13 +50,9 @@ full-format source with a label destination: move.b (table.l,d0.w),(a1) ``` -Or assemble that file with `-no-opt`. That turns off **all** vasm -optimizations (also `moveq` for `move.l #imm` and branch-size choices), so -optimize those by hand. - ## Detection -Assemble with a listing (`-L file.lst`) and look for MOVE and the other +Assemble with a listing (`-L file.lst`) and look for MOVE and other instructions above with destination mode 7/2 (`d16(pc)`) and a full-format source operand. @@ -69,6 +61,5 @@ source operand. | Claim | Source | Core | Method | |---|---|---|---| | PC-relative destination is not calculated correctly with some extended source formats | (official) PRM, integer unit page | any | Manual | -| vasm `-m68080` makes `(d16,PC)` destinations by default; only `-no-opt` stops it | (M) | any | vasm 2.0f/2.0g listings | | The fix belongs in vasm `cpu.c`: `APOLLO_PCDEST` misses operand types DN/MA/MI/BS/CT | (SRC) | any | vasm source | | ApolloCrossDev ships vasm 2.0f | (SRC) | any | `vasm.c`: `_VER "vasm 2.0f"` |