Repository navigation
amiga: fix 68000 address errors; tune the 68000 builds for the 68000 - #62
Merged
Merged
Conversation
The 68000 builds stop with an address error (80000003) on a 68000 as soon as they list an ISO 9660 directory or mount an audio CD, as carlosbragatto found and analysed in #61. memcpy only asks exec whether the CPU allows unaligned long moves when __mc68020__ is not defined, and iso_read_le32() loads both-byte-order fields with one move.l when it is. GCC's __mc680x0__ macros follow -mtune, though, not the -m option: the 68000 builds use -m68000 -mtune=68020-60 and get __mc68020__ to __mc68060__ as well. Their predefined macros are the same as those of -m68020 -mtune=68020-60, so no compiler macro can tell the two apart. So the 68000 and ROM builds used long moves for every misaligned copy of more than 16 bytes, and iso_read_le32() read fields with move.l where a Rock Ridge entry can put them at an odd address: SUSP entries are not padded, so the PX entry after mkisofs' five-byte RR entry starts at an odd offset in every ".." record. Let the Makefile say it instead: the 68020 build defines ODFS_M68K_UNALIGNED_OK, and both places test that. A build without it takes the safe path, so a new variant that forgets it gets slower code, not an address error. The 68020 build stays byte for byte the same. The 68000 build grows by 592 bytes and the ROM build by 48: iso_read_le32() reads bytes now.
The 68000 disk and ROM builds were tuned for the 68020 to 68060
(-mtune=68020-60). That dates from when the 68000 build was the only
one. The 68020 build serves those CPUs now, and the tuning costs the
68000: GCC replaces moveq with clr.l and cmpi.l, swap with long
shifts, and shift-and-add with mulu, all of which take a 68000 more
cycles.
Keep the 68020-60 tuning for handler_main.c alone. It holds the
packet loop and the streaming read path, and tuned for the 68000 they
cost a 68040 one E-clock tick per Read(): GCC keeps the file handle in
a data register and moves it to an address register for each access,
and builds shifts from swap. That is -0.85% sequential read in
CDBench, the same under four different free-memory layouts. GCC has
no per-function tuning on m68k, so the Makefile sets it per object.
The 68020 build and the LTO-linked ROM profile leave it out; the ROM
reads as fast either way.
CDBench, 68000 disk build, all-68020-60 -> this:
68040 rig seq read 209126 -> 208998 KiB/s (same tick)
deep lock 148 -> 139 us
small o+r 318 -> 298 us
Discovery 9432 -> 9668 entries/s
A600, 68000 deep lock 8485 -> 7714 us
open/lock 10549 -> 10120 us
small o+r 43913 -> 42800 us
and for the ROM build, all-68020-60 -> all-68000:
68040 rig deep lock 619 -> 575 us
small o+r 1970 -> 1934 us
A600, 68000 deep lock 35856 -> 32921 us
small o+r 123633 -> 118545 us
The A600 runs use a cycle-exact 68000 with KS 3.2.3 and an ATAPI CD
on Gayle IDE; sequential read there is limited by the PIO transfers
and stays at 90 KiB/s. The 68000 build shrinks by 384 bytes and the
ROM build by 216. The 68020 build stays byte for byte the same.
reinauer
force-pushed
the
m68000-unaligned
branch
from
November 28, 2026 22:11
f125c6f to
a0b8d9a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #61.
What was wrong
GCC's
__mc680x0__macros follow-mtune, not-m: with-m68000 -mtune=68020-60it defines__mc68020__through__mc68060__, and the full set of predefined macros is identical to-m68020 -mtune=68020-60. No compiler macro can tell the two apart.Two places used
__mc68020__to decide whether unaligned long accesses are allowed:memcpy(platform/amiga/os3/string.S) skipped the AttnFlags test and copied misaligned buffers withmove.l. That's the crash in the report.iso_read_le32()(backends/iso9660/iso9660.h) loaded both-byte-order fields with onemove.l, with no fallback at run time. Rock Ridge fields can sit at odd addresses: mkisofs puts PX right after a 5-byte RR entry, at offset 39 of every..record. So a 68000 crashed on the first directory listing of any such disc. The patch in the issue doesn't cover this.Both affect the 68000 disk build and the ROM build, since ROM inherits the 68000 CPU flags.
Commits
ODFS_M68K_UNALIGNED_OK, and both places test that. A build without it takes the safe path. The 68020 build stays byte-for-byte identical; the 68000 build grows by 592 bytes and the ROM by 48.-mtune=68020-60from the 68000 disk and ROM builds; that tuning predates the 68020 build. One exception:handler_main.c(the packet loop and the streaming read path) stays tuned for the 68020–60 in the 68000 disk build. Tuned for the 68000, that path costs a 68040 one E-clock tick per Read(), −0.85% sequential read. GCC has no per-function tuning on m68k, so it's set per object. The 68020 build and the LTO-linked ROM leave it out. The 68000 build shrinks by 384 bytes and the ROM by 216.Testing
Emulated A600: cycle-exact 68000, Kickstart 3.2.3, ATAPI CD on Gayle IDE.
Exception 3 (000022d8 …)inmemcpyduring CDBenchmkisofs -R)Exception 3 (00002032 …)iniso_read_le32on the first listingCDBench, old tuning (all 68020–60) → this PR (all three runs per boot agree):
Tuning everything for the 68000, including
handler_main.c, gave 207349 KiB/s sequential read on the 68040 (one tick lower). That was the same under four different free-memory layouts, which is whyhandler_main.ckeeps the 68020–60 tuning.The 68020 build is unchanged (byte-identical to main), so its CDBench figures can't move.
make check,golden-checkandmalformed-checkpass;amiga,amiga-020,rom,amiga-testandrom-testbuild within their size limits.Thanks to carlosbragatto for the report and the analysis.