From 57f692c0e5da2d5fe0b1c361a9f04e43baf7ec07 Mon Sep 17 00:00:00 2001 From: WDrijver Date: Tue, 24 Nov 2026 14:32:33 +0100 Subject: [PATCH 1/3] Pitfall: AMMX code with a separate LOAD or STORE Gunnar (2026-11-24): AI agents load every AMMX operand with LOAD and store pack results with STORE. Operations take (register, memory or immediate) as their first operand; store and pack instructions have on the right. Don't use LOADI and STOREI. Includes the vasm 2.0g syntax for the repeated-word immediate (paddb.w #$0101) and the silent 64-bit immediate without the suffix, the PC-relative exception, and the names vasm accepts. Co-Authored-By: Claude Opus 5.5 --- core/best-practices/ammx-where-it-wins.md | 1 + core/pitfalls/ammx-separate-load-and-store.md | 133 ++++++++++++++++++ .../pitfalls/vasm-68080-encoding-issues.md | 1 + 3 files changed, 135 insertions(+) create mode 100644 core/pitfalls/ammx-separate-load-and-store.md diff --git a/core/best-practices/ammx-where-it-wins.md b/core/best-practices/ammx-where-it-wins.md index c06dfa0..3873995 100644 --- a/core/best-practices/ammx-where-it-wins.md +++ b/core/best-practices/ammx-where-it-wins.md @@ -11,6 +11,7 @@ applies_to: 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 diff --git a/core/pitfalls/ammx-separate-load-and-store.md b/core/pitfalls/ammx-separate-load-and-store.md new file mode 100644 index 0000000..ae81ede --- /dev/null +++ b/core/pitfalls/ammx-separate-load-and-store.md @@ -0,0 +1,133 @@ +--- +title: AMMX code with a separate LOAD or STORE where the operand can be memory +type: pitfall +owner: WDrijver +status: draft +origin: ai-assisted +basis: [core-developer, official, source-code] +components: [cpu-68080, toolchain] +applies_to: + core: "any" + os: [any] +tags: [68080, ammx, load, store, vea, immediate, packuswb, pack3216, loadi, storei] +related: + - core/cpu-68080/prm/ammx/ammx-format.md + - core/cpu-68080/prm/ammx/load.md + - core/cpu-68080/prm/ammx/store.md + - core/cpu-68080/prm/ammx/packuswb.md + - 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: + - "Gunnar (core developer), AMMX operand forms, 2026-11-24" + - "Apollo 68080 PRM (sources/official/AC68080PRM.odt), AMMX format page" + - "vasm 2.0g (ApolloCrossDev GCC-6.50-Dev), test assembly of the forms below, 2026-11-24" +--- + +## Symptom + +AMMX code that loads every operand with `load` before the operation, or +packs into a register and then stores it with `store`. It runs and gives the +right result, but uses more instructions and more slots of the one AMMX unit +than needed. Gunnar sees this "again and again" in AI-written code (G). + +## Cause + +AMMX instructions have two forms (G, official): + +- **Operations** take their first operand from an effective address: + `op ,b,d`. `` can be a register (D0–D7, E0–E23), any memory mode + (`(An)`, `(An)+`, `-(An)`, `d16(An)`, `d8(An,Xn)`, absolute) or an + immediate. The result always goes to the register `d`. +- **Store instructions** have the effective address on the right and write + to memory: `store b,`, `storem b,mask,`, `storec b,count,`, + `storeilm b,mask,`, `storem3 b,#mode,`, and the pack + instructions `packuswb b,d,` and `pack3216 b,d,`. + +So a separate `load` is not needed when the value is used once, and a pack +needs no `store` after it. There is one AMMX unit; the second pipe accepts +AMMX stores only (M, see +[superscalar-issue.md](../cpu-68080/superscalar-issue.md)), so every extra +`load` takes a slot on that unit. + +Other AMMX operations have no form that writes to memory: the PRM's +"write to memory (b,d,vea)" mode is marked future, and vasm 2.0g rejects +`paddw d1,d2,(a0)`. Their results still need a `store`. + +## Wrong + +```asm +.loop: + load (a0)+,d0 + paddusb d0,d1,d2 ; d1 + source, saturated + packuswb d2,d3,d4 + store d4,(a1)+ + dbra.l d7,.loop +``` + +## Right + +```asm +.loop: + paddusb (a0)+,d1,d2 ; memory source, no load + packuswb d2,d3,(a1)+ ; packs straight to memory, no store + dbra.l d7,.loop +``` + +An immediate is an operand too: + +```asm + paddb.w #$0101,d1,d2 ; the word $0101 repeated: +1 in every byte lane +``` + +### 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, + `paddb #$0101,d1,d2` assembles silently to a 64-bit immediate + `$0000000000000101` (12-byte instruction), so only the lowest lanes get + the value. `paddb #$0101.w,d1,d2` does the same, with a "trailing garbage" + warning. Gunnar suggests `#imm.w` as the syntax (G); vasm does not + support it. +- **Names:** Gunnar calls the store instructions VSTORE, VSTOREM, + VSTOREC, VSTOREM2 and VSTOREM3. vasm accepts only the PRM names `store`, + `storem`, `storec`, `storeilm` (the PRM: "also called storem2") and + `storem3`, and `pack3216` (not "PACK3116"). + +### Don't use LOADI and STOREI + +Gunnar (G, 2026-11-24): `loadi` and `storei`, the indexed variants that +take the register number from another register, are extremely dangerous to +use and esoteric in their use cases. Don't use them. He would remove them +from the instruction list. Their PRM pages +([loadi.md](../cpu-68080/prm/ammx/loadi.md), +[storei.md](../cpu-68080/prm/ammx/storei.md)) are generated from the PRM +and still describe them. + +## Detection + +- A `load` whose register is read by exactly one AMMX operation. +- A `store` of a register that a `packuswb` or `pack3216` just wrote. +- An AMMX immediate without a `.w` suffix whose value fits in a word. +- Any `loadi` or `storei`. + +## Evidence + +| Claim | Source | Core | Method | +|---|---|---|---| +| Operations take `(EA)` on the left; store and pack instructions have it on the right; agents add needless `load`/`store` | (G) | any | Statement, 2026-11-24 | +| `#imm.W` is a word repeated to a quad | (official) | any | PRM AMMX format page | +| The general write-to-memory mode (M=1) is future | (official) | any | PRM AMMX format page | +| `paddw (a0)+,d1,d2`, `paddw 8(a0),d1,d2`, `paddw (a0),e1,e2`, `pmull (a0)+,d1,d2`, `packuswb d1,d2,(a0)+`, `pack3216 d1,d2,(a0)+` assemble; `paddw d1,d2,(a0)` is rejected | (SRC) | any | vasm 2.0g, 2026-11-24 | +| `paddb.w #$0101` → `ff3c 1210 0101`; `paddb #$0101` → `fe3c 1210` + 8-byte immediate `0000000000000101` | (SRC) | any | vasm 2.0g, 2026-11-24 | +| Don't use `loadi`/`storei` | (G) | any | Statement, 2026-11-24 | +| Cost of a memory source against a register source | Not measured | | To be measured on Core 13000+ (G) | diff --git a/toolchain/pitfalls/vasm-68080-encoding-issues.md b/toolchain/pitfalls/vasm-68080-encoding-issues.md index e11acf7..b365b55 100644 --- a/toolchain/pitfalls/vasm-68080-encoding-issues.md +++ b/toolchain/pitfalls/vasm-68080-encoding-issues.md @@ -13,6 +13,7 @@ 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: From b7d66ff08d0973ee05d3742057943447c3e7f3e4 Mon Sep 17 00:00:00 2001 From: WDrijver Date: Tue, 24 Nov 2026 14:39:27 +0100 Subject: [PATCH 2/3] PRM converter: generate LOADI and STOREI as deprecated Decision WDrijver (option b): the original PRM stays as it is; the converter marks loadi.md and storei.md deprecated, superseded by the AMMX load/store pitfall, with a reason line from Gunnar's 2026-11-24 statement. Co-Authored-By: Claude Opus 5.5 --- core/cpu-68080/prm/ammx/loadi.md | 5 ++++- core/cpu-68080/prm/ammx/storei.md | 5 ++++- tools/intake/prm68080.py | 30 +++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/core/cpu-68080/prm/ammx/loadi.md b/core/cpu-68080/prm/ammx/loadi.md index 104042f..99c96c1 100644 --- a/core/cpu-68080/prm/ammx/loadi.md +++ b/core/cpu-68080/prm/ammx/loadi.md @@ -2,7 +2,8 @@ title: "LOADI: Load Indirect source into register" type: reference owner: WDrijver -status: reviewed +status: deprecated +superseded_by: core/pitfalls/ammx-separate-load-and-store.md origin: official basis: [official] components: [cpu-68080] @@ -20,6 +21,8 @@ generated_from: sources/official/AC68080PRM.odt +**Deprecated:** don't use this instruction. Gunnar (core developer, 2026-11-24) calls LOADI and STOREI extremely dangerous and esoteric; see [the AMMX load/store pitfall](../../../pitfalls/ammx-separate-load-and-store.md). The page below is the PRM text. + ## Summary **LOADI** (Load Indirect source into register): Load 64 bit indirect into destination register. diff --git a/core/cpu-68080/prm/ammx/storei.md b/core/cpu-68080/prm/ammx/storei.md index 69fe318..c50a972 100644 --- a/core/cpu-68080/prm/ammx/storei.md +++ b/core/cpu-68080/prm/ammx/storei.md @@ -2,7 +2,8 @@ title: "STOREI: Store Indirect register into memory" type: reference owner: WDrijver -status: reviewed +status: deprecated +superseded_by: core/pitfalls/ammx-separate-load-and-store.md origin: official basis: [official] components: [cpu-68080] @@ -20,6 +21,8 @@ generated_from: sources/official/AC68080PRM.odt +**Deprecated:** don't use this instruction. Gunnar (core developer, 2026-11-24) calls LOADI and STOREI extremely dangerous and esoteric; see [the AMMX load/store pitfall](../../../pitfalls/ammx-separate-load-and-store.md). The page below is the PRM text. + ## Summary **STOREI** (Store Indirect register into memory): Store 64 bit from indirect source register in memory. diff --git a/tools/intake/prm68080.py b/tools/intake/prm68080.py index 901319f..5738356 100644 --- a/tools/intake/prm68080.py +++ b/tools/intake/prm68080.py @@ -1835,6 +1835,30 @@ def body(text): return text.split("\n---\n", 1)[-1] +# Pages the maintainers deprecate while the original PRM still describes +# them (decision WDrijver, 2026-11-24). The converter generates them as +# deprecated, with one line at the top of the body that says why. +DEPRECATED = { + "ammx/loadi.md": "core/pitfalls/ammx-separate-load-and-store.md", + "ammx/storei.md": "core/pitfalls/ammx-separate-load-and-store.md", +} +DEPRECATED_WHY = ( + "**Deprecated:** don't use this instruction. Gunnar (core developer, " + "2026-11-24) calls LOADI and STOREI extremely dangerous and esoteric; " + "see [the AMMX load/store pitfall](../../../pitfalls/" + "ammx-separate-load-and-store.md). The page below is the PRM text.") + + +def deprecate(text, superseded_by): + """Mark a generated page as deprecated: status, superseded_by and a + reason line after the GENERATED comment.""" + text = STATUS_RE.sub("", text) + text = text.replace("origin: ", "status: deprecated\n" + f"superseded_by: {superseded_by}\norigin: ", 1) + marker = "Do not edit: change the original and regenerate. -->\n" + return text.replace(marker, marker + "\n" + DEPRECATED_WHY + "\n", 1) + + def keep_status(old, new): """New text with the status fields of the old text, when the body is unchanged. A file keeps the status a maintainer gave it until its body @@ -1857,7 +1881,11 @@ def main(): for rel, text in files.items(): p = os.path.join(out, rel) old = open(p, encoding="utf-8").read() if os.path.isfile(p) else None - files[rel] = text = keep_status(old, text) + if rel in DEPRECATED: + text = deprecate(text, DEPRECATED[rel]) + else: + text = keep_status(old, text) + files[rel] = text if old != text: stale.append(rel) extra = sorted(existing - set(files)) From 6ab1e1339611fe25d3adb47796abe17998fed7a4 Mon Sep 17 00:00:00 2001 From: WDrijver Date: Tue, 24 Nov 2026 14:58:51 +0100 Subject: [PATCH 3/3] Fix Markdown lint on main: escape | in a WBConfig table cell PR #64 broke the KB checks on main (MD056, too many cells). Co-Authored-By: Claude Opus 5.5 --- os/libraries/workbench-wbconfig.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/os/libraries/workbench-wbconfig.md b/os/libraries/workbench-wbconfig.md index 2b423d6..7f0b296 100644 --- a/os/libraries/workbench-wbconfig.md +++ b/os/libraries/workbench-wbconfig.md @@ -89,7 +89,7 @@ frees the bitmap), then the struct (`AllocVec`/`FreeVec` in 44.23). | +10 | 1 | front pen (`fp_FrontPen`): colour of the icon label text | | +11 | 1 | back pen (`fp_BackPen`) | | +12 | 8 | `struct TextAttr`, `ta_Name` pointing to +20 | -| +20 | n | font name, NUL-terminated (`AllocVec(strlen(name) + 21, MEMF_PUBLIC | MEMF_CLEAR)`) | +| +20 | n | font name, NUL-terminated (`AllocVec(strlen(name) + 21, MEMF_PUBLIC \| MEMF_CLEAR)`) | To free a returned struct: `CloseFont()` on +4, then the struct.