Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions core/best-practices/ammx-where-it-wins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion core/cpu-68080/prm/ammx/loadi.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -20,6 +21,8 @@ generated_from: sources/official/AC68080PRM.odt

<!-- GENERATED by tools/intake/prm68080.py from sources/official/AC68080PRM.odt. Do not edit: change the original and regenerate. -->

**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.
Expand Down
5 changes: 4 additions & 1 deletion core/cpu-68080/prm/ammx/storei.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -20,6 +21,8 @@ generated_from: sources/official/AC68080PRM.odt

<!-- GENERATED by tools/intake/prm68080.py from sources/official/AC68080PRM.odt. Do not edit: change the original and regenerate. -->

**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.
Expand Down
133 changes: 133 additions & 0 deletions core/pitfalls/ammx-separate-load-and-store.md
Original file line number Diff line number Diff line change
@@ -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 <vea>,b,d`. `<vea>` 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,<vea>`, `storem b,mask,<vea>`, `storec b,count,<vea>`,
`storeilm b,mask,<vea>`, `storem3 b,#mode,<vea>`, and the pack
instructions `packuswb b,d,<vea>` and `pack3216 b,d,<vea>`.

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) |
2 changes: 1 addition & 1 deletion os/libraries/workbench-wbconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions toolchain/pitfalls/vasm-68080-encoding-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 29 additions & 1 deletion tools/intake/prm68080.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down