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
2 changes: 1 addition & 1 deletion skills/apollo-new-project/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Copy `<ACD_ROOT>/Projects/_makefiles/Makefile` and change only:
| Line | Set to |
|---|---|
| `PROJECT_NAME` | the name |
| `C_INCL_NDK` | the `ndk39-include` line: AmigaOS 3.9 is a target, so a function that 3.9 lacks gives a compile error instead of a crash on 3.9 (`KB toolchain/target-os-headers.md`) |
| `C_INCL_NDK` | keep the `ndk-include` line (NDK 3.2). ApolloCrossDev installs no NDK 3.9: when AmigaOS 3.9 is a target, check every OS function the program calls against `KB os/apolloos-and-amigaos-on-v4.md` instead (`KB toolchain/target-os-headers.md`) |
| `C_COMPILER` | the `m68k-amigaos-g++` line for C++; the template does not collect `.cpp` files, so add them as `KB toolchain/project-makefile.md` says |

Keep `APOLLOLIB`, `C_OPTIONS` and `S_FLAGS` as they are.
Expand Down
12 changes: 9 additions & 3 deletions toolchain/c-compiler-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ more on code generation, [gcc-code-generation-for-68080.md](best-practices/gcc-c
| Runtime | Option | Include path |
|---|---|---|
| libnix (default) | `-noixemul` | `<prefix>/m68k-amigaos/libnix/include` |
| clib2 | `-mcrt=clib2` | `<prefix>/m68k-amigaos/clib2/include` |
| clib2 | `-mcrt=clib2` | `<prefix>/m68k-amigaos/clib2/include`, not installed by the GCC-6.50 scripts |

Pass the runtime option both when compiling and when linking.

Expand All @@ -62,12 +62,18 @@ and NDK 3.2:
-I. \
-I<prefix>/m68k-amigaos/libnix/include \
-I<prefix>/m68k-amigaos/sys-include \
-I<prefix>/m68k-amigaos/ndk32-include/Include_H
-I<prefix>/m68k-amigaos/ndk-include
```

For other target operating systems, see `toolchain/target-os-headers.md`.
Optional include folders: `<prefix>/m68k-amigaos/include/GL`, `.../SDL`,
`.../MUI`.
`.../mui` (lower case: case matters on Linux).

Until ApolloCrossDev pull request #38 (2026-11-25) the template pointed at
`ndk32-include/Include_H`, which the GCC-6.50 scripts never create. Builds
still worked because GCC's built-in include path already holds
`ndk-include`. A Makefile copied before that date has the wrong path; the
generated code is the same.

### Extra libraries

Expand Down
43 changes: 33 additions & 10 deletions toolchain/compiler-variants.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sources:
- "github.com/WDrijver/ApolloCrossDev pull request #15 (removes double-indirect-fix.patch) and issue #14"
- "WDrijver (ApolloCrossDev maintainer), 2026-11-04"
- "WDrijver (maintainer), 2026-11-11: LineA instructions are not yet implemented; only a few unreleased test cores had them"
- "github.com/WDrijver/ApolloCrossDev pull requests #26, #28, #29, #30, #34, #35 and #37 (merged 2026-11-16 to 2026-11-25), install scripts at commit c1fba26a4"
---

## Summary
Expand All @@ -34,17 +35,17 @@ and differ mainly in which Apollo 68080 patches they apply. Use GCC-6.50-Dev.

| Variant | Script | Apollo patches applied | Use |
|---|---|---|---|
| GCC-6.50-Dev | `GCC-6.50-Dev-Linux.sh`, `-MacOS.sh` | 12 (see below) | Default, latest |
| GCC-6.50-Stable | `GCC-6.50-Stable-Linux.sh`, `-MacOS.sh` | 5 | Fallback if GCC-6.50-Dev gives problems |
| GCC-6.50-Dev | `GCC-6.50-Dev-Linux.sh`, `-MacOS.sh` | 19 (see below) | Default, latest |
| GCC-6.50-Stable | `GCC-6.50-Stable-Linux.sh`, `-MacOS.sh` | 7 | Fallback if GCC-6.50-Dev gives problems |
| GCC-6.50-Base | `GCC-6.50-Base-Linux.sh`, `-MacOS.sh` | none | Original baseline (November 2024) |

Each variant installs into its own folder `Compilers/<variant>`, so several
can be installed side by side. All three set `MUIMASTER_VMIN` to 19 in
`mui.h`, so MUI programs also open on MUI 3.8 (from 2026-11-03).

Patches applied by GCC-6.50-Dev from ApolloCrossDev pull request #15
(2026-11-04), from
`Compilers/_archives/patches/`:
Patches applied by GCC-6.50-Dev (install scripts at ApolloCrossDev commit
`c1fba26a4`, 2026-11-25), from `Compilers/_archives/patches/`. The first
twelve date from ApolloCrossDev pull request #15 (2026-11-04):

| Patch | Author |
|---|---|
Expand All @@ -60,15 +61,23 @@ Patches applied by GCC-6.50-Dev from ApolloCrossDev pull request #15
| `m68k-mrtd-call-pop.patch` | TuKo1982 |
| `m68k-sincos-constraint-fix.patch` | TuKo1982 |
| `m68k-dbra-hi-addrreg-fix.patch` | TuKo1982 |
| `m68k-btst-mem-offset-fix.patch` (PR #26, 2026-11-16) | WDrijver |
| `reload-ind-equiv-offset-fix.patch` (PR #28, 2026-11-17) | WDrijver |
| `bbb-autoinc-converted-insn-fix.patch` (PR #29, 2026-11-24) | delwall |
| `bbb-invalidate-mem-fix.patch` (PR #30, 2026-11-24) | delwall |
| `bbb-autoinc-fixup-constraints-fix.patch` (PR #34, 2026-11-24) | WDrijver |
| `bbb-propagate-moves-bb-boundary-fix.patch` (PR #35, 2026-11-25) | WDrijver |
| `bbb-propagate-moves-addr-exit-fix.patch` (PR #37, 2026-11-25) | WDrijver |

Until then GCC-6.50-Dev also applied `double-indirect-fix.patch` by Marcel
(r3dbug). It stopped GCC from generating memory indirect addressing, and
made GCC crash on computed gotos through a table (`jmp ([table,dN.l*4])`,
for example in Lua's `lvm.c`). It was removed because the 68080 has full
double indirect addressing (WDrijver, 2026-11-04).

GCC-6.50-Stable applies `q2g-stable.patch` and the four patches by Morten,
none by TuKo1982.
GCC-6.50-Stable applies `q2g-stable.patch`, the four patches by Morten,
`m68k-btst-mem-offset-fix.patch` and `reload-ind-equiv-offset-fix.patch`.
It applies none by TuKo1982 and none of the bbb fixes.

### Known GCC bugs and which variant fixes them

Expand All @@ -79,11 +88,25 @@ none by TuKo1982.
| ICE with `-mrtd` | [gcc-mrtd-calling-convention.md](pitfalls/gcc-mrtd-calling-convention.md) | Fixed | Not fixed | Not fixed |
| 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 |
| ICE in `schedule_region` when bbb moves a copy out of a loop | [gcc-bbb-propagate-moves-ice.md](pitfalls/gcc-bbb-propagate-moves-ice.md) | Fixed | Not fixed | Not fixed |
| bbb pass gives an early loop exit the old pointer value | [gcc-bbb-propagate-moves-loop-exit.md](pitfalls/gcc-bbb-propagate-moves-loop-exit.md) | Fixed | Not fixed | Not fixed |
| ICE in `print_operand_address2` on computed gotos (Dev builds of 2026-11-03 only) | [double-memory-indirect.md](../core/pitfalls/double-memory-indirect.md) | Fixed (patch removed) | Not affected | Not affected |

"Fixed" means the install script applies the patch on 2026-11-03. A fix only
reaches you when you reinstall the variant; an older install still has the
bug.
"Fixed" means the install script applies the patch at ApolloCrossDev commit
`c1fba26a4` (2026-11-25). A fix only reaches you when you reinstall the
variant; an older install still has the bug. Each pitfall gives the date from
which an install has the fix.

`m68k-amigaos-gcc --version` prints `6.5.0b 240104120137` for every install,
so it does not tell which patches you have. Check the date of the install
(`ls -l <prefix>/libexec/gcc/m68k-amigaos/6.5.0b/cc1`) against the merge dates
above. When a bbb bug is suspected, compile the file again with `-fbbb=-`: if
the problem goes away, it is in the bbb pass.

### 68080 instructions the compiler generates

Expand Down
107 changes: 107 additions & 0 deletions toolchain/pitfalls/gcc-bbb-autoinc-converted-insn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: GCC 6.5 bbb pass fixes up a post-increment it just made, and a pointer advances too little
type: pitfall
owner: WDrijver
status: draft
origin: ai-assisted
basis: [measured, source-code]
components: [toolchain]
applies_to:
core: "any"
os: [any]
tags: [gcc, bbb, optimizer, autoincrement, miscompile, struct-stride]
related:
- toolchain/compiler-variants.md
- 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

A loop over packed records (for example 12-byte `float[3]` vertices) reads
the wrong fields and advances its pointer too little. The result is silently
wrong. There is no warning and no crash. `-fbbb=-` gives correct code.

It needs a loop body that reads the same record in two groups, such as two
dot products on the same vertex. The original case was a 68080 renderer.
`float`, `double`, and 3, 4 or 5 element records were all affected.

## Cause

Bebbo's bbb pass `opt_autoinc` (`-fbbb=i`) turns `(a0)`, `(4,a0)`, `(8,a0)`
into post-increments one instruction at a time. For each one it lowers the
offsets of the other uses of `a0` and the closing `add`/`lea`. After an
instruction is converted, its bookkeeping still shows the old offset until
the next pass. A later search in the same pass sees that instruction as a
plain `(-4,a0)` access and lowers the `add` a second time. Offsets shift too
far and a `lea (4,a0),a0` that must stay is deleted.

In the reproducer below, `a0` advanced 8 bytes per vertex instead of 12, and
`v[2]` was read from `(a0)` instead of `(4,a0)`.

The fix makes `try_auto_inc` stop at an instruction that already
auto-modifies the register. Only GCC-6.50-Dev applies it.

## Wrong

```c
typedef float vec3_t[3];
void uv(const vec3_t *pos, float (*out)[2], int n,
const float *vx, const float *vy,
float ox, float oy, float sx, float sy, float k)
{
int i;
for (i = 0; i < n; i++) {
const float *v = pos[i]; /* read twice: two groups of loads */
out[i][0] = (v[0]*vx[0] + v[1]*vx[1] + v[2]*vx[2] + ox - sx) * k;
out[i][1] = (v[0]*vy[0] + v[1]*vy[1] + v[2]*vy[2] + oy - sy) * k;
}
}
```

With `-m68080 -m68881 -ffast-math -fomit-frame-pointer -Ofast
-fexcess-precision=fast -fno-unsafe-math-optimizations`, before the fix:

```text
fsmove.s (a0)+,fp0
fsmove.s (a0),fp3 ; v[1] and v[2] both read at (a0)
fsmove.s (a0),fp2
...
fsmove.s (-8,a0),fp0
fsmove.s (-4,a0),fp3
fsmove.s (a0)+,fp2 ; a0 advanced 8 bytes, not 12
```

## 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
```

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.

## Detection

Compile with `-S` and look for an address register that is post-incremented
in one group of loads while other loads of the same record use `(aN)`
without an offset. Compare with the output of `-fbbb=-`: the number of
bytes the pointer advances per iteration must be the record size.

## Evidence

| 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` |
102 changes: 102 additions & 0 deletions toolchain/pitfalls/gcc-bbb-autoinc-fixup-ice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
title: "GCC 6.5 bbb pass crashes with \"insn does not satisfy its constraints\" after an auto-increment"
type: pitfall
owner: WDrijver
status: draft
origin: ai-assisted
basis: [measured, source-code]
components: [toolchain]
applies_to:
core: "any"
os: [any]
tags: [gcc, bbb, optimizer, autoincrement, ice, volatile]
related:
- toolchain/compiler-variants.md
- toolchain/pitfalls/gcc-bbb-autoinc-converted-insn.md
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

The compiler stops with an internal compiler error:

```text
error: insn does not satisfy its constraints:
(insn 84 ... (set (reg:SI 8 a0)
(plus:SI (mem/v:SI (plus:SI (reg/v/f:SI 11 a3) (const_int 11054)))
(const_int 1)))) {*addsi3_internal}
internal compiler error: in final_scan_insn, at final.c:2943
```

It was found building `v4net.device` at `-O2` with `-m68020` or `-m68080`.
The trigger was a `volatile ULONG` increment at a large struct offset between
`Forbid()` and `Permit()`, with `SysBase` read through a struct pointer.
`-fbbb=-` compiles the file.

## Cause

Bebbo's bbb pass `opt_autoinc` (`-fbbb=i`) turns `move.l (a3),a2` into
`move.l (a3)+,a2` and lowers the offsets of the later uses of `a3`. Each
changed instruction is emitted again and recognized anew, and GCC takes the
first pattern whose operand types match. That need not be the pattern the
instruction had. `lea ([11054,a3],1),a0` came back with offset 11050 as
`*addsi3_internal`, which does not allow a memory source with an address
register as destination. Nothing checked this, so `final` crashed.

The fix tries each fixup on a copy first and gives up the auto-increment
when the copy is not a valid instruction. That spot then compiles as with
`-fbbb=-`. Only GCC-6.50-Dev applies it.

## Wrong

The reduced case from ApolloCrossDev issue #33:

```c
#include <exec/types.h>
#include <exec/memory.h>
struct Db { UBYTE pad[34]; struct Library *db_SysBase; };
#include <proto/exec.h>
#define SysBase db->db_SysBase
struct Nd { struct Db *nd_Db; UBYTE pad[11050]; volatile ULONG cnt; };

APTR f(APTR ctx, ULONG size, ULONG align)
{
struct Nd *nd = ctx;
struct Db *db = nd->nd_Db;
UBYTE *raw;
APTR *p;
if (align < 4) align = 4;
raw = AllocVec(size + align + 4, MEMF_PUBLIC);
if (raw == NULL) return NULL;
p = (APTR *)(((ULONG)raw + 4 + align - 1) & ~(align - 1));
p[-1] = raw;
Forbid();
nd->cnt++; /* volatile increment at offset 11054 */
Permit();
return p;
}
```

## Right

Use GCC-6.50-Dev installed on or after 2026-11-25 (pull request #34 was
merged late on 2026-11-24). With an older install, compile the affected
file with `-fbbb=-`, or reinstall GCC-6.50-Dev. The code needs no change.

## Detection

The error message itself: `insn does not satisfy its constraints` with a
`mem` operand and an address register destination, in `final_scan_insn`.
If `-fbbb=-` makes it go away, it is this bug or another bbb bug.

## Evidence

| 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` |
Loading